Hamerspace 🔨
A compiler-style optimization pass for non-LLM machine learning models
Hamerspace is a model compression and optimization engine that orchestrates existing open-source toolkits to compress and optimize computer vision, audio, time-series, and tabular ML models.
Features
- 🎯 Goal-oriented optimization: Specify what you want (size, latency, accuracy) and let Hamerspace figure out how
- 🔧 Multi-backend orchestration: Automatically selects and composes tools from PyTorch, TensorFlow, ONNX, OpenVINO, TVM, and more
- 📊 Comprehensive benchmarking: Measures size, latency, and accuracy before and after optimization
- 🎨 Hardware-aware: Optimizes for specific target hardware (CPU, ARM, edge devices)
- 📦 Deployment-ready: Produces optimized model artifacts ready for production
Installation
pip install hamerspace
For full backend support (OpenVINO, TVM, bitsandbytes):
pip install hamerspace[full]
Quick Start
from hamerspace import Optimizer, OptimizationGoal, Constraints
# Load your trained model
optimizer = Optimizer.from_pytorch("model.pt")
# Define constraints
constraints = Constraints(
target_size_mb=10, # Must be under 10MB
max_latency_ms=50, # Must inference in <50ms
max_accuracy_drop=0.02, # Max 2% accuracy drop
target_hardware="cpu" # Optimize for CPU
)
# Optimize
result = optimizer.optimize(
goal=OptimizationGoal.AUTO,
constraints=constraints
)
# Save optimized model
result.save_model("optimized_model.onnx")
# View report
print(result.report)
Optimization Goals
OptimizationGoal.QUANTIZE: Apply quantization (INT8, INT4)OptimizationGoal.PRUNE: Remove unnecessary weightsOptimizationGoal.DISTILL: Knowledge distillation (requires training data)OptimizationGoal.AUTO: Automatically select best techniques
Supported Frameworks
Input Models
- PyTorch (.pt, .pth)
- TensorFlow (.h5, SavedModel)
- ONNX (.onnx)
Backend Toolkits
- PyTorch (quantization, pruning)
- TensorFlow (quantization)
- ONNX Runtime (quantization, graph optimization)
- OpenVINO (optimization for Intel hardware)
- Apache TVM (compilation and optimization)
- Hugging Face Optimum (hardware-specific optimization)
Architecture
┌─────────────────────────────────────────────────────┐
│ Public API Layer │
│ (Optimizer, Constraints, Goals) │
└────────────────────┬────────────────────────────────┘
│
┌────────────────────▼────────────────────────────────┐
│ Orchestration Layer │
│ (Strategy Selection, Pipeline Composition) │
└────────────────────┬────────────────────────────────┘
│
┌────────────────────▼────────────────────────────────┐
│ Backend Layer │
│ ┌──────────┬──────────┬──────────┬──────────┐ │
│ │ PyTorch │ ONNX │ OpenVINO │ TVM │ │
│ │ Backend │ Backend │ Backend │ Backend │ │
│ └──────────┴──────────┴──────────┴──────────┘ │
└─────────────────────────────────────────────────────┘
Advanced Usage
Custom Backend Selection
from hamerspace import Optimizer, Backend
optimizer = Optimizer.from_pytorch("model.pt")
result = optimizer.optimize(
goal=OptimizationGoal.QUANTIZE,
constraints=constraints,
preferred_backends=[Backend.ONNX, Backend.OPENVINO]
)
Benchmarking Only
# Benchmark without optimization
metrics = optimizer.benchmark(
hardware="cpu",
num_runs=100
)
print(f"Latency: {metrics.latency_ms}ms")
print(f"Size: {metrics.size_mb}MB")
Export Optimization Config
# Save configuration for reproducibility
result.save_config("optimization_config.json")
# Reproduce optimization
from hamerspace import Optimizer
optimizer = Optimizer.from_config("optimization_config.json")
result = optimizer.apply()
Non-Goals
❌ LLM optimization (use specialized tools like vLLM, TensorRT-LLM)
❌ Training models from scratch
❌ Research or SOTA benchmarking
❌ Custom kernel development
Requirements
- Python 3.8+
- One or more supported backends installed
Contributing
Contributions welcome! Please see CONTRIBUTING.md for guidelines.
License
Apache License 2.0
Citation
@software{hamerspace2025,
title={Hamerspace: Model Compression and Optimization Engine},
author={Hamerspace Contributors},
year={2025},
url={https://github.com/yourusername/hamerspace}
}
Metadata
Release files for hamerspace 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hamerspace-0.1.0.tar.gz | 28.5 kB | Without provenance | Details for hamerspace-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hamerspace-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for hamerspace-0.1.0-py3-none-any.whl |
Total release size: 59.0 kB
Release files / hamerspace-0.1.0.tar.gz
| Download URL | hamerspace-0.1.0.tar.gz |
|---|---|
| Size | 28.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eebe68cf2b7ce7824c33860801f79c33666090398a55439cea47c548981b50bb
|
|
BLAKE2b-256 checksum How to use checksums |
1cc08d6a1f9f7bb2da7a4917e15543c4b688415968c15dbe6a8dc41208d81c6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.7
|
Release files / hamerspace-0.1.0-py3-none-any.whl
| Download URL | hamerspace-0.1.0-py3-none-any.whl |
|---|---|
| Size | 30.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d812926c12408aec5204c5ceb3575ed5bf4af83e4fa85edca831b16e90e06ef7
|
|
BLAKE2b-256 checksum How to use checksums |
c21ecc4aa096432bcf4546af47f6bffe3ad433a9214355d8a4be1a687073e0ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.7
|
Security for hamerspace 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.