Skip to main content

Distributed PyTorch file transfer for Baseten - Environment-aware, lock-free file transfer management

Project description

https://www.notion.so/ml-infra/mega-base-cache-24291d247273805b8e20fe26677b7b0f

B10 Transfer

PyTorch file transfer for Baseten deployments.

Usage

import b10_transfer

# Inside model.load() function
def load()
    # Load cache before torch.compile()
    cache_loaded = b10_transfer.load_compile_cache()

    # ...

    # Your model compilation
    model = torch.compile(model)
    # Warm up the model with dummy prompts, and arguments that would be typically used in your requests (e.g resolutions)
    dummy_input = "What is the capital of France?"
    model(dummy_input)

    # ...

    # Save cache after compilation
    if not cache_loaded:
        b10_transfer.save_compile_cache()

Configuration

Configure via environment variables:

# Cache directories
export TORCH_CACHE_DIR="/tmp/torchinductor_root"      # Default
export B10FS_CACHE_DIR="/cache/model/compile_cache"   # Default  
export LOCAL_WORK_DIR="/app"                          # Default

# Cache limits
export MAX_CACHE_SIZE_MB="1024"                       # 1GB default

How It Works

Environment-Specific Caching

The library automatically creates unique cache keys based on your environment:

torch-2.1.0_cuda-12.1_cc-8.6_triton-2.1.0 → cache_a1b2c3d4e5f6.latest.tar.gz
torch-2.0.1_cuda-11.8_cc-7.5_triton-2.0.1 → cache_x9y8z7w6v5u4.latest.tar.gz
torch-2.1.0_cpu_triton-none                → cache_m1n2o3p4q5r6.latest.tar.gz

Components used:

  • PyTorch version (e.g., torch-2.1.0)
  • CUDA version (e.g., cuda-12.1 or cpu)
  • GPU compute capability (e.g., cc-8.6 for A100)
  • Triton version (e.g., triton-2.1.0 or triton-none)

Cache Workflow

  1. Load Phase (startup): Generate environment key, check for matching cache in B10FS, extract to local directory
  2. Save Phase (after compilation): Create archive, atomic copy to B10FS with environment-specific filename

Lock-Free Race Prevention

Uses journal pattern with atomic filesystem operations for parallel-safe cache saves.

API Reference

Functions

  • load_compile_cache() -> bool: Load cache from B10FS for current environment
  • save_compile_cache() -> bool: Save cache to B10FS with environment-specific filename
  • clear_local_cache() -> bool: Clear local cache directory
  • get_cache_info() -> Dict[str, Any]: Get cache status information for current environment
  • list_available_caches() -> Dict[str, Any]: List all cache files with environment details

Exceptions

  • CacheError: Base exception for cache operations
  • CacheValidationError: Path validation or compatibility check failed

Performance Impact

Debugging

Enable debug logging:

import logging
logging.getLogger('b10_transfer').setLevel(logging.DEBUG)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

b10_transfer-0.2.3.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

b10_transfer-0.2.3-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

Details for the file b10_transfer-0.2.3.tar.gz.

File metadata

  • Download URL: b10_transfer-0.2.3.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.13 Linux/5.15.0-1048-gke

File hashes

Hashes for b10_transfer-0.2.3.tar.gz
Algorithm Hash digest
SHA256 5ef695239fc6b317fdc55b23059220b83de19e6113b786bcc4a00cb7f5173813
MD5 6be592cd8fb4604ef931c6e0c1433f70
BLAKE2b-256 a3ad857507fffbd24e842e8c30cb67a591d81b310dc8a87d14fc22d0f5e82263

See more details on using hashes here.

File details

Details for the file b10_transfer-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: b10_transfer-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 30.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.13 Linux/5.15.0-1048-gke

File hashes

Hashes for b10_transfer-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 072110c92782bfe03afb584eecc8093d76f98009eb9ee595ecbf980d4efb7246
MD5 9d201d1703fdab5177033fc20bfceab1
BLAKE2b-256 6ec9ec0ed7214bbe8cefc5913f4bdf9f47afe22dc1b363f731b0ccb1a40630c8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page