Table of contents
GitHub Actions let you to automate your software development workflows directly within your GitHub repository.
In this tutorial, you'll learn how to use GitHub Actions to build and push your model to Replicate, so you don't have to manually build and push your model. This setup works equally well for both public and private models.
To use GitHub Actions, you define workflows using YAML files stored in the .github/workflows
directory of your GitHub repository.
Your new workflow will use an open-source GitHub Action called replicate/setup-cog that takes care of installing Docker buildx, Cog, CUDA drivers (optionally), and other setup steps.
Create a new file in the .github/workflows
directory of your repository, and name it push.yml
. Then add the following content:
If you're creating a new model from scratch, you can use the cog init
command, which will automatically generate a starter workflow for you.
The replicate/setup-cog action supports automatically authenticating with your Replicate account so you can push models to Replicate. For this to work, you need to provide it with a Replicate API token.
Go to replicate.com/account/api-tokens and create a new token with a name like "GitHub Actions workflow for my-model", then copy the token to your clipboard.
Next you'll add your Replicate API token as a secret to your repository, so it can be safely accessed by your workflow.
Go to your GitHub repository, click Settings, click Secrets, click New repository secret, and add your token as the secret. Name it REPLICATE_API_TOKEN
and paste in the token you copied in the previous step.
Next you'll commit and push your changes to GitHub, so you can run the workflow:
GitHub Actions workflows can be triggered manually, or on a schedule, or in response to events like creating pull requests or pushing to your default branch.
The workflow you added above is configured to be triggered manually (see the workflow_dispatch
bit). It's a good idea to start with a manual trigger so you can test out the workflow explicitly, then switch to a more automated process once you've got it working as expected.
Once you've run the workflow manually and the process is working as expected, you may want to update your workflow to trigger automatically. Here's how to update the workflow to trigger whenever you push to your default branch:
First, add a Repository configuration variable to your repository to store the name of your model.
Then update your workflow to run on pushes to your main branch:
Then update the cog push
step in your workflow to fall back to the default model name if the input is empty. This will allow you to manually trigger the workflow with a custom model name, or automatically trigger the workflow with the default model name:
If your model is large, the default GitHub Actions runner may not have enough disk space. The jlumbroso/free-disk-space action included in the workflow above saves about 30GB of disk space, but that may not be enough for your model.
If you need even more space, you can can set up a larger hosted runner on GitHub, then update your workflow to use your new runner:
Note: You'll need a GitHub Team or GitHub Enterprise Cloud plan to use larger runners.
Hooray! You've now got a workflow that pushes your model to Replicate. You're on the path to a more automated future, where you can iterate quickly on AI models and ship them just like normal software.