Cog

Containers for machine learning
Alternatives To Cog
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Awesome Kubernetes13,893
15 days ago9otherShell
A curated list for awesome kubernetes sources :ship::tada:
Mlcourse.ai8,803
10 days ago4otherPython
Open Machine Learning Course
Doccano7,807
a day ago28May 19, 2022244mitPython
Open source annotation tool for machine learning practitioners.
Fate5,035
a day ago1May 06, 2020725apache-2.0Python
An Industrial Grade Federated Learning Framework
Cog4,785
4 days ago61September 23, 2022273apache-2.0Python
Containers for machine learning
Pipeline4,160
7 months ago85July 18, 20171apache-2.0Jsonnet
PipelineAI Kubeflow Distribution
Deeplearningproject4,043
3 years ago3mitHTML
An in-depth machine learning tutorial introducing readers to a whole machine learning pipeline from scratch.
Orchest3,867
3 days ago14April 06, 2022126agpl-3.0TypeScript
Build data pipelines, the easy way 🛠️
Eagleeye3,530
a year ago18wtfplPython
Stalk your Friends. Find their Instagram, FB and Twitter Profiles using Image Recognition and Reverse Image Search.
Serve3,47811a day ago14May 13, 2022274apache-2.0Java
Serve, optimize and scale PyTorch models in production
Alternatives To Cog
Select To Compare


Alternative Project Comparisons
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 with Pydantic.

  • Automatic HTTP prediction server: Your model's types are used to dynamically generate a RESTful HTTP API using FastAPI.

  • Automatic queue worker. Long-running deep learning models or batch processing is best architected with a queue. Cog models do this out of the box. Redis is currently supported, with more in the pipeline.

  • Cloud storage. Files can be read and written directly to Amazon S3 and Google Cloud Storage. (Coming soon.)

  • 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-mesa-glx"
    - "libglib2.0-0"
  python_version: "3.8"
  python_packages:
    - "torch==1.8.1"
predict: "predict.py:Predictor"

Define how predictions are run on your model with predict.py:

from cog import BasePredictor, Input, Path
import torch

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

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

Now, you can run predictions on this model:

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

Or, build a Docker image for deployment:

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

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

$ curl http://localhost:5000/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 [email protected].

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.

Install

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

brew install cog

You can also download and 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

Alternatively, you can build Cog from source and install it with these commands:

make
sudo make install

Next steps

Need help?

Join us in #cog on Discord.

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

Eric Allam
Eric Allam

Ivn Perdomo
Ivn Perdomo

Charles Frye
Charles Frye

Luan Pham
Luan Pham

TommyDew
TommyDew

Jesse Andrews
Jesse Andrews

Nick Stenning
Nick Stenning

Justin Merrell
Justin Merrell

Rurik Yl-Onnenvuori
Rurik Yl-Onnenvuori

Youka
Youka

Clay Mullis
Clay Mullis

Mattt
Mattt

Eng Zer Jun
Eng Zer Jun

BB
BB

williamluer
williamluer

Simon Eskildsen
Simon Eskildsen

F
F

Philip Potter
Philip Potter

Joanne Chen
Joanne Chen

This project follows the all-contributors specification. Contributions of any kind welcome!

Popular Machine Learning Projects
Popular Docker Projects
Popular Machine Learning Categories

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Python
Docker
Machine Learning
Deep Learning
Pytorch
Tensorflow