Truss Transfer: Baseten Pointer Resolution Utility
Truss-transfer is a Python-optional download utility library for resolving Baseten Pointers (bptr), designed to speed up file transfers within the Baseten ecosystem. It is primarily used internally by the `truss` CLI for serving AI/ML models in production. The current stable version is 0.0.41, with frequent releases often coinciding with updates to the main `truss` library.
Common errors
-
ModuleNotFoundError: No module named 'truss-transfer'
cause The Python import statement uses a hyphen, which is invalid for module names. The PyPI package name `truss-transfer` is installed, but the corresponding importable module uses an underscore.fixChange the import statement to use an underscore: `import truss_transfer`. -
TypeError: PyModelRepo.__init__() got an unexpected keyword argument 'unsupported_arg'
cause The `PyModelRepo` class constructor arguments have changed or an unrecognized argument is being passed. This often happens with minor version updates due to the library's active development.fixConsult the latest `truss-transfer` or Baseten `truss` documentation (specifically `PyModelRepo` usage) for the correct set of parameters. Remove or update the offending keyword argument. -
FileNotFoundError: [Errno 2] No such file or directory: 'bptr://...' when deploying a Truss model
cause The Baseten Pointer (bptr) specified in the `PyModelRepo` or `config.yaml` cannot be resolved or accessed by `truss-transfer`. This can be due to incorrect `repo_id`, missing credentials (e.g., `runtime_secret_name` not configured on Baseten), or network issues.fixVerify the `repo_id` is correct and accessible from the Baseten environment. Ensure that any specified `runtime_secret_name` (e.g., `hf_access_token`, `gcs-service-account-jsn`) is correctly configured and available within your Baseten workspace. Check network connectivity if deploying to a custom environment.
Warnings
- gotcha Direct standalone usage of `truss-transfer` is uncommon for end-users. It is primarily an internal dependency and utility for the `truss` CLI and Baseten platform. Attempting to use it outside this context without a clear understanding of Baseten Pointers (bptr) and `truss` deployment mechanisms may not yield expected results.
- gotcha The package name on PyPI is `truss-transfer`, but the primary import is `truss_transfer` (with an underscore). Mismatched naming conventions between PyPI and import statements are a common source of `ModuleNotFoundError`.
- breaking Since `truss-transfer` is frequently updated and tightly coupled with the `truss` library and Baseten platform, new versions might introduce subtle changes in `PyModelRepo` parameters or expected behavior without explicit major version bumps. This is particularly relevant when `truss-transfer` is bundled with `truss`.
Install
-
pip install truss-transfer
Imports
- truss_transfer
import truss_transfer
- PyModelRepo
from truss_transfer import PyModelRepo
Quickstart
import truss_transfer
import os
# Example: Define a Hugging Face model repository using PyModelRepo
# For actual use, 'hf_access_token' would be an environment variable or Baseten secret.
# Replace 'your-hf-model' with an actual model ID and 'main' with a valid revision.
hf_model_repo = truss_transfer.PyModelRepo(
repo_id=os.environ.get('HF_MODEL_ID', 'microsoft/DialoGPT-medium'),
revision=os.environ.get('HF_MODEL_REVISION', 'main'),
volume_folder='dialogpt_model_cache',
runtime_secret_name='hf_access_token'
)
print(f"Defined Hugging Face model repository: {hf_model_repo.repo_id}")
# Example: Define a GCS model repository
# 'gcs-service-account-jsn' would be a Baseten secret containing GCS service account JSON.
gcs_model_repo = truss_transfer.PyModelRepo(
repo_id=os.environ.get('GCS_BUCKET_PATH', 'gs://my-bucket/my-model/'),
revision='',
volume_folder='gcs_model_cache',
runtime_secret_name='gcs-service-account-jsn',
kind='gcs'
)
print(f"Defined GCS model repository: {gcs_model_repo.repo_id}")
# In a typical Truss deployment, these PyModelRepo objects are often used
# within a `config.yaml` or a `model.py` for model loading and data transfer.
# This example primarily shows how to instantiate the objects.