ztensor
Simple tensor serialization format
Key Features
- 🛡️ Simple Spec — Minimalist spec for easy parsing.
- 🚀 Zero-Copy Access — Instant memory-mapping (mmap) with no RAM overhead.
- 🔄 Efficient Writes — Supports streaming and append-only operations without rewriting files.
- 🔮 Future-Proof — Decouples physical storage from logical representation for long-term compatibility.
Ecosystem
- 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 Support | ✅ | ❌ | ❌ | ✅ | ✅ |
| Compression | ✅ | ❌ | ❌ | ❌ | ✅ |
| Quantization | ✅ | ✅ | ✅ | ✅ | ✅ |
| Parser Complexity | 🟢 Low | 🟢 Low | 🟡 Med | 🔴 High | 🔴 High |
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?;
writer.add_tensor?;
writer.finalize?;
// Read
let mut reader = open?;
// Read as specific type (automatically handles endianness)
let weights: = reader.read_tensor_as?;
Sparse Tensors
// Write CSR
writer.add_csr_tensor?;
// Read CSR
let csr = reader.?;
println!;
Compression
// Write with compression
writer.add_tensor?;
// Read (auto-decompresses)
let data: = reader.read_tensor_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
# Delete originals after conversion
Compression Tools
# Compress an existing raw file
# Decompress a file
Merge Files
Combine multiple zTensor files into one.
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