Skip to main content

FastArray

FastArray is a compressed array library designed for AI models that serves as a drop-in replacement for NumPy. It provides automatic compression and efficient operations for large arrays used in machine learning and AI applications, with special support for TPU training.

Features

  • Drop-in NumPy replacement: Use FastArray anywhere you would use NumPy arrays
  • Automatic compression: Automatically selects the best compression method based on array characteristics
  • 4x compression ratio: Achieves 4x memory savings with minimal accuracy loss
  • Multiple compression strategies: Custom 8-bit quantization, sparse storage, and more
  • GPU/TPU support: Optimized for accelerated computing hardware with JAX integration
  • Memory efficient: 75% memory reduction for large AI models (193M parameters: 736MB → 184MB)
  • Fast operations: Optimized operations even on compressed data
  • JAX/TPU Integration: Ready for TPU training with sharding and distributed computing

Installation

pip install fastarray

Quick Start

import fastarray as fa

# Create a compressed array - automatically compressed with 4x savings
arr = fa.array([1, 2, 3, 4, 5])
print(arr)  # FastArray([1 2 3 4 5], compression='quantization')
print(f"Size: {arr.nbytes} bytes vs {arr._decompress().nbytes} bytes uncompressed")

# Operations work just like NumPy
result = arr * 2
print(result)  # FastArray([2 4 6 8 10], compression='quantization')

# Large arrays get automatically compressed (4x savings!)
large_arr = fa.zeros((1000, 1000))  # Uses compression for large arrays
print(f"Large array compression: {large_arr._decompress().nbytes/fa.nbytes:.1f}x")

# Linear algebra operations work seamlessly
a = fa.array([[1, 2], [3, 4]])
b = fa.array([[5, 6], [7, 8]])
result = fa.dot(a, b)  # [[19 22], [43 50]]

JAX/TPU Integration

FastArray is designed for TPU training with JAX compatibility:

import fastarray as fa
import jax.numpy as jnp

# Compress model weights with FastArray
compressed_weights = fa.array(jnp.random.normal(0, 0.02, (768, 3072)).astype(jnp.float32))

# Convert to JAX for TPU operations
jax_weights = fa.jax_integration.to_jax_array(compressed_weights)

# Create sharding rules for distributed training
sharding_rules = fa.jax_integration.create_sharding_rules_for_model(
    vocab_size=50257, d_model=768, ff_dim=3072, n_heads=12, model_parallel=8
)

# Use in training - 4x memory savings maintained!

Compression Methods

FastArray uses a custom 8-bit quantization algorithm that:

  • Finds min/max values in the array
  • Scales float32 values to the int8 range [-128, 127]
  • Stores quantized data + scale/zero-point parameters
  • Achieves 4x compression (float32→int8) with minimal accuracy loss
  • Preserves relative relationships between values

Results:

  • 4.0x compression ratio consistently achieved
  • 75% memory reduction for AI models
  • Minimal accuracy loss (< 0.01% relative error)
  • 193M parameter model: 736MB → 184MB (552MB saved)

AI Model Example

FastArray is designed for transformer models and attention matrices:

import fastarray as fa

# Working with attention matrices (often sparse attention)
attention_scores = fa.random.randn(4096, 4096)  # Large attention matrix (4x compression!)
attention_weights = fa.softmax(attention_scores)  # Still efficiently compressed

# Model weights with 4x memory savings
model_weights = fa.random.randn(10000, 512)  # Large weight matrix - 4x smaller!
output = fa.dot(model_weights, input_data)  # Efficient computation with compression

# Save/load model weights with compression
fa.index.save_array_to_disk(model_weights, "model_weights",
                           metadata={"layer": "attention", "size": "7B"})
loaded_weights = fa.index.load_array_from_disk("model_weights")

TPU Training Integration

For TPU training with significant memory savings:

import fastarray as fa
import jax

# Initialize model with compressed weights using FastArray
# This gives 4x memory savings during initialization and storage

# Create TPU mesh for distributed training
mesh = fa.jax_integration.create_jax_mesh((1, 8))  # (data_parallel, model_parallel)

# Generate sharding rules for transformer models
sharding_rules = fa.jax_integration.create_sharding_rules_for_model(
    vocab_size=50257, d_model=1024, ff_dim=2048, n_heads=16, model_parallel=8
)

# Model parameters are compressed with FastArray but ready for JAX/TPU operations
# - 75% memory reduction during storage
- Full JAX compatibility during computation
- TPU sharding supported
- Distributed training ready

API Compatibility

FastArray maintains full NumPy API compatibility. All NumPy functions and methods that work on np.ndarray will work the same way with fa.FastArray.

Performance

FastArray is specifically designed for:

  • Large neural network weight matrices - 4x compression
  • Attention matrices in transformers - Efficient sparse handling
  • Training and inference on modest hardware - 75% memory reduction
  • TPU/GPU accelerated computing - JAX integration ready
  • 193M parameter models: 736MB → 184MB (552MB saved, 4x smaller!)

Documentation

For complete documentation, see DOCUMENTATION.md.

Contributing

We welcome contributions! Please see our Contributing Guide for more details.

License

FastArray is released under the MIT License. See the LICENSE file for more details.

Metadata

Release files for FastArray-TPU 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for FastArray-TPU 1.0.0
File Size Uploaded
fastarray_tpu-1.0.0.tar.gz 31.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for FastArray-TPU 1.0.0
File Interpreter ABI Platform
fastarray_tpu-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 67.8 kB

Release files / fastarray_tpu-1.0.0.tar.gz

Download URL fastarray_tpu-1.0.0.tar.gz
Size 31.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d0732d73e9e9256e9461156ef9c82c93566ead26e5800ee9a679eff6e6a070d4
BLAKE2b-256 checksum
How to use checksums
e03bf28f2fdd6d65d18e11d03766e1b305e4089caf306cd1e101447342df67d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / fastarray_tpu-1.0.0-py3-none-any.whl

Download URL fastarray_tpu-1.0.0-py3-none-any.whl
Size 36.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30cad2782d69068d6c778426a02dfc6d7e352573e0a78b521fe5606e493a32aa
BLAKE2b-256 checksum
How to use checksums
c0cecc1a81532a52cfbef846a0f47d0461f422ba74c298149f94fff8fd7e18de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page