Skip to main content
Looking for memory snapshots, container snapshots, or a warm pool of preloaded containers? See Memory Checkpointing, which snapshots a ready container’s GPU and CPU memory so subsequent containers restore instantly.

Container vs Storage Volume for Model Loading

Two main options exist for storing model weights:
  1. Inside the Container: Packaging model weights directly in your container image
    • Pros:
      • Faster initial startup as weights are already in the container
      • No need to download or transfer weights from external storage
    • Cons:
      • Much larger container size, leading to longer deployment times
      • Less flexibility to update model weights without rebuilding container
  2. Storage Volume: Storing weights in a persistent storage volume
    • Pros:
      • Smaller container sizes and faster deployments
      • Easy to update model weights without rebuilding container
    • Cons:
      • Initial cold start includes time to load weights from storage
      • Requires managing separate storage infrastructure
Storing model weights in a storage volume works best for most applications. For smaller models requiring minimal cold start times, container storage may be more appropriate.
Increasing core counts can parallelize downloads, improving pull-through times for large images. This benefit becomes particularly notable when handling large files from the storage layer, as multiple cores process different parts simultaneously, reducing overall download time.

Loading Models from Storage Volume Faster

One of the biggest factors in model startup time is loading the model from storage into GPU memory. For example, in larger models of 20B+ parameters, it can take over 40 seconds to load using a normal Hugging Face load, even with 2GB/s transfer speeds from persistent storage. The underlying hardware is optimized for fast model loading, but several additional techniques can further reduce cold-start times. Tensorizer is a library that loads models from storage into GPU memory in a single step. Initially built for S3, it also works with Cerebrium’s persistent storage (nearly 2GB/s read speed). For large models (20B+ parameters), loading time decreases by 30–50%, with even greater improvements for larger models. See the GitHub page for details on the underlying methods. The following section covers using Tensorizer to load a model from storage directly 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. On the next deployment start, load the serialised model from storage into GPU memory in a single step:
Tensorizer works with any model type — Transformers, Diffusers, scikit-learn, or custom PyTorch. The only requirement is the ability to initialize an empty model. The deserializer restores weights into that empty model.