Registry / ai-ml / torchao

torchao

JSON →
library0.18.0pypypi✓ verified 25d ago

TorchAO is a PyTorch library for applying advanced optimization (AO) techniques, primarily quantization and sparsity, to deep learning models running on GPUs. It focuses on performance acceleration through low-precision kernels, mixture-of-experts (MoE) optimizations, and quantization-aware training (QAT). The current version is 0.17.0, with new versions and significant features released frequently, often monthly.

pip install torchao
INSTALL
IMPORT
SIG · TORCHAO
T
torchao
ai-mlpythonv0.18.0
Install
2.4s avg
Import
Disk
34MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.18.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 29.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.000s · 43MB
34MB installed
● package 34MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

quantize_
from torchao.quantization import quantize_
from torchao.quantization import quantize_

This quickstart demonstrates how to define a simple PyTorch model and apply a predefined post-training quantization recipe using `torchao.quantization.quantize_`.

import torch import torch.nn as nn from torchao.quantization import quantize_, int8_dynamic_activation_int4_weight # 1. Define a simple model class MyModel(nn.Module): def __init__(self): super().__init__() self.linear1 = nn.Linear(10, 20) self.relu = nn.ReLU() self.linear2 = nn.Linear(20, 5) def forward(self, x): return self.linear2(self.relu(self.linear1(x))) model = MyModel() print(f"Original model: {model}") # 2. Define a quantization recipe # This uses a predefined post-training quantization recipe quantizer = int8_dynamic_activation_int4_weight() # 3. Apply quantization to the model # quantize_ modifies the model in-place (or returns a modified copy) quantized_model = quantize_(model, quantizer) print(f"\nQuantized model: {quantized_model}") # Test with some dummy input dummy_input = torch.randn(1, 10) output = quantized_model(dummy_input) print(f"\nOutput shape: {output.shape}") assert isinstance(quantized_model.linear1, torch.nn.Module) # Verify structure
Debug
Known issues
breakingThe `quantize_` API underwent a significant overhaul in version 0.9.0, changing how quantization recipes are applied to models. Direct calls to `quantize_` with previous argument patterns will fail.
fix
Consult the `torchao` documentation for versions 0.9.0+ for the new `quantize_` API, which now typically requires a `Quantizer` object (e.g., from a predefined recipe or a custom `QuantConfig`).
affects: <0.9.0
deprecatedOlder configurations and less-used quantization options have been deprecated to streamline the library. Using these deprecated features may lead to warnings or errors in future releases.
fix
Refer to the latest `torchao` documentation (v0.16.0+) for current recommended configurations and quantization options. Update your code to use the officially supported APIs.
affects: <0.16.0
gotchaFeatures located in `torchao.prototype` modules are experimental and subject to frequent, unannounced API changes, or may be removed entirely without prior deprecation. They are not considered stable.
fix
Avoid using `torchao.prototype` modules in production-critical code. If used, be prepared for frequent updates and potential breaking changes with new `torchao` releases.
affects: All versions
gotchaOptimal performance for `torchao`'s advanced kernels (e.g., MXFP8 MoE, W4A8) often requires specific CUDA versions (e.g., CUDA 12.8+) or particular GPU architectures (e.g., Blackwell, GB200). Using non-supported environments may result in reduced performance, errors, or inability to leverage certain features.
fix
Before deployment, verify your CUDA version and GPU architecture against `torchao`'s requirements for the specific features you intend to use. Ensure your environment matches the recommendations for optimal results.
affects: All versions
Upgrade
Version history
0.18.0latest on PyPI · released Aug 3, 2026
Audit
Dependencies
torchrequiredCore PyTorch dependency for model definition and operations.
Agent activity
51 hits · last 30 days
node
44
OpenAI (training)
1
Resources
torchao — pip install torchao · libregistry