Repository navigation
refactor(quantization): centralize lifecycle contracts - #3796
Conversation
|
Pushed Fixed an EoRA multi-GPU finalize deadlock caused by reversed processor/module lock order. Also updated the checkpoint tests to use all four visible 4090s and keep EoRA on two GPUs. Validated:
|
|
Pushed CI found an AWQ dynamic-config bug ( Validated:
|
|
Pushed Single-GPU checkpoint cases now pin one visible GPU instead of inheriting all four. Specialized QQQ/Paro EoRA recovery passes. Validated:
|
|
Pushed Forward controls now use Validated:
|
|
Pushed Moved all forward behavior into ForwardConfig(
required=...,
replay_after_process=...,
all_modules_in_single_pass=...,
subset_early_stop=...,
activation_capture=...,
capture_layer_context=...,
)Validated:
|
|
Pushed Removed redundant lifecycle=self.lifecycle.use(ForwardConfig(...))
forward_config=ForwardConfig(...)Validated:
|
|
Pushed Simplified the names: forward=ForwardConfig(...)
processor.forwardNo Validated:
|
|
Pushed Processor constructors now accept one complete config: GPTQProcessor(..., forward=ForwardConfig(required=False, ...))Removed Validated:
|
|
Fixed the FP8 oracle in Validation: 58 passed, 1 skipped; Ruff, compileall, and diff checks passed. |
|
Added Validation: 250 processor tests, 98 lifecycle/stage tests, and 37 checkpoint tests passed. Ruff, compileall, and diff checks passed. |
|
Pushed Review fixes:
Validation:
|
Qubitium
left a comment
There was a problem hiding this comment.
I reviewed the lifecycle refactor at e584e93c4 and reproduced two checkpoint regressions. I also found one avoidable calibration preparation cost in the new processor factory. Details are attached to the changed lines below.
Persist runtime calibration exclusions across continuation and record each AWQ module's effective format. Pass an empty calibration config to planning-only preprocessors.
Qubitium
left a comment
There was a problem hiding this comment.
Re-reviewed at b06782733. The three issues I reported on e584e93c4 are addressed and their focused regressions pass. I found one remaining checkpoint resume failure for dynamic weight-only settings, detailed below.
Record effective FP8 scale/format settings and BitsAndBytes block/compression settings in packed module specs. Restore them over global method defaults and cover dynamic FP8 stop/resume.
Rename EffectiveModuleConfig to ResolvedModuleConfig, effective variables to resolved_cfg, and the bind/get helpers to resolved-module-config names. Update docs and tests.
Qubitium
left a comment
There was a problem hiding this comment.
Fresh subagent correctness review at 25d44e724, with local verification of both findings. The earlier dynamic weight-only checkpoint failure is fixed: its FP8 stop/resume reproduction and the new FP8/BNB tests pass.
[P3] scripts/repro_issue_2326.py still imports and constructs ExecutionConfig (lines 29 and 258), which this PR removes from loop_processor.py. Running python scripts/repro_issue_2326.py --help now exits immediately with ImportError: cannot import name 'ExecutionConfig'. Please migrate the diagnostic to ForwardConfig and processor.forward so it remains usable for the multi-GPU regression it documents.
run_layer_stage() replays and publishes every trailing decoder layer when an embedding endpoint is requantized, so the execution plan must cover them instead of truncating at the last quantized layer. Extract plan_layer_count() and share it with the weight-only looper.
|
Fresh correctness and design review at New correctness finding — [P3] run-plan diagnostics crash for accepted string backends. A real CPU RTN run with Design assessment: the grouped configs are useful, but several decisions still have multiple owners. I would keep this approach and tighten ownership in these concrete ways:
Prepared calibration ownership is another possible follow-up: consumers sharing the same dataset/preparation policy can share read-only prepared batches while retaining separate activation caches. Repeated preparation predates this PR, so this is an optimization opportunity rather than a new regression. Validation: local scheduling/lifecycle selection 80 passed; independent agent lifecycle/checkpoint-schema selection 74 passed (overlapping suites, not additive). Locally reproduced the string-backend crash and forward-policy mismatch. No new confirmed quantization/checkpoint numerical failure emerged from this pass; no new free-threaded multi-GPU qualification was performed. The previously reported stale |
- Normalize the recorded loop backend with method-aware normalization so run-plan diagnostics accept string backends; AUTO stays AUTO. - Delegate LoopProcessor.forward to the mutable lifecycle instead of a stale copy. - Share one checkpoint-chain admission predicate between the run plan and the checkpoint adapter, with a drift test against processor lifecycles. - Let run_layer_stage consume the planner-resolved layer extent instead of recomputing it. - Migrate scripts/repro_issue_2326.py to ForwardConfig and cover it with a regression test.
|
Pushed Fixes for this review:
Design items 2 (one normalized constructor spec for packing/checkpoint) and 3 (execute the LoopPlan as step authority) remain follow-ups. Item 3's smaller intermediate change is done; item 2 would be a larger schema refactor and I did not silently expand this PR into it. Validation: lifecycle contracts 15 passed; checkpoint/loop-extension/method compatibility 26 passed; stage and weight-only focused tests passed; broader AWQ/prepare-dataset/checkpoint/stage suite 227 passed, 32 skipped. The one QQQ failure in that run was caused by forcing |
|
Re-reviewed head One actionable finding — [P2] migrate the checkpoint adapter fixture so its existing assertions still run. The new capture call unconditionally reads the quantization config through Reproduction: Latest fixes verified: string backend quantization and plan diagnostics pass through the public API; Design: the smaller extent-passing change is sufficient for the observed planner/executor mismatch. The step-to-checkpoint-role table still duplicates processor declarations, but its drift test is a reasonable guard. A normalized per-module constructor specification shared by packing and restoration remains a useful follow-up; I would keep that separate from fixing the failing tests. Validation: lifecycle/helpers/stage/subset/weight-only suites: 157 passed, 9 skipped. Checkpoint adapter/method/modules/extension and loop-extension checks, with recovery cases deselected: 94 passed, 8 failed (the fixture issue above), 95 deselected. Full subprocess recovery coverage was not completed in this pass. No repository files changed. |
- Add ModuleConstructorSpec as the single normalized constructor contract. create_quant_module resolves dynamic overrides into it, checkpoint capture derives it from the packed module, and restore consumes it. This removes the duplicated field inventory and override interpretation. - Make the LoopPlan the execution authority in run_layer_stage: iterate the planned steps from the extension cursor and publish those exact step objects instead of recomputing the stop condition. - Fix checkpoint capture for models without a quantization config. - Cover plan/observer agreement for normal, excluded-tail, embedding, and resumed runs, plus packing/checkpoint spec agreement.
|
Pushed 2. One normalized constructor spec.
3. LoopPlan is the step authority.
Also fixed: checkpoint capture crashed for models with no quantization config ( Validation: 138 passed (lifecycle, checkpoint modules, stage, checkpoint adapter); checkpoint quantization/extension 34 passed; weight-only/AWQ/prepare-dataset 142 passed, 75 skipped; QQQ GPU-only schema test passes with a GPU visible. Ruff, compileall, and diff checks pass. |
Drop the remaining spec naming from the lifecycle surface: - module_spec -> module_config - ModuleConstructorSpec -> ModuleConstructorConfig - resolve/module_constructor_spec -> resolve/module_constructor_config - packed_module_spec -> packed_module_config - checkpoint state key specs -> modules (adapter schema v6)
|
Re-reviewed head No new actionable correctness findings in this delta.
Design assessment: these changes address the two main structural concerns from the earlier review. Executing the plan directly removes the competing traversal decision, and the shared constructor config centralizes common constructor fields without requiring a generic quantization algorithm. Keeping kernel resolution and tensor-schema validation explicit is appropriate. I do not see a correctness-driven reason for another broad redesign in this pass. Validation on this head:
Total: 305 passed, 9 skipped. The subagent additionally checked traversal combinations with mocked subset/replay work; those are not counted above. This was not the full method/device/recovery matrix or a GIL=0 qualification. No repository files changed. |
Summary
ProcessorLifecycleConfigfor forward, calibration, and checkpointing behavior.ForwardConfig; all dataset behavior in immutableCalibrationConfig.CalibrationConfigand one optionalForwardConfig; individual calibration/forward arguments are removed.QuantizationRunPlanas the single processor-chain contract and one shared checkpoint admission predicate.ResolvedModuleConfigsnapshots so one dynamic-rule result drives quantization and packing.ModuleConstructorConfigas the single normalized constructor contract shared by packing, checkpoint capture, and checkpoint restore.LoopPlanthe execution authority:run_layer_stage()iterates planned steps from the extension cursor and publishes those exact step objects.Contracts
QuantizationRunPlangptqmodel/models/quantization_run_plan.pyBaseQModel, checkpoint admission, diagnosticsProcessorLifecycleConfiggptqmodel/looper/loop_processor.pyResolvedModuleConfiggptqmodel/quantization/config.pyModuleConstructorConfiggptqmodel/quantization/module_config.pycreate_quant_module, checkpoint capture/restoreLoopPlan/LoopStepgptqmodel/looper/extension.pyModuleLooper,run_layer_stage, extensionsA lifecycle property is shared only when at least two processors or stages consume it. Method math, kernels, capture storage, and method-specific failure rules stay local to the owning processor.
Design flow
flowchart TD A["model.quantize(...)"] --> B["QuantizationRunPlan.build"] B --> C{"checkpoint requested?"} C -- yes --> D{"run_plan.checkpoint_supported"} D -- no --> X1["NotImplementedError<br/>unsupported processor chain"] D -- yes --> E["processor_class(step)"] C -- no --> E E --> F["ModuleLooper<br/>build LoopPlan"] F --> G["extensions.start(LoopContext(plan))<br/>returns resume cursor"] G --> H["run_layer_stage(plan, cursor)"] H --> I["iterate plan.steps[cursor:]<br/>plan is the step authority"] I --> J["ProcessorLifecycleConfig<br/>forward + calibration"] J --> K["QuantizeConfig.resolve_module_config"] K --> L{"first dynamic rule excluded?"} L -- yes --> X2["skip module<br/>record runtime exclusion"] L -- no --> M["ResolvedModuleConfig"] M --> N["resolve_module_constructor_config"] N --> O["ModuleConstructorConfig<br/>bits / group / sym / pack_dtype / format / options"] O --> P["create_quant_module<br/>pack once"] P --> Q["packed_module_config<br/>derive the same config"] Q --> R["checkpoint capture<br/>schema v6"] R --> S["restore_packed_module<br/>consume the same config"] I --> T["extensions.publish(planned step)"] T --> U["LoopExtension observers<br/>boundary equals plan"] classDef failure fill:#ffd6d6,stroke:#b42318,color:#7a271a; classDef contract fill:#dbeafe,stroke:#2563eb,color:#1e3a8a; class X1,X2 failure; class B,F,M,N,O contract;The run plan is immutable after preflight.
BaseQModel.quantization_run_planexposes it for diagnostics. The resume cursor is a position in the plan, distinct from the model-layer index used by layer-boundary recovery.Example
Validation
compileall, andgit diff --check: pass.Known environment limits
tests/test_dynamic.pyneeds a real model; the available GPUs mix compute capabilities, so only its unit-level override test runs here.test_gguf_forward_requests_dequantized_weight_in_input_dtypefails identically on the base revision in this environment (CPU/CUDA dtype mismatch) and is unrelated to this PR.