Expand description
Neural Compression
10x compression using learned codebooks for model weights.
§Architecture
┌─────────────────────────────────────────────────────────────────┐
│ Neural Compression │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Traditional: weights.safetensors (16GB) │
│ ↓ LZ4 │
│ weights.hct (8GB) — 2:1 compression │
│ │
│ Neural: weights.safetensors (16GB) │
│ ↓ Learned Encoder │
│ weights.nct (1.6GB) — 10:1 compression │
│ ↓ Learned Decoder (GPU) │
│ weights (reconstructed) │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Compression Pipeline │ │
│ │ │ │
│ │ Encoder (offline, CPU): │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ Weight │ -> │ Vector │ -> │ Codebook│ -> indices │ │
│ │ │ Tensor │ │ Quantize│ │ Lookup │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ │ │
│ │ │ │
│ │ Decoder (runtime, GPU): │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ Indices │ -> │ Codebook│ -> │ Residual│ -> weights │ │
│ │ │ │ │ Lookup │ │ Refine │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ │ │
│ └──────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘§Layer-Specific Codebooks
Different layer types use different codebook sizes:
- Attention Q/K: 4096 centroids, 12-bit indices
- Attention V/O: 8192 centroids, 13-bit indices
- FFN: 2048 centroids, 11-bit indices
- Normalization: 256 centroids, 8-bit (lossless)
Modules§
- prelude
- Prelude for common imports
Structs§
- Codebook
- A codebook containing centroids for vector quantization
- Codebook
Config - Configuration for a codebook
- Codebook
Stats - Statistics from codebook training
- Codebook
Trainer - Codebook trainer using K-means clustering
- Decoder
Config - Configuration for the decoder
- Encoded
Tensor - Encoded tensor data
- Encoder
Config - Configuration for the encoder
- GpuDecoder
- GPU-accelerated decoder (placeholder for CUDA implementation)
- Layer
Codebook - Collection of codebooks for different layer types
- NctFile
- NCT file container
- NctHeader
- NCT (Neural Compressed Tensor) file header.
- NctMetadata
- NCT file metadata
- Neural
Decoder - Neural decoder for model decompression
- Neural
Encoder - Neural encoder for model compression
- Refiner
Config - Configuration for residual refiner
- Residual
Refiner - Residual refiner for improving reconstruction quality
- Training
Config - Configuration for codebook training
Enums§
- Layer
Type - Layer type for codebook selection
- Neural
Error - Errors that can occur during neural compression
Constants§
- DEFAULT_
COMPRESSION_ RATIO - Default compression ratio target
- NCT_
EXTENSION - File extension for neural compressed tensors
- NCT_
MAGIC - Magic bytes for NCT format
Type Aliases§
- Result
- Result type for neural compression operations