MCPcopy Index your code
hub / github.com/replicate/cog

github.com/replicate/cog @v0.21.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.21.0 ↗ · + Follow
3,725 symbols 17,018 edges 366 files 1,450 documented · 39% 93 cross-repo links updated 3d agov0.21.0 · 2026-06-16★ 9,43844 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Cog: Containers for machine learning

Cog is an open-source tool that lets you package machine learning models in a standard, production-ready container.

You can deploy your packaged model to your own infrastructure, or to Replicate.

Highlights

  • 📦 Docker containers without the pain. Writing your own Dockerfile can be a bewildering process. With Cog, you define your environment with a simple configuration file and it generates a Docker image with all the best practices: Nvidia base images, efficient caching of dependencies, installing specific Python versions, sensible environment variable defaults, and so on.

  • 🤬️ No more CUDA hell. Cog knows which CUDA/cuDNN/PyTorch/Tensorflow/Python combos are compatible and will set it all up correctly for you.

  • Define the inputs and outputs for your model with standard Python. Then, Cog generates an OpenAPI schema and validates the inputs and outputs.

  • 🎁 Automatic HTTP inference server: Your model's types are used to dynamically generate a RESTful HTTP API using a high-performance Rust/Axum server.

  • 🚀 Ready for production. Deploy your model anywhere that Docker images run. Your own infrastructure, or Replicate.

How it works

Define the Docker environment your model runs in with cog.yaml:

build:
  gpu: true
  system_packages:
    - "libgl1"
    - "libglib2.0-0"
  python_version: "3.13"
  python_requirements: requirements.txt
run: "run.py:Runner"

Define how your model runs with run.py:

from cog import BaseRunner, Input, Path
import torch

class Runner(BaseRunner):
    def setup(self):
        """Load the model into memory to make running multiple inferences efficient"""
        self.model = torch.load("./weights.pth")

    # The arguments and types the model takes as input
    def run(self,
          image: Path = Input(description="Grayscale input image")
    ) -> Path:
        """Run the model"""
        processed_image = preprocess(image)
        output = self.model(processed_image)
        return postprocess(output)

In the above we accept a path to the image as an input, and return a path to our transformed image after running it through our model.

Now, you can run the model:

$ cog run -i image=@input.jpg
--> Building Docker image...
--> Running...
--> Output written to output.jpg

Or, build a Docker image for deployment:

$ cog build -t my-classification-model
--> Building Docker image...
--> Built my-classification-model:latest

$ docker run -d -p 5000:5000 --gpus all my-classification-model

$ curl http://localhost:5000/predictions -X POST \
    -H 'Content-Type: application/json' \
    -d '{"input": {"image": "https://.../input.jpg"}}'

Or, combine build and run via the serve command:

$ cog serve -p 8080

$ curl http://localhost:8080/predictions -X POST \
    -H 'Content-Type: application/json' \
    -d '{"input": {"image": "https://.../input.jpg"}}'

Why are we building this?

It's really hard for researchers to ship machine learning models to production.

Part of the solution is Docker, but it is so complex to get it to work: Dockerfiles, pre-/post-processing, Flask servers, CUDA versions. More often than not the researcher has to sit down with an engineer to get the damn thing deployed.

Andreas and Ben created Cog. Andreas used to work at Spotify, where he built tools for building and deploying ML models with Docker. Ben worked at Docker, where he created Docker Compose.

We realized that, in addition to Spotify, other companies were also using Docker to build and deploy machine learning models. Uber and others have built similar systems. So, we're making an open source version so other people can do this too.

Hit us up if you're interested in using it or want to collaborate with us. We're on Discord or email us at team@replicate.com.

Prerequisites

  • macOS, Linux or Windows 11. Cog works on macOS, Linux and Windows 11 with WSL 2
  • Docker. Cog uses Docker to create a container for your model. You'll need to install Docker before you can run Cog. If you install Docker Engine instead of Docker Desktop, you will need to install Buildx as well.

Install

If you're using macOS, you can install Cog using Homebrew:

brew install replicate/tap/cog

You can also download and install the latest release using our install script:

# bash, zsh, and other shells
sh <(curl -fsSL https://cog.run/install.sh)

# fish shell
sh (curl -fsSL https://cog.run/install.sh | psub)

# download with wget and run in a separate command
wget -qO- https://cog.run/install.sh
sh ./install.sh

You can manually install the latest release of Cog directly from GitHub by running the following commands in a terminal:

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

Or if you are on docker:

RUN sh -c "INSTALL_DIR=\"/usr/local/bin\" SUDO=\"\" $(curl -fsSL https://cog.run/install.sh)"

Upgrade

If you're using macOS and you previously installed Cog with Homebrew, run the following:

brew upgrade replicate/tap/cog

Otherwise, you can upgrade to the latest version by running the same commands you used to install it.

Development

See CONTRIBUTING.md for how to set up a development environment and build from source.

Next steps

Need help?

Join us in #cog on Discord.

Ask DeepWiki

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Ben Firshman Ben Firshman 💻 📖 Andreas Jansson Andreas Jansson 💻 📖 🚧 Zeke Sikelianos Zeke Sikelianos 💻 📖 🔧 Rory Byrne Rory Byrne 💻 📖 ⚠️ Michael Floering Michael Floering 💻 📖 🤔 Ben Evans Ben Evans 📖 shashank agarwal shashank agarwal 💻 📖
VictorXLR VictorXLR 💻 📖 ⚠️ hung anna hung anna 🐛 Brian Whitman Brian Whitman 🐛 JimothyJohn JimothyJohn 🐛 ericguizzo ericguizzo 🐛 Dominic Baggott Dominic Baggott 💻 ⚠️ Dashiell Stander Dashiell Stander 🐛 💻 ⚠️
Shuwei Liang Shuwei Liang 🐛 💬

Extension points exported contracts — how you extend this code

Builder (Interface)
Builder builds an artifact from a spec. Each builder handles one artifact type (image, weight, etc.). [6 implementers]
pkg/model/builder.go
Check (Interface)
Check is the interface every doctor rule implements. [12 implementers]
pkg/doctor/doctor.go
ConfigError (Interface)
ConfigError is the base interface for all config errors. Allows callers to use errors.As to get config-specific details. [5 …
pkg/config/errors.go
Client (Interface)
(no doc) [5 implementers]
pkg/registry/client.go
Provider (Interface)
Provider encapsulates registry-specific behavior [3 implementers]
pkg/provider/provider.go
CodedError (Interface)
Types //////////////////////////////////////// [1 implementers]
pkg/errors/errors.go
Store (Interface)
Store is a content-addressed store of individual weight files. Every method takes a context; implementations SHOULD hon [1 …
pkg/weights/store/store.go
Command (Interface)
Command defines the interface for testscript commands.
integration-tests/harness/command.go

Core symbols most depended-on inside this repo

Equal
called by 1080
pkg/util/version/version.go
Errorf
called by 778
pkg/util/console/console.go
Equal
called by 565
pkg/model/artifact_weight.go
Run
called by 387
pkg/docker/command/command.go
Get
called by 292
pkg/schema/types.go
Len
called by 262
pkg/schema/types.go
Error
called by 171
pkg/model/weightsource/filter.go
String
called by 129
pkg/model/model.go

Shape

Function 2,204
Method 1,065
Struct 290
Class 105
TypeAlias 30
Interface 17
FuncType 14

Languages

Go86%
Python14%

Modules by API surface

pkg/schema/python/parser_test.go228 symbols
pkg/docker/dockertest/command_mocks.go88 symbols
crates/coglet-python/tests/test_coglet.py75 symbols
python/tests/test_adt.py70 symbols
pkg/model/resolver_test.go65 symbols
pkg/schema/types.go60 symbols
python/tests/test_predictor.py55 symbols
pkg/dockerfile/standard_generator.go49 symbols
pkg/schema/openapi_test.go48 symbols
pkg/config/config_test.go44 symbols
pkg/doctor/check_config_test.go42 symbols
pkg/model/weights_status_test.go40 symbols

Dependencies from manifests, versioned

dario.cat/mergov1.0.2 · 1×
github.com/Azure/go-ansitermv0.0.0-2025010203350 · 1×
github.com/bitfield/gotestdoxv0.2.2 · 1×
github.com/containerd/consolev1.0.5 · 1×
github.com/containerd/continuityv0.4.5 · 1×
github.com/containerd/errdefsv1.0.0 · 1×

For agents

$ claude mcp add cog \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact