cog.yaml defines how to build a Docker image and how to run predictions on your model inside that image.
It has three main sections: build, image, and predict.
Example Configuration
Top-Level Properties
Describes how to build the Docker image your model runs in. See Build Configuration for all available options.
The name given to built Docker images. If you want to push to a registry, this should also include the registry name.If you don’t set this, a name will be generated from the directory name. When set, you can run
cog push without specifying the model name.r8.im is Replicate’s registry, but this can be any Docker registry.
The pointer to the
Predictor object in your code, which defines how predictions are run on your model.The pointer to the
Predictor object in your code that defines how training runs on your model.Describes the concurrency capabilities of the model. Added in cog 0.14.0.
A list of environment variables to make available during builds and at runtime, in the format
NAME=value.A list of weight files or directories to include in the model.
Build Configuration
Thebuild section describes how to build the Docker image your model runs in.
The minor (Cog supports Python 3.10, 3.11, 3.12, and 3.13. If you don’t define a version, Cog will use the latest version of Python 3.13 or a version of Python that is compatible with the versions of PyTorch or TensorFlow you specify.
3.11) or patch (3.11.1) version of Python to use.These are the versions supported in the Docker container, not your host machine. You can run any version(s) of Python you wish on your host machine.
A pip requirements file specifying the Python packages to install.This follows the standard requirements.txt format.requirements.txt:You can also pin Python package installations to a specific git commit:
Your
cog.yaml file can set either python_packages or python_requirements, but not both. Use python_requirements when you need to configure options like --extra-index-url or --trusted-host to fetch Python package dependencies.Installing Git-hosted packages
To install Git-hosted Python packages, addgit to the system_packages list, then use the git+https:// syntax:cog.yaml:You can use a shortened prefix of the 40-character git commit SHA, but you must use at least six characters.
A list of Python packages to install from the PyPI package index, in the format Your
package==version.cog.yaml file can set either python_packages or python_requirements, but not both.A list of Ubuntu APT packages to install.
Enable GPUs for this model. When enabled, the nvidia-docker base image will be used, and Cog will automatically figure out what versions of CUDA and cuDNN to use based on the version of Python, PyTorch, and Tensorflow that you are using.
When you use
cog run or cog predict, Cog will automatically pass the --gpus=all flag to Docker. When you run a Docker image built with Cog, you’ll need to pass this option to docker run.Cog automatically picks the correct version of CUDA to install, but this lets you override it by specifying the minor (
11.8) or patch (11.8.0) version of CUDA to use.Cog automatically picks the correct version of cuDNN to install, but this lets you override it for whatever reason.
A list of setup commands to run in the environment after your system packages and Python packages have been installed. If you’re familiar with Docker, it’s like a You can use secret mounts to securely pass credentials to setup commands, without baking them into the image. For more information, see the Dockerfile reference.
RUN instruction in your Dockerfile.Using secret mounts
Each command inrun can be either a string or a dictionary with secret mounts:A list of setup commands to run in the environment before your Python packages are installed.
Pin the version of the cog Python SDK installed in the container. Accepts a PEP 440 version string. When omitted, the latest release is installed.Pre-release versions are also supported:The
When a pre-release
sdk_version is set, --pre is automatically passed to the pip install commands for both cog and coglet, so pip will resolve matching pre-release packages.COG_SDK_WHEEL environment variable takes precedence over sdk_version. See Environment variables for details.Tests Configuration
A list of test cog commands to run.