algo_cfg#
Compile a quantize config into an ordered list of scoped calibration stages.
Classes
What one calibration algorithm reads, writes and assumes. |
|
One algorithm applied to one scope — the unit of work in a calibration plan. |
Functions
Capabilities of |
|
Lower a quantize config into an ordered, validated list of scoped stages. |
|
Build the |
- class AlgoCapabilities#
Bases:
objectWhat 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_litefolds a scale into the weight assuming an unsmoothed start, so it conflicts withpre_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.
weightandactsare ambient, so never counted. Not a precondition: every algorithm listingweight_amaxalso seeds its own via an internalmax_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_processwrite-mask through everything it writes.Falseforces 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:
ValueErrorRaised when an
algo_cfgcannot be lowered into a valid plan.
- class AlgoStage#
Bases:
objectOne 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
Noneif 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:
config (QuantizeConfig | dict)
model (Module | None)
strict (bool)
- Return type:
list[AlgoStage]