ztensor
Simple tensor serialization format
Key Features
- Simple Spec — Minimalist spec for easy parsing.
- Zero-Copy Access — Instant memory-mapping (mmap) with no extra RAM copying overhead.
- Efficient Writes — Supports streaming and append-only operations without rewriting files.
- Future-Proof — Decouples physical storage from logical representation for long-term compatibility.
Tools
- Rust Core — High-performance, SIMD-aligned implementation.
- Python API — First-class bindings for NumPy and PyTorch.
- Universal Converters — CLI tools to easily convert Pickle, SafeTensors, and GGUF files.
Comparison
| Feature | zTensor | SafeTensors | GGUF | Pickle | HDF5 |
|---|---|---|---|---|---|
| Zero-Copy Read | ✅ | ✅ | ✅ | ❌ | ⚠️ |
| Safe (No Exec) | ✅ | ✅ | ✅ | ❌ | ✅ |
| Streaming / Append | ✅ | ❌ | ❌ | ❌ | ✅ |
| Sparse Tensors | ✅ | ❌ | ❌ | ✅ | ✅ |
| Compression | ✅ | ❌ | ❌ | ❌ | ✅ |
| Quantization | ✅ | ✅ | ✅ | ✅ | ✅ |
| Parser Complexity | 🟢 Low | 🟢 Low | 🟡 Med | 🔴 High | 🔴 High |
Benchmark

See benchmark for more details.
Installation
Python
Rust
[]
= "0.1"
CLI
Quick Start: Python
Basic Usage with NumPy
# Write tensors
# Read tensors (zero-copy where possible)
# Returns a numpy-like view
=
PyTorch Integration
# Write PyTorch tensors directly
=
# Read back as PyTorch tensors
# 'to="torch"' returns a torch.Tensor sharing memory with the file (if mmap)
=
Sparse Tensors
Supports CSR (Compressed Sparse Row) and COO (Coordinate) formats.
=
# Add CSR tensor
# Read back as scipy.sparse.csr_matrix
=
Compression
Use Zstandard (zstd) compression to reduce file size.
Quick Start: Rust
Basic Usage
use ;
// Write
let mut writer = create?;
// Zero-copy generic write with generic Compression
writer.add_object?;
writer.finalize?;
// Read
let mut reader = open?;
// Read as specific type (automatically handles endianness)
let weights: = reader.read_object_as?;
Sparse Tensors
// Write CSR (using generic method)
writer.add_csr_object?;
// Read CSR
let csr = reader.?;
println!;
Compression
// Write with compression (level 3)
writer.add_object?;
// Read (auto-decompresses)
let data: = reader.read_object_as?;
CLI
The ztensor CLI tool allows you to inspect and manipulate zTensor files.
Inspect Metadata
Print tensor names, shapes, and properties.
Convert Other Formats
Convert SafeTensors, GGUF, or Pickle files to zTensor.
# Auto-detect format from extension
# Explicit format with compression (default level 3)
# Specify compression level (1-22)
# Delete originals after conversion
Compression Tools
# Compress an existing raw file (default level 3)
# Compress with specific level (1-22)
# Decompress a file
File Management
# Merge multiple files into one
# Migrate legacy v0.1.0 files to v1.1.0
Download from HuggingFace
Download safetensors from HuggingFace and convert to zTensor:
Supported Data Types
| Type | Description |
|---|---|
float32, float16, bfloat16, float64 |
Floating point |
int8, int16, int32, int64 |
Signed integers |
uint8, uint16, uint32, uint64 |
Unsigned integers |
bool |
Boolean |
File Format
See SPEC.md for the complete specification.
License
MIT