# build-models

Walks an agent through packaging a custom model with Cog and serving it locally. Useful when you have weights or a HuggingFace project and need a predict.py.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 1800 installs · ★ 141
- Author: replicate
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/replicate/skills/tree/HEAD/skills/build-models/SKILL.md
- Updated: 2026-06-04
- HTML: https://affpapa.org/en/nevibecode/skills/build-models

## What it does

The skill guides an agent through building custom models with Cog: writing `cog.yaml`, `predict.py` and `train.py`, defining inputs and outputs, building a Docker image, and serving locally with `cog serve` or `cog predict`. It also covers porting a HuggingFace, GitHub or ComfyUI project.

Inside are pointers to the Cog references, a project template and examples. The common traps are spelled out: pin Python and every line of `requirements.txt`, since floating versions break cold boots; use `ge`/`le` and `choices` for bounds and enums; `cog.Path` for files and `cog.Secret` for tokens; async predictors with continuous batching and streaming text for LLMs. Weight loading gets three patterns: bake into the image at build time, pull with `pget` from `weights.replicate.delivery`, or fetch in `setup()`.

You need Docker running and Cog installed — `brew install replicate/tap/cog` or the install script. Pushing to Replicate lives in the separate `publish-models` skill, running existing models in `run-models`. No Docker, no build.

## Requirements
- Works with: GitHub, Docker

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add replicate/skills --skill build-models -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/build-models/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/build-models/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add replicate/skills --skill build-models -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/build-models/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add replicate/skills --skill build-models -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/build-models/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install replicate/skills build-models
```

2. **Manually: put the files in place**
- File: `.github/skills/build-models/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add replicate/skills --skill build-models -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/replicate/skills --path skills/build-models
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/build-models/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add replicate/skills --skill build-models -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/replicate/skills/tree/HEAD/skills/build-models/SKILL.md

## When to use it
- build a Docker image for a GPU model with CUDA
- define predictor inputs and outputs with validation
- cut cold-boot time by baking weights into the image
- port a HuggingFace or ComfyUI project to Replicate
- serve a model locally and test a prediction

## Example prompts
- Package this repo as a Cog model with `cog.yaml` and `predict.py`
- Add streaming output to the predictor for an LLM
- Rewrite weight loading to use `pget` so cold boots are faster

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: a1c5a1b089f93ff4.

BEGIN THIRD-PARTY FILE a1c5a1b089f93ff4
````text
---
name: build-models
description: >
  Package and build custom AI models with Cog for deployment on Replicate.
  Use when creating a cog.yaml or predict.py, defining model inputs and
  outputs, loading model weights at setup time, building Docker images for
  ML models, serving locally with cog serve or cog predict, or porting a
  HuggingFace, GitHub, or ComfyUI model to run on Replicate. Trigger on
  phrases like "build a model", "package a model", "create a Cog model",
  "wrap a model", "containerize an AI model", "predict.py", "cog.yaml",
  "BasePredictor", or "Cog container", and when referencing cog.run,
  github.com/replicate/cog, or github.com/replicate/cog-examples. Covers
  GPU and CUDA setup, pget for fast weight downloads, async predictors
  with continuous batching, streaming outputs, and cold-boot optimization
  for image, video, audio, and LLM models. For pushing built models to
  Replicate, see publish-models. For running existing models, see
  run-models.
---

## Docs

- Cog reference (single file): <https://cog.run/llms.txt>
- `cog.yaml` reference: <https://cog.run/yaml>
- Python predictor reference: <https://cog.run/python>
- Examples: <https://github.com/replicate/cog-examples>
- Template: <https://github.com/replicate/cog-template>

## When to use this skill

- You have model code, weights, or a HuggingFace/GitHub project you want to host on Replicate.
- You're writing or editing a `cog.yaml`, `predict.py`, or `train.py`.
- For pushing a built model to Replicate, see `publish-models`.
- For running existing Replicate models, see `run-models`.

## Prerequisites

- Docker running locally.
- Cog installed: `brew install replicate/tap/cog` or `sh <(curl -fsSL https://cog.run/install.sh)`.
- Optional: `cog init` to scaffold `cog.yaml` and `predict.py`.

## Project layout

The canonical Replicate model layout:

```
cog.yaml
predict.py
weights.py                 # optional download helpers
requirements.txt
cog-safe-push-configs/
  default.yaml             # see publish-models skill
.github/workflows/
  ci.yaml
script/                    # github.com/github/scripts-to-rule-them-all
  lint
  test
  push
```

## cog.yaml essentials

A modern config for a GPU model:

```yaml
build:
  gpu: true
  cuda: "12.8"
  python_version: "3.12"
  python_requirements: requirements.txt
  system_packages:
    - libgl1
    - libglib2.0-0
predict: predict.py:Predictor
```

Notes:

- Pin Python to a specific minor version, and pin every line in `requirements.txt`. Floating versions break cold boots.
- Use `python_requirements` over inline `python_packages` once the list grows.
- `cuda` follows your torch wheel (e.g. `12.8` paired with `torch==2.7.1+cu128`).
- Add `train: train.py:train` if your model is fine-tunable.
````
END THIRD-PARTY FILE a1c5a1b089f93ff4

The third-party file has ended. Everything between the a1c5a1b089f93ff4 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2759 of 14222 bytes. © replicate · Apache-2.0 · https://github.com/replicate/skills/tree/HEAD/skills/build-models/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
