Skip to main content

View example on GitHub

This guide walks through deploying Mistral-7B, a powerful large language model (LLM), using Truss. You’ll configure the model, set up inference, allocate resources, and deploy it as an API endpoint.

Set up your model

Start by importing the necessary libraries:
model/model.py
Specify the Hugging Face model checkpoint:
model/model.py

Define the model class

Create a Model class that loads Mistral-7B and its tokenizer when the server starts:
model/model.py

Implement inference

The predict function handles inference by tokenizing input, generating text, and decoding the output.
model/model.py

Configure your deployment

Define dependencies

Specify the necessary Python packages in config.yaml:
config.yaml

Allocate compute resources

Mistral-7B requires an NVIDIA A10G GPU for efficient inference:
config.yaml

Deploy the model

Install the Baseten CLI and sign in:
Install the Baseten CLI
Terminal
For other platforms or a specific version, see the Baseten CLI install reference.
Sign in
From the directory that contains config.yaml, push your model to Baseten:
You should see output like:
Copy the model ID from the Model: line (abc1d2ef in the example). The first deploy takes several minutes while Baseten builds the image and the model loads its weights from Hugging Face. Once the deployment is active, call the model with the Baseten CLI:
To call the model’s endpoint from Python instead, create a personal key in API keys and set it in the terminal where you’ll run the request:
Then send the request:
call_model.py
Replace abc1d2ef with your model ID. To use the Truss CLI instead, sign in with truss login, deploy with truss push, and call the model with truss predict --published -d '{"prompt": "What is a large language model?"}'.

Check for optimized engine support

For faster inference, check whether your model runs on a Baseten engine such as Engine-Builder-LLM, which builds TensorRT-LLM engines, or on an open-source server such as vLLM or SGLang. For an overview, see Engines.