Skip to content

base

base

Abstract base class for PT2E quantization backends.

BasePT2EBackend

Bases: ABC

Base class for PT2E quantization backends.

Each backend provides quantizer creation, environment setup, and operator lowering for a specific hardware target.

name abstractmethod property

name

Serialized PT2E backend name.

is_dynamic abstractmethod property

is_dynamic

Whether this backend uses dynamic activation quantization.

is_qat abstractmethod property

is_qat

Whether this backend is configured for PT2E QAT.

supported_device_types abstractmethod property

supported_device_types

Device types this backend supports (e.g., ('cpu',) for x86).

create_quantizer abstractmethod

create_quantizer(module_path)

Create a configured quantizer targeting a specific module.

Parameters:

Name Type Description Default
module_path str

Dotted path to the target submodule. Empty string means global (whole model).

required

Returns:

Type Description
Quantizer

A quantizer instance ready for ComposableQuantizer.

Source code in src/versatil/quantization/pt2e/backends/base.py
@abstractmethod
def create_quantizer(self, module_path: str) -> Quantizer:
    """Create a configured quantizer targeting a specific module.

    Args:
        module_path: Dotted path to the target submodule.
            Empty string means global (whole model).

    Returns:
        A quantizer instance ready for ComposableQuantizer.
    """

environment_context abstractmethod

environment_context()

Context manager that sets and restores backend-specific env vars.

Source code in src/versatil/quantization/pt2e/backends/base.py
@abstractmethod
@contextmanager
def environment_context(self) -> Generator[None]:
    """Context manager that sets and restores backend-specific env vars."""

activate_environment abstractmethod

activate_environment()

Set backend env vars permanently (no restore on exit).

Use this instead of environment_context when the env must persist beyond a single scope — e.g., for torch.compile where the actual compilation is deferred to the first forward pass.

Source code in src/versatil/quantization/pt2e/backends/base.py
@abstractmethod
def activate_environment(self) -> None:
    """Set backend env vars permanently (no restore on exit).

    Use this instead of environment_context when the env must
    persist beyond a single scope — e.g., for torch.compile
    where the actual compilation is deferred to the first
    forward pass.
    """