Upload Model | Clarifai - The World's AI
Clarifai Model Upload
The Clarifai platform allows you to upload custom models for a wide range of use cases. With just a few simple steps, you can get your models up and running and leverage the platform’s powerful capabilities.
1
Set Clarifai PAT
You need to set the CLARIFAI_PAT you've retrieved as an environment variable.
Unix-Like Systems
export CLARIFAI_PAT=YOUR_PERSONAL_ACCESS_TOKEN_HERE
Windows
set CLARIFAI_PAT=YOUR_PERSONAL_ACCESS_TOKEN_HERE
2
Install Clarifai Package
Install the latest version of the clarifai Python SDK. This also installs the Clarifai Command Line Interface (CLI), which we'll use for uploading the model.
pip install -U clarifai
3
Create Files
clarifai model init
After the files are created, add the following snippets to each of the respective files.
├── your_model_directory/
├── 1/
│ └── model.py
├── requirements.txt
└── config.yaml
model.py
from clarifai.runners.models.model_class import ModelClass
from typing import Iterator
class MyFirstModel(ModelClass):
"""A custom model that generates 'Hello World' outputs in a streaming fashion."""
@ModelClass.method
def generate(self, text1: str = "") -> Iterator[str]:
"""
This method streams multiple outputs instead of returning just one.
It takes an input string and yields a sequence of outputs.
"""
for i in range(5): # number of generated outputs
output_text = text1 + f" Hello World {i}"
yield output_text
requirements.txt
clarifai>=11.10.3
config.yaml
model:
id: "my-first-model"
user_id: "YOUR_USER_ID_HERE"
app_id: "YOUR_APP_ID_HERE"
model_type_id: "text-to-text"
build_info:
python_version: "3.11"
inference_compute_info:
cpu_limit: "1"
cpu_memory: "5Gi"
num_accelerators: 0
4
Upload the Model
Once your custom model is ready, upload it to the Clarifai platform by navigating to the directory containing the model and running the following command:
clarifai model upload
Getting help
- Check the Clarifai Documentation
- Use
clarifai --helpfor CLI command help - Use
clarifai model --helpfor model-specific commands
Additional Resources
- Set up a cluster
This serves as the foundation of your compute environment. - Deploy your model
Once the nodepool is ready, deploy your model to make it available for inference. - Predict with model
Once your model is successfully deployed, you can start making predictions with it.