Skip to main content

Zero-config CPU optimization decorator for Deep Learning models.

Project description

Raafeli (CPU Turbo)

Zero-config Python decorator to speed up Deep Learning models on CPU by up to 300%.

Python License


⚡ The Problem: GPU-less Deployments

Deploying large AI models or running them on local machines without a dedicated GPU is painfully slow. Matrix multiplications inside torch.nn.Linear layers bottleneck heavily on CPU architectures because they process 32-bit floats natively.

🚀 The Solution: Raafeli

Raafeli automatically transforms your heavy FP32 PyTorch models into highly optimized INT8 (Dynamic Quantized) representations under the hood. All it takes is a single decorator. You do not need to change your architecture, deployment pipeline, or weights.

Quick Start

import torch
import torch.nn as nn
from raafeli import optimize_cpu

# 1. Your heavy model
class HeavyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1 = nn.Linear(1024, 4096)
        self.fc2 = nn.Linear(4096, 1024)
        
    def forward(self, x):
        return self.fc2(torch.relu(self.fc1(x)))

model = HeavyModel()
input_data = torch.randn(1, 1024)

# 2. Decorate your prediction function
@optimize_cpu(model_arg="model", precision="int8")
def predict(model, data):
    return model(data)

# 3. Magic! First run takes a tiny fraction of a second to optimize,
#    all subsequent runs execute in INT8 natively on your CPU!
output = predict(model, input_data)

How It Works

When you call @optimize_cpu, Raafeli hooks into the execution stack. It intercepts the model object passed to your function, and aggressively applies torch.quantization.quantize_dynamic targeting performance-bound layers (like Linear and LSTM).

It caches the optimized model graph back into the object, ensuring the overhead is $0$ on every subsequent call. Your model footprint drops by ~75% and throughput spikes significantly.

Support This Project

Raafeli is an open-source project built out of passion. If it has saved you valuable GPU hours, deployment costs, or debugging time, consider supporting the creator by following on Instagram!

Follow on Instagram


Contributing & Testing

We welcome PRs! To run the test suite locally and verify your changes:

# Clone the repository
git clone https://github.com/ginganomercy/raafeli.git
cd raafeli

# Install with development dependencies
pip install -e .[dev]

# Run tests
pytest tests/

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

raafeli-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

raafeli-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: raafeli-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for raafeli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 efa68f349afeab2460136d7a979c745e467bd591017364d8bd4742283067e607
MD5 b0b8d5f50a52fd7eebfa0840c0800475
BLAKE2b-256 cba645d3537f062b359e07ba3d90ada453d1f53ea1e8b0a95c5d1c1bf74e31e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for raafeli-0.1.0.tar.gz:

Publisher: publish.yml on ginganomercy/raafeli

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

File details

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

File metadata

  • Download URL: raafeli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for raafeli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f175ef483ecd5aae91c214c1ad446f3853fca4ce06b0cfae6f6a6e9db18f2449
MD5 12b7556ed9cd0ee0ca05187726c827d1
BLAKE2b-256 6ee0df3faa4cba39e7f36e90ba419d4ca7bee06208e20c9931c12669a3655bb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for raafeli-0.1.0-py3-none-any.whl:

Publisher: publish.yml on ginganomercy/raafeli

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