Skip to main content
Cog is a command-line tool for packaging machine learning models in production-ready containers.

Quick Reference

CommandDescription
cog initInitialize a new Cog project
cog buildBuild a Docker image from cog.yaml
cog predictRun a prediction on your model
cog runRun a command inside a Docker environment
cog serveStart an HTTP prediction server
cog pushBuild and push an image to a registry
cog trainRun a training job
cog loginLog in to a container registry

Global Flags

These flags are available on all commands:
--debug
boolean
Show debugging output
--help
boolean
Show help for any command
--version
boolean
Show version of Cog

Installation

Install Cog using Homebrew on macOS:
brew install replicate/tap/cog
Or install manually on Linux/macOS:
sudo curl -o /usr/local/bin/cog -L "https://github.com/replicate/cog/releases/latest/download/cog_$(uname -s)_$(uname -m)"
sudo chmod +x /usr/local/bin/cog

Getting Started

Create a cog.yaml file to define your environment:
build:
  python_version: "3.12"
  python_requirements: requirements.txt
predict: "predict.py:Predictor"
Run predictions on your model:
cog predict -i prompt="a photo of a cat"
Build a Docker image:
cog build -t my-model:latest

Common Workflows

Development

  1. Create your cog.yaml configuration
  2. Use cog run to test commands in the environment
  3. Use cog predict to test predictions locally

Testing

# Run a Python shell in your environment
cog run python

# Run a training script
cog run python train.py

# Test predictions
cog predict -i [email protected]

Production

# Build an image
cog build -t my-model:v1

# Push to a registry
cog push r8.im/username/my-model

# Or combine build and push
cog push r8.im/username/my-model --separate-weights

Next Steps

Build docs developers (and LLMs) love