aitune.torch.backend.torchao_backend
aitune.torch.backend.torchao_backend
Torchao backend.
Module Contents
Classes
Data
MXFP8DQ_BLOCK_SIZE_DIVISIBILITY
NVFP4DQ_BLOCK_SIZE_DIVISIBILITY
API
Bases: Backend
Backend that does torch quantization.
If you would like to use customize quantization, you can pass in a quantization config.
Activates backend.
Builds the model with torchao quantization and torch.compile.
Check hardware and model constraints for the selected quantization format.
Parameters:
The PyTorch module to validate.
Raises:
RuntimeError: If hardware or model constraints are not met.
Validate sm100+ GPU, bfloat16 dtype, and block-size alignment for mxfp8dq.
Pre-flight mirror of the bfloat16 assertion in
torchao.prototype.mx_formats.inference_workflow._mx_inference_linear_transform
and the block_size=32 field of MXDynamicActivationMXWeightConfig.
The sm100+ and library requirement is captured by the module-level MX_FORMATS_AVAILABLE
flag (evaluated at import time). Dtype is bfloat16-only —
torchao asserts this explicitly; float32 is not accepted despite what older comments suggested.
Parameters:
The PyTorch module to validate.
Raises:
RuntimeError: If sm100+ GPU is unavailable, any parameter is not bfloat16, or a weight’s last dimension is not divisible by MXFP8DQ_BLOCK_SIZE_DIVISIBILITY.
Validate sm100+ GPU, bfloat16 dtype, and weight shape alignment for nvfp4dq.
Pre-flight mirror of the assertions in
torchao.prototype.mx_formats.inference_workflow._nvfp4_inference_linear_transform
(is_sm_at_least_100() assert, bfloat16 assert, and weight.shape[-2] % 16 check).
The sm100+ and library requirement is captured by the module-level MX_FORMATS_AVAILABLE
flag (evaluated at import time).
Parameters:
The PyTorch module to validate.
Raises:
RuntimeError: If sm100+ GPU is unavailable, the model dtype is unsupported, or any weight’s last two dimensions are not divisible by the block size.
Deactivates backend.
Deploys the backend.
Apply TorchAO quantization and warm up the compiled model.
Runs inference with the given arguments.
Parameters:
inference arguments
inference keyword arguments
Returns: Any
The result of the inference.
Iterate parameters from modules selected by the TorchAO filter function.
TorchAO applies filter_fn at the module level and skips modules where it returns False. The
compatibility preflight must mirror that behavior, otherwise it can reject parameters in layers that TorchAO
would not quantize anyway, such as embeddings, output projections, or small Linear layers excluded by a
model-specific predicate.
Store the backend configuration to a file.
Returns the description of the backend.
Creates a backend from a state_dict.
Returns the key of the backend.
Returns the state_dict of the backend.
Bases: BackendConfig
Configuration for TorchAOBackend.
Parameters:
Passed to torch.compile to require a single graph.
Passed to torch.compile. When None, TorchAOBackend enables dynamic compilation only for
graph specs with detected dynamic axes, without mutating this config.
Passed through to torch.compile(mode=...). Valid presets are "default",
"reduce-overhead", "max-autotune", and "max-autotune-no-cudagraphs".
Name of a built-in TorchAO quantization preset.
Custom TorchAO quantization config. Use this instead of quantization for advanced
TorchAO options.
Optional TorchAO quantization predicate. It receives (module, fqn) and should return True
for modules that should be quantized. Compatibility preflight checks use the same predicate.
Post init for TorchAOBackendConfig.
Returns the description of the backend.
Initialise config from a plain dict (e.g. parsed from YAML).
Supports two forms:
{"quantization": "int8wo"}— user-facing YAML form;quantizationmust be one of the supportedQuantizationTypeliterals.{"quantization_config": <bytes>}— internal checkpoint form produced byto_dict(), wherequantization_configis pickle-serialised.
Returns the key of the backend configuration.
Convert TorchAOBackendConfig to dict.