Truss is a Python library that provides a seamless bridge from model development to model delivery. It allows data scientists to containerize, test, and deploy machine learning models as production-ready services with ease, often to platforms like Baseten. The current stable version is 0.15.12, with a fairly active release cadence, frequently releasing patch versions.
pip install trussVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a new Truss project and add a basic `predict` function. The example includes simulating model data loading via an environment variable. To actually serve and test the model, navigate into the created directory (`cd my_truss_model`) and run `truss serve` from your terminal. For deployment to platforms like Baseten, an API key (e.g., `os.environ.get('BASETEN_API_KEY', '')`) would typically be required for `truss.push()` operations.
For models deployed with Truss 0.15.13 or newer, ensure your `config.yaml` explicitly specifies a supported Python version (e.g., `python_version: '3.10'`) or upgrade your model's environment to Python 3.10 or newer.
Consult the official Truss documentation for a list of reserved environment variables to avoid collisions. Consider prefixing your custom model-specific environment variables (e.g., `MY_MODEL_VAR_NAME`) to minimize the risk of conflict.
If you encounter validation errors, refer to the latest `config.yaml` schema documentation or try initializing a new Truss project and migrating your model code to ensure your configuration is up-to-date and compliant.
Install the truss library via pip: `pip install truss`
Add the missing package and its version to the `requirements.txt` file inside your Truss directory (e.g., `transformers==4.30.0`) and restart the Truss.
Stop the process currently using the port, or specify a different port for `truss serve` using `truss serve -p <new_port_number>`.
Ensure the `predict` method is defined as `def predict(self, model_input):` within your model class.