Learn how to package a trained model using Cog and publish it to Replicate.
Before you can publish your model, you'll need a Replicate account. Replicate is currently in closed beta while we iron out the wrinkles. If you have a beta invite link you can use that to sign up. If you don't have a beta invite, come talk to us in Discord or send an email to team@replicate.com.
Next you'll create a page for your model on Replicate. Visit replicate.com/create to choose a name for your model, and specify whether it should be public or private.
Cog makes it easy to put a machine learning model in a Docker container.
$ 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
More information about Cog and its full documentation are on GitHub.
To configure your project for use with Cog, you'll need to add two files:
cog.yaml
defines system requirements, Python package dependencies, etcpredict.py
describes the prediction interface for your modelUse the cog init
command to generate these files in your project:
$ cd path/to/your/model
$ cog init
For more details on how to configure these files, follow this guide to setting up Cog for your model.
You might also find these references useful:
Now that you've configured your model for use with Cog, it's time to publish it to the Replicate registry:
$ cog login
$ cog push r8.im/your-username/your-model
Note: You can also set the image property in your cog.yaml file. This allows you to run cog push
without specifying the image, and also makes your Replicate model page more discoverable for folks reading your model's source code.
Once you've pushed your model to the registry it will be visible on the website, and you can use the web-based form to run predictions using your model. Whenever you generate a prediction that you like, click the "Add to example gallery" button to display that output on your model page.
Congratulations! You've now got a hosted machine learning model with a web-based demo that anyone can use! Now it's time to share it with the your friends, peers, and colleagues. Share a link to the model page, or use the "Share a link to this output" button to share the output of a specific prediction from your model.
Did something go wrong along the way? Let us know and we'll help. If you encountered a problem with Cog, you can file a GitHub issue. Otherwise chat with us in Discord or send us an email at team@replicate.com.