Skip to main content

How a Linear picks its precision

Every Linear picks one physical spec at construction. The order is fixed in LinearBase.__init__ (phyai/src/phyai/layers/linear/layers.py): four options, highest priority first.
Most of the time you only meet option 3: the plan is built automatically when the checkpoint loads, and you pass nothing.

Automatic loading from a checkpoint

load_quant_plan(checkpoint_dir) (layers/quant/active.py) reads two places:
  • quantization_config in config.json, falling back to compression_config
  • a standalone hf_quant_config.json (used by ModelOpt)
If neither is present it returns None and the model stays bf16. If it finds one, it hands off to an importer to recognize the framework and build the plan. Three are recognized today:
quant_method is fp8 in config.json:
weight_block_size present means block granularity; absent means per-channel. Any activation_scheme other than "static" means dynamic activation quantization. Layers listed in ignored_layers (or modules_to_not_convert) are skipped and stay bf16.
The three importers are tried in a fixed order (fp8 → compressed-tensors → modelopt). On success it logs one line telling you which file the config came from.

Hand-writing a QuantPlan

When automatic loading is not enough, you can assemble the rule table yourself. A QuantPlan is an ordered sequence of Rules plus a fallback default. Each Rule pairs a Matcher with a QuantScheme; a scheme of None means skip (stay bf16).
Matcher supports four kinds of match: resolve walks top to bottom; the first matching Rule wins, and if none match it uses default.

Passing a scheme to a single Linear

To change one layer without building a whole table, pass scheme straight to that Linear. It skips the plan and goes directly to materialize:

How scales are loaded

The scale parameters a physical spec allocates (weight_scale, input_scale, weight_global_scale) get their hf_keys and loader attached by LinearBase._attach_optional_scales, marked optional. A pre-quantized checkpoint’s scales then load automatically, and a plain bf16 checkpoint that lacks them does not error on the missing keys.