Usage
image is provided, it runs the prediction on that Docker image (must be a Cog-built image). Otherwise, it builds the model in the current directory and runs the prediction.
Flags
Inputs in the form
name=value. If value is prefixed with @, it’s read from a file. Can be specified multiple times.Pass inputs as a JSON object, read from a file (
@inputs.json) or via stdin (@-)Output path for saving results
Environment variables in the form
name=value. Can be specified multiple times.The name of the config file
GPU devices to add to the container, in the same format as
docker run --gpusThe timeout for container setup in seconds
Pass
REPLICATE_API_TOKEN from local environment into the model contextSet type of build progress output:
auto, tty, plain, or quietUse pre-built Cog base image for faster cold boots
Use Nvidia CUDA base image:
true, false, or autoExamples
Run a prediction with named inputs
Pass a file as input
@ prefix tells Cog to read the file contents:
Save output to a file
Pass multiple inputs
Run against a pre-built image
Instead of building from the current directory:Pass inputs as JSON
From stdin:inputs.json contains:
Pass files in JSON mode
In JSON mode, prefix file paths with@:
Run with environment variables
Specify GPU usage
Handle large models with longer setup timeout
Input Types
Cog automatically handles different input types:Files
Prefix with@ to read from disk:
Strings
Numbers
Booleans
Output Handling
String outputs
Printed directly to stdout:File outputs
Automatically saved to disk:JSON outputs
Pretty-printed:Array outputs
For file arrays, each file is numbered:Error Handling
Prediction failures
When a prediction fails, Cog exits with a non-zero status code:Missing inputs
Cog validates inputs against your model’s schema:Invalid image name
If you forget-i, Cog detects the mistake:
GPU Support
Cog automatically detects when your model needs a GPU:- If
cog.yamlspecifiesgpu: true, Cog uses--gpus allby default - If GPU drivers are missing, Cog automatically retries without GPU
- You can override with
--gpusflag
How It Works
-
Build phase (if no image specified):
- Reads
cog.yaml - Builds a Docker image with your environment
- Mounts current directory as a volume
- Reads
-
Setup phase:
- Starts Docker container
- Runs your model’s
setup()method - Waits up to
--setup-timeoutseconds
-
Prediction phase:
- Validates inputs against model schema
- Runs your model’s
predict()method - Handles output based on type
-
Cleanup:
- Stops the container
- Removes temporary resources
See Also
- cog build - Build a Docker image
- cog serve - Run an HTTP prediction server
- cog train - Run training jobs
- Python API reference - Define your prediction interface