Decrease Model Loading Time
Decrease the time it takes to load your model from storage into GPU
One of the biggest contributions to the startup time of your model is the time it takes to load your model from storage into GPU memory. For example, in larger models of 20B+ parameters, it can take >40s for your model to be loaded using a normal huggingface load, even with the 2GB/s transfer speeds from persistent storage.
While we’ve optimised the underlying hardware to load models as fast as possible, there are a few things you can do to decrease the time it takes to load your model and, therefore, your coldstart times.
Using a serialisation and zero-copy initialisation libraries
Tensorizer (recommended)
Tensorizer is a library that allows you to load your model from storage into GPU memory in a single step.
While initially built to fetch models from S3, it can be used to load models from file as well and so, can be used to load models from Cerebrium’s persistent storage, which features a near 2GB/s read speed.
In the case of large models (20B+ parameters), we’ve observed a 30–50% decrease in model loading time which further increases with larger models.
For more information on the underlying methods, take a look at their GitHub page here.
In this section below, we’ll show you how to use Tensorizer to load your model from storage straight into GPU memory in a single step.
Installation
Add the following to your [cerebrium.dependencies.pip]
in your cerebrium.toml file to install Tensorizer in your deployment:
Usage
To use Tensorizer, you need to first serialise your model and save it to your persistent-storage.
This will convert your model to a protocol buffer serialised format that is optimised for faster transfer speeds and fast loading into GPU memory.
Then, the next time your deployment starts, you can load your serialised model from storage into GPU memory in a single step. You would do this as follows:
Note that your model does not need to be a transformers or even a huggingface model. If you have a diffusers, scikit-learn or even a custom pytorch model, you can still use Tensorizer to load your model from storage into GPU memory in a single step. The only requirement to obtain the speedup from deserialization is that you can initialize an empty model. The Deserialiser object will then restore the weights into the empty model.