algo_cfg#

Compile a quantize config into an ordered list of scoped calibration stages.

Classes

AlgoCapabilities

What one calibration algorithm reads, writes and assumes.

AlgoStage

One algorithm applied to one scope — the unit of work in a calibration plan.

Functions

capabilities_for

Capabilities of algo, read off its calibrate-mode descriptor.

compile_algo_cfg

Lower a quantize config into an ordered, validated list of scoped stages.

stage_predicate

Build the should_process write-mask for a stage.

class AlgoCapabilities#

Bases: object

What one calibration algorithm reads, writes and assumes.

__init__(writes_whole_module, refines, requires=frozenset({}), may_write=frozenset({}), invalid_if_present=frozenset({}), scopable=True, requires_weight_scales=None)#
Parameters:
  • writes_whole_module (bool)

  • refines (Literal['weight', 'input', 'both'])

  • requires (frozenset[str])

  • may_write (frozenset[str])

  • invalid_if_present (frozenset[str])

  • scopable (bool)

  • requires_weight_scales (Literal['static', 'dynamic'] | None)

Return type:

None

invalid_if_present: frozenset[str] = frozenset({})#

awq_lite folds a scale into the weight assuming an unsmoothed start, so it conflicts with pre_quant_scale.

Type:

Tokens whose presence makes this algorithm incorrect

may_write: frozenset[str] = frozenset({})#

it may write fewer on a given model (smoothquant only touches INT8 layers), never more. Over-declaring is safe for conflict detection and unsafe for the hand-off, which is why the hand-off also checks coverage.

Type:

Tokens this may write. An upper bound

refines: Literal['weight', 'input', 'both']#

weight-side algorithms also seed input amax via an internal max_calibrate, which may_write records.

Type:

Role this algorithm improves. Narrower than what it writes

requires: frozenset[str] = frozenset({})#

Tokens this algorithm reads. weight and acts are ambient, so never counted. Not a precondition: every algorithm listing weight_amax also seeds its own via an internal max_calibrate, so a plan starting with one compiles. Declaring a token means two things – an earlier stage producing it on every target lets this one skip that init (derive_handoff), and it keeps that earlier write from counting as dead.

requires_weight_scales: Literal['static', 'dynamic'] | None = None#

"static" (stored per-block amax it can search) or "dynamic" (derived in-kernel). None = works on either. Dynamic upgrades to static as a prep step; static never downgrades, since that discards a search.

Type:

NVFP4 weight block scales this algorithm needs

scopable: bool = True#

Can be restricted to a scope, i.e. threads the should_process write-mask through everything it writes. False forces whole-model scope; the compiler rejects the rest.

writes_whole_module: bool#

Writes every quantizer of each linear it touches, not one quantizer at a time.

exception AlgoCfgValidationError#

Bases: ValueError

Raised when an algo_cfg cannot be lowered into a valid plan.

class AlgoStage#

Bases: object

One algorithm applied to one scope — the unit of work in a calibration plan.

__init__(algo, cfg, scope, selector, order, exclude=())#
Parameters:
  • algo (str | None)

  • cfg (dict)

  • scope (str)

  • selector (str)

  • order (int)

  • exclude (tuple[tuple[str, str], ...])

Return type:

None

algo: str | None#
property capabilities: AlgoCapabilities | None#

Declared capabilities of this stage’s algorithm, or None if undeclared.

cfg: dict#
exclude: tuple[tuple[str, str], ...] = ()#
order: int#
scope: str#
selector: str#
WRITABLE_TOKENS = frozenset({'input_amax', 'pre_quant_scale', 'weight', 'weight_amax'})#

over-reporting conflicts is the safe direction.

Type:

Conservative default for an algorithm that declares nothing

capabilities_for(algo, cfg=None)#

Capabilities of algo, read off its calibrate-mode descriptor.

Parameters:
  • algo (str | None)

  • cfg (dict | None)

Return type:

AlgoCapabilities | None

compile_algo_cfg(config, model=None, strict=True)#

Lower a quantize config into an ordered, validated list of scoped stages.

Parameters:
Return type:

list[AlgoStage]

stage_predicate(model, stage)#

Build the should_process write-mask for a stage.

Parameters:
Return type:

Callable[[Module], bool]