Skip to main content

High-performance zero-copy tensor protocol

Project description

Tenso Banner

Tenso

Up to 12.6x faster than Apache Arrow. 32x less CPU than SafeTensors.

Zero-copy, SIMD-aligned tensor protocol for high-performance ML infrastructure.

PyPI version Python 3.10+ License: Apache 2.0


Why Tenso?

Most serialization formats are designed for general data or disk storage. Tenso is focused on network tensor transmission where every microsecond matters.

The Problem

Traditional formats waste CPU cycles during deserialization:

  • SafeTensors: 41.3% CPU usage (great for disk, overkill for network)
  • Pickle: 43.3% CPU usage + security vulnerabilities
  • Arrow: Fast, but 12.6x slower than Tenso for large tensors

The Solution

Tenso achieves true zero-copy with:

  • Minimalist Header: Fixed 8-byte header eliminates JSON parsing overhead.
  • 64-byte Alignment: SIMD-ready padding ensures the data body is cache-line aligned.
  • Direct Memory Mapping: The CPU points directly to existing buffers without copying.

Result: ~1.3% CPU usage vs >40% for SafeTensors/Pickle.


Benchmarks

System: Python 3.12.9, NumPy 2.3.5, 12 CPU cores, macOS

Deserialization Speed (8192×8192 Float32 Matrix)

Format Time CPU Usage Speedup
Tenso 0.064ms 1.3% 1x
Arrow 0.810ms 1.2% 12.6x slower
SafeTensors 2.792ms 41.3% 43x slower
Pickle 3.031ms 43.3% 47x slower

**

Stream Reading Performance (95MB Packet)

Method Time Throughput Speedup
Tenso read_stream 7.05ms 13,534 MB/s 1x
Naive loop 7,399.7ms 12.8 MB/s 1,050x slower

**


Installation

pip install tenso

Quick Start (v0.10.0)

Basic Serialization

import numpy as np
import tenso

# Create tensor
data = np.random.rand(1024, 1024).astype(np.float32)

# Serialize
packet = tenso.dumps(data)

# Deserialize (Zero-copy view)
restored = tenso.loads(packet)

Async I/O

import asyncio
import tenso

async def handle_client(reader, writer):
    # Asynchronously read a tensor from the stream
    data = await tenso.aread_stream(reader)
    
    # Process and write back
    await tenso.awrite_stream(data * 2, writer)

**

FastAPI Integration

from fastapi import FastAPI
import numpy as np
from tenso.fastapi import TensoResponse

app = FastAPI()

@app.get("/tensor")
async def get_tensor():
    data = np.ones((1024, 1024), dtype=np.float32)
    return TensoResponse(data) # Zero-copy streaming response

**


Advanced Features

GPU Acceleration (Direct Transfer)

Supports fast transfers between Tenso streams and device memory for CuPy, PyTorch, and JAX using pinned host memory.

import tenso.gpu as tgpu

# Read directly from a stream into a GPU tensor
torch_tensor = tgpu.read_to_device(stream, device_id=0) 

Sparse Formats & Bundling

Tenso natively supports complex data structures beyond simple dense arrays:

  • Sparse Matrices: Direct serialization for COO, CSR, and CSC formats.
  • Dictionary Bundling: Pack multiple tensors into a single nested dictionary packet.
  • LZ4 Compression: Optional high-speed compression for sparse or redundant data.

Data Integrity (XXH3)

Protect your tensors against network corruption with ultra-fast 64-bit checksums:

# Serialize with 64-bit checksum footer
packet = tenso.dumps(data, check_integrity=True)

# Verification is automatic during loads()
restored = tenso.loads(packet) 

Protocol Design

Tenso uses a minimalist structure designed for direct memory access:

┌─────────────┬──────────────┬──────────────┬────────────────────────┬──────────────┐
│   HEADER    │    SHAPE     │   PADDING    │    BODY (Raw Data)     │    FOOTER    │
│   8 bytes   │  Variable    │   0-63 bytes │   C-Contiguous Array   │   8 bytes*   │
└─────────────┴──────────────┴──────────────┴────────────────────────┴──────────────┘
                                                                        (*Optional)

The padding ensures the body starts at a 64-byte boundary, enabling AVX-512 vectorization and zero-copy memory mapping.


Use Cases

  • Model Serving APIs: 12.6x faster deserialization saves massive CPU overhead on inference nodes.
  • Distributed Training: Efficiently pass gradients or activations between nodes (Ray, Spark).
  • GPU-Direct Pipelines: Stream data from network cards to GPU memory with minimal host intervention.
  • Real-time Robotics: Sub-millisecond latency for high-frequency sensor fusion (LIDAR, Radar).

Contributing

Contributions are welcome! We are currently looking for help with:

  • Rust Core: Porting serialization logic to Rust for even lower overhead.
  • gRPC Integration: Native Tenso marshaling for gRPC services.
  • C++ / JavaScript Clients: Extending the protocol to other ecosystems.

License

Apache License 2.0 - see LICENSE file.

Citation

@software{tenso2025,
  author = {Khushiyant},
  title = {Tenso: High-Performance Zero-Copy Tensor Protocol},
  year = {2025},
  version = {0.10.0},
  url = {[https://github.com/Khushiyant/tenso](https://github.com/Khushiyant/tenso)}
}

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

tenso-0.10.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

tenso-0.10.1-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file tenso-0.10.1.tar.gz.

File metadata

  • Download URL: tenso-0.10.1.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tenso-0.10.1.tar.gz
Algorithm Hash digest
SHA256 b3f87bed9e0713c25f375b76e20de46bad114edd0d5342fc3cf8526eec7d4b12
MD5 f1ea64f571ab930f33d652516beb5e26
BLAKE2b-256 46f1c285724a9bbb6d3dcda7112c963d96a9eb040c4982ec334f36172cac3672

See more details on using hashes here.

Provenance

The following attestation bundles were made for tenso-0.10.1.tar.gz:

Publisher: release.yml on Khushiyant/tenso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tenso-0.10.1-py3-none-any.whl.

File metadata

  • Download URL: tenso-0.10.1-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tenso-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 079f935c6da1c14cd922dcc831ad3b2d94237a2c75c348c6a3ff1bfc85afa338
MD5 8ef6f135ccc1e8905e143b0bb4127a87
BLAKE2b-256 7d864d8af5a4bd8fc1ef3a7e19f70557a2acd36d98a528a7d5d9bbf3c43eea04

See more details on using hashes here.

Provenance

The following attestation bundles were made for tenso-0.10.1-py3-none-any.whl:

Publisher: release.yml on Khushiyant/tenso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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