Skip to main content

SGLang — Storage File Analysis

Overview

SGLang reads model weights from persistent storage and optionally writes hierarchical cache data. It does not maintain its own custom file format for model weights — it leverages the HuggingFace ecosystem (safetensors format) and adds specialized loaders.


Model Weight Files

SafeTensors Format (.safetensors)

Location: Specified by --model-path (HuggingFace model ID or local path)

Loading Chain:

  1. ModelRunner.load_model() (model_runner.py:1071) — Entry point
  2. ModelRunner._load_model() (model_runner.py:101) — Creates model architecture
  3. loader.load_model() (model_runner.py:1159) — Loads weights into the model

Model Loaders (loader.py):

LoaderClassWhen Used
DefaultModelLoaderloader.py:302Standard safetensors/PyTorch loading
LayeredModelLoaderloader.py:712Layer-by-layer loading for memory efficiency
QuantizedRLModelLoaderloader.py:786Quantized models (GPTQ, AWQ)
GGUFModelLoaderloader.py:1974GGUF format models
BitsAndBytesModelLoaderloader.py:1496bitsandbytes quantized models
ShardedStateLoaderloader.py:1315Load from PyTorch sharded state dict
RemoteModelLoaderloader.py:2413Load from remote server
RemoteInstanceModelLoaderloader.py:2080Load from remote SGLang instance
DummyModelLoaderloader.py:1259Testing (no real weights)
ModelOptModelLoaderloader.py:2594NVIDIA ModelOpt quantized models

Default Loading Flow:

SafeTensors File Format:

[8 bytes] Header length (uint64, little-endian)
[N bytes] JSON header: {"__metadata": {...}, "tensor_name": {dtype, shape, data_offsets}}
[Padding] Alignment to 8-byte boundary
[N bytes] Raw tensor data (contiguous, mmap-able)

The safetensors format is preferred over PyTorch's .bin format because:

  • Memory-safe: No pickle deserialization (no arbitrary code execution)
  • Mmap-friendly: Tensors can be memory-mapped without loading into RAM
  • Fast: Zero-copy loading for large models

Weight Update Storage

Dynamic Weight Updates

SGLang supports hot-swapping model weights at runtime:

EndpointStorage SourceLoader
/update_weights_from_diskLocal filesystem pathRe-loads via DefaultModelLoader
/update_weights_from_tensorIn-memory tensor dictDirect parameter copy
/update_weights_from_distributedRemote sourceRemoteModelLoader
/update_weights_from_ipcIPC shared memoryDirect memory copy

Weight updates are applied in-place on the GPU without reinitializing the model architecture, enabling fast model switching.


Hierarchical Cache Storage (HiCache)

HiCacheFile (hicache_storage.py:303)

Purpose: Persistent hierarchical cache that can offload KV cache pages to disk or remote storage.

Configuration:

FieldTypePurpose
hicache_storage_backendstr/NoneBackend type (file, etc.)
hicache_write_policystr"write_through" or "write_back"

The HiCache storage extends the radix cache with a secondary storage tier:

  • Write-through: KV cache pages are written to storage immediately when created
  • Write-back: KV cache pages are written lazily when evicted from GPU memory

Configuration Files

SGLang reads the following configuration files during startup:

FileLocationPurpose
config.jsonModel directoryHuggingFace model config (architecture, dimensions, attention type)
tokenizer.json / tokenizer.modelModel directoryTokenizer vocabulary and merges
tokenizer_config.jsonModel directoryTokenizer metadata, chat template
generation_config.jsonModel directoryDefault generation parameters
*.safetensorsModel directoryModel weight files
adapter_model.safetensorsLoRA directoryLoRA adapter weights

Crash Dump Storage

When --crash-dump-folder is specified, SGLang writes diagnostic dumps on crashes:

FileContent
scheduler_dump_*.jsonScheduler state at crash time
detokenizer_dump_*.jsonDetokenizer state at crash time

Summary

SGLang does not define any custom persistent file format. It relies on the HuggingFace safetensors format for model weights and adds specialized loaders for various quantization schemes and remote sources. The only persistent storage it writes is the optional HiCache (for KV cache offloading) and crash dumps.