Skip to main content

Runtime compression tuning utilities for PyTorch

Project description

rasnatune

rasnatune is a lightweight PyTorch compression helper based on forward hooks.

Installation

pip install rasnatune

What It Does

  • Applies compression at runtime using hooks (no permanent weight rewrite).
  • Supports quantization and unstructured sparsification.
  • Targets torch.nn.Conv2d and torch.nn.Linear.

Quick Start

import torch
from rasnatune import Compression, SparseWeightUnstructured

model = torch.nn.Sequential(
    torch.nn.Linear(128, 64),
    torch.nn.ReLU(),
    torch.nn.Linear(64, 10),
)

wrapped = Compression(model)
wrapped.attach(
    SparseWeightUnstructured,
    filter=lambda m: isinstance(m, torch.nn.Linear),
    sparsity=0.5,
)

x = torch.randn(128)
y = wrapped(x)

Public API

Top-level exports:

  • rasnatune.Compression
  • rasnatune.Compressor
  • rasnatune.QuantizeWeight
  • rasnatune.QuantizeActivation
  • rasnatune.SparseWeightUnstructured
  • rasnatune.SparseActivationUnstructured

Compression Classes

  • QuantizeWeight(min=-128, max=127): Quantizes layer weights only during forward, then restores original weights.
  • QuantizeActivation(min=-128, max=127): Quantizes the first input activation of the layer before forward.
  • SparseWeightUnstructured(sparsity=0.5): Applies unstructured sparsity to layer weights only during forward, then restores.
  • SparseActivationUnstructured(sparsity=0.5): Applies unstructured sparsity to the first input activation before forward.

Notes

  • Compression.attach uses filter= to choose target modules.
  • If filter is omitted, it will try all submodules, and unsupported modules will raise an assertion.
  • Supported module types for built-in compressors are torch.nn.Conv2d and torch.nn.Linear.

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

rasnatune-0.0.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

rasnatune-0.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file rasnatune-0.0.1.tar.gz.

File metadata

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

File hashes

Hashes for rasnatune-0.0.1.tar.gz
Algorithm Hash digest
SHA256 98fd9d69080d720b5e7d350f46fb4c81ff7ac2dfbdd0b3996bf4873a7257d291
MD5 90ff13f45dee6db59f06f11e1a52c57e
BLAKE2b-256 9b6831356fb8a07d83095aed9aa4dac55114e7666e69b4c4fcf9dd9a7566f1d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for rasnatune-0.0.1.tar.gz:

Publisher: rasnatune-pypi-publish.yml on spiceengine/rasnatune

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

File details

Details for the file rasnatune-0.0.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for rasnatune-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 80fcedef8fa4c929b2fa8bcccb00b282eae6f945882afe061e83b3391fb01718
MD5 1afea827c8bed943478c65a0ff058439
BLAKE2b-256 e44b43ca885400d0acf6af8bc10d5281ad569f5a5c9bb452397a7491465a989c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rasnatune-0.0.1-py3-none-any.whl:

Publisher: rasnatune-pypi-publish.yml on spiceengine/rasnatune

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