自动从仓库构建cog.yaml
项目描述
Cogreqs
Cogreqs是一个实验性的cog init
替代品,它智能地填充cog.yaml。
安装
pip安装cogreqs
使用方法
在现有的Python仓库中运行以下命令
$ cogreqs --gpu .
Wrote cog.yaml
Wrote predict.py
cog.yaml可能现在包含类似的内容
# Configuration for Cog ⚙
# Reference: https://github.com/replicate/cog/blob/main/docs/yaml.md
build:
# set to true if your model requires a GPU
gpu: true
# a list of ubuntu apt packages to install
system_packages:
- "ffmpeg"
- "libsndfile-dev"
# python version in the form '3.8' or '3.8.12'
python_version: "3.8"
# a list of packages in the format <package-name>==<version>
python_packages:
- "librosa==0.9.1"
- "numpy==1.22.2"
- "scipy==1.8.0"
- "torch==1.10.2"
# commands run after the environment is setup
run:
注意:Cogreqs输出的predict.py仅与Cog的future
分支兼容。直到该分支合并到主分支,请从https://github.com/replicate/cog/releases/tag/v0.1.0-alpha安装Cog
您还可以将生成的cog.yaml内容输出到stdout
$ cogreqs --config-path=- --predict-path=/dev/null .
# Configuration for Cog ⚙
# Reference: https://github.com/replicate/cog/blob/main/docs/yaml.md
build:
[...]
CLI参考
usage: cogreqs [-h] [-f] [-g] [--config-path CONFIG_PATH] [--predict-path PREDICT_PATH] folder
Generate cog.yaml and predict.py from an existing repository. This is an experimental alternative to
cog init
positional arguments:
folder Project folder
optional arguments:
-h, --help show this help message and exit
-f, --force-overwrite
Overwrite existing cog.yaml and predict.py
-g, --gpu Use GPU
--config-path CONFIG_PATH
Config file path (default cog.yaml)
--predict-path PREDICT_PATH
Predict file path (default predict.py)
它是如何工作的?
Cogreqs使用pipreqs从仓库中的Python文件中提取需求。然后,它对这些需求应用一系列启发式方法,以填充cog.yaml中的python_packages
和system_packages
。
例如,Cogreqs知道librosa
需要ffmpeg
和libsndfile-dev
系统包,因此如果librosa
是Python需求之一,它将添加这些到system_packages
中。
工作正在进行中!
该项目仍在开发中。如果您有关于启发式方法或其他功能的想法,请提交问题或pull request!