Overview of Baseten Performance Reverse Proxy
mainbaseten-performance-client-core library. It supports both HTTP/1.1 and HTTP/2 and is designed to be deployed via Docker.repository·main·Indexed 22 days ago
https://github.com/basetenlabs/trussA CLI tool and library designed to simplify the deployment and serving of AI/ML models on Baseten. It handles containerization, dependency management, and GPU configuration. The package also includes the @basetenlabs/performance-client for Node.js, providing high-performance capabilities for embeddings, reranking, and classification via a specialized PerformanceClient with support for HTTP/2, request hedging, and custom proxy configurations.
baseten-performance-client-core library. It supports both HTTP/1.1 and HTTP/2 and is designed to be deployed via Docker.The baseten_performance_client is a high-performance Python library designed for massive concurrent POST requests to Baseten.co endpoints (embeddings, reranking, classification) or any other URL.
Key features include:
pyo3, reqwest, and tokio.@basetenlabs/performance-client-linux-x64-gnu package provides the specific x86_64-unknown-linux-gnu binary for the @basetenlabs/performance-client. Use this package if your target environment is a Linux system with an x86_64 architecture using the GNU C library (glibc).@basetenlabs/performance-client-win32-x64-msvc package provides the specific x86_64-pc-windows-msvc binary required for running the @basetenlabs/performance-client on Windows 64-bit systems using the MSVC toolchain.armv7-linux-androideabi binary for the @basetenlabs/performance-client. It is specifically intended for use in Android environments running on ARMv7 architecture.@basetenlabs/performance-client-darwin-universal package provides the universal-apple-darwin binary for the @basetenlabs/performance-client library. This package is intended for use on macOS (Darwin) environments that require a universal binary compatible with multiple Apple architectures.@basetenlabs/performance-client library. It is intended for use on Apple Silicon (ARM64) macOS environments.A standard Truss model requires a Model class in model/model.py with three specific methods:
__init__(self, **kwargs): Initializes the class instance.load(self): Runs once when the server starts to load weights, tokenizers, or pipelines into memory.predict(self, request: Dict) -> Dict: Handles inference. For non-streaming models, this method should accept a dictionary and return a JSON-serializable dictionary.class Model:
def __init__(self, **kwargs) -> None:
self.tokenizer = None
self.model = None
def load(self):
# Load model and tokenizer here
pass
def predict(self, request: Dict) -> Dict:
# Perform inference and return a dictionary
return {"output": "result"}Every Truss requires a Model class in model/model.py with three specific member functions:
__init__(self, **kwargs): Initializes the object. It must capture kwargs["secrets"] if you need to access Baseten secrets.load(self): Runs once when the model server starts. Use this to load your model (e.g., weights, pipelines) into a class property like self._model.predict(self, model_input): Runs on every inference request. It handles the input and returns a JSON-serializable output.from transformers import pipeline
class Model:
def __init__(self, **kwargs) -> None:
self._secrets = kwargs["secrets"]
self._model = None
def load(self):
self._model = pipeline(
"fill-mask",
model="baseten/docs-example-gated-model"
)
def predict(self, model_input):
return self._model(model_input)Request hedging allows the client to send duplicate requests after a specified hedge_delay to mitigate tail latency. This is configured via RequestProcessingPreference.
from baseten_performance_client import RequestProcessingPreference
preference = RequestProcessingPreference(
hedge_delay=0.5, # Send hedge request after 0.5s
max_chars_per_request=256000,
total_timeout_s=360
)
response = client.embed(input=texts, model="my_model", preference=preference)To significantly reduce cold start times, you can cache model weights at build time. This bakes the weights directly into the Truss image, making them available immediately when a model replica starts.
When using this method:
Truss separates IO-bound tasks from compute-bound tasks using preprocess and postprocess methods. This architecture prevents IO operations (like downloading files from a URL) from blocking the compute resources (like a GPU) and allows for higher throughput.
predict method: Subject to the predict_concurrency limit defined in config.yaml. This ensures the GPU/CPU is not overloaded.preprocess and postprocess methods: These run on separate threads and are not subject to the predict_concurrency limit.Example Scenario: If predict_concurrency is set to 5 and you receive 10 requests, all 10 requests will begin preprocess in parallel. However, only 5 will be allowed to enter the predict stage at a time. This ensures that while the model is waiting for IO, the compute engine remains fully utilized.