Skip to main content

Model compression and optimization engine for non-LLM machine learning models

Project description

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 weights
  • OptimizationGoal.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}
}

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

hamerspace-0.1.0.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

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

hamerspace-0.1.0-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

Details for the file hamerspace-0.1.0.tar.gz.

File metadata

  • Download URL: hamerspace-0.1.0.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.7

File hashes

Hashes for hamerspace-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eebe68cf2b7ce7824c33860801f79c33666090398a55439cea47c548981b50bb
MD5 9be4376ef13950af37b711bf31ce07e1
BLAKE2b-256 1cc08d6a1f9f7bb2da7a4917e15543c4b688415968c15dbe6a8dc41208d81c6a

See more details on using hashes here.

File details

Details for the file hamerspace-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hamerspace-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.7

File hashes

Hashes for hamerspace-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d812926c12408aec5204c5ceb3575ed5bf4af83e4fa85edca831b16e90e06ef7
MD5 8d4c466e93eb554e114ff45de790c56d
BLAKE2b-256 c21ecc4aa096432bcf4546af47f6bffe3ad433a9214355d8a4be1a687073e0ab

See more details on using hashes here.

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