Repository navigation
fix(exl3): refresh deferred runtime weights per layer forward and align generic geometry (#4006) - #4026
Merged
Conversation
…gn generic geometry (#4006)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4006
TL;DR
EXL3 now refreshes deferred dense replay weights for the whole layer before every subset capture forward and before
_replay_layer_outputs, instead of only for the current subset. The generic path also zero-pads output columns to a 128 multiple and rejects non-128-aligned input features inpreprocess, before calibration, with a namedValueError. The two repo recovery tests that fail onmainnow pass on CUDA.1. The problem
EXL3Processor._stage_runtime_weight(gptqmodel/looper/exllamav3_processor.py:2388) replaces a packed projection's dense weight with a META placeholder. The layer forward still executes every module, but only the current subset was prepared, so a projection packed by an earlier subset reached the next capture forward (and the post-process replay) as META.flowchart TD A["subset 0 capture forward"] --> B["subset 0 process: stage META weight"] B --> C["subset 1 capture forward"] C --> D["_prepare_named_module_for_forward for subset 1 only"] D --> E["layer forward executes subset 0 projections"] E --> F["META weight reaches HookedLinear.forward"] F --> G["NotImplementedError: Cannot copy out of meta tensor; no data"] style G fill:#ffd6d6,stroke:#b00020,stroke-width:2pxBefore/after repro on the issue's command (RTX 4090, CUDA):
test_moe_method_checkpoint_recovery[term-exl3]failed the same way.2. The new flow
prepare_layer_runtime_weights_for_forward(gptqmodel/looper/loop_processor.py:87) walks the complete layer inventory and offers everyNamedModuleto each processor'sprepare_runtime_weight_for_forwardhook. The hook materializes the deferred weight on the forward device and clears its marker, so a repeat call is a no-op.flowchart TD A["run_subset_stage: subset n of N"] --> B["_run_single_subset_pass"] B --> C["_prepare_layer_direct_state_for_forward"] C --> D["prepare_layer_runtime_weights_for_forward"] D --> E["prepare_runtime_weight_for_forward for every NamedModule in full"] E --> F{"deferred marker present?"} F -- "yes" --> G["reconstruct_exl3_tensors on forward device"] G --> H["_restore_module_weight crops padded output columns"] H --> I["clear exl3_deferred_runtime_weight marker"] F -- "no" --> J["return None, leave module unchanged"] I --> K["_run_forward_batches for the whole layer"] J --> K K --> L["process subset n and stage its META placeholder"] L --> M["_replay_layer_outputs"] M --> D M --> N["prepare_layer_post_quantize: terminal layer retires META to sentinel"] N --> O["submodule_finalize installs ExllamaV3Linear"]Call sites:
gptqmodel/looper/stage_subset.py:946gptqmodel/looper/stage_layer.py:3213. Geometry contract
EXL3 applies a 128-wide signed Hadamard transform to the weight and the captured Hessian, and the runtime reconstructs in 128-wide output blocks.
in_featurespreprocessandquantize_exl3before captureout_featuresceil(out/128)*128;ExllamaV3Linear.forwardcrops(in_features, stored_out_features)_quant_input_weightInput channels are not padded:
ExllamaV3Linear._stored_featuresrequirestrellis.shape[0] * 16 == in_featuresand there is no activation-padding boundary. This is why the generic path fails closed for unaligned input widths instead of pretending to support them. Output padding is fully supported because the runtime already crops padded stored features (tests/test_kimi_k3_core_format.py).flowchart TD A["EXL3Processor.preprocess"] --> B["validate_exl3_quantization_geometry"] B --> C{"in_features % 128 == 0?"} C -- "no" --> D["ValueError with module name and in_features"] style D fill:#ffd6d6,stroke:#b00020,stroke-width:2px C -- "yes" --> E["build capture task"] E --> F["_quant_input_weight pads output columns"] F --> G["quantize_exl3 validates the same geometry again"] G --> H["packed trellis stores padded outputs"]hidden=192, intermediate=320now fails before calibration:Direct
quantize_exl3on(144,208),(48,32),(16,16)now raises the same clearValueErrorinstead of a bareAssertionError.4. Failure and ambiguity contract
_run_forward_batchesin_featuresnot 128-alignedAssertionErrorafter calibrationValueErrorfrompreprocessout_featuresnot 128-alignedAssertionErrorin the quantizerNone5. Change inventory
gptqmodel/exllamav3/modules/quant/exl3_lib/quantize.pyquantize_exl3validationgptqmodel/looper/exllamav3_processor.pygptqmodel/looper/loop_processor.pyprepare_layer_runtime_weights_for_forwardgptqmodel/looper/stage_subset.pygptqmodel/looper/stage_layer.pytests/test_exl3_generic_geometry.pydocs/exl3-runtime-weights.md,README.md6. Tests / guarantees
test_quant_input_weight_pads_output_columns_to_128(320,128)weight exports as(128,384)with a zero tailtest_restore_module_weight_crops_padded_output_columns(320,128)test_preprocess_rejects_unaligned_input_features_before_capturein_features=192raises before any task existstest_direct_quantize_exl3_rejects_unaligned_geometry(144,208),(48,32),(16,16)raiseValueErrortest_layer_runtime_weight_preparation_covers_every_named_moduleNamedModuleis offered to the hooktest_replay_prepares_deferred_weights_for_modules_outside_last_subsettest_specialized_checkpoint_recovery[term-exl3]test_moe_method_checkpoint_recovery[term-exl3]Fail-before evidence (stashed fix, same commands): all 8 new tests failed and both repo tests failed with
Cannot copy out of meta tensor. After the fix:10 passedon CUDA.7. Validation
Hardware: RTX 4090 (Ada,
GPU-d458708b-c760-bbf1-08fb-8b8803a2157d,nvidia-smiindex 3) and AMD R9700 (HIP_VISIBLE_DEVICES=2). The RTX 5090 was never used.CUDA (
/opt/venvs/cu130t):ruff check gptqmodel docs/eora tests setup.py->All checks passed!Reload identity on the 2-layer Llama fixture: 14
ExllamaV3Linearmodules, 0 bitwise mismatches, logits bitwise equal between the in-memory and reloaded model. Logits vs the FP16 native model on this random fixture: relative Frobenius error0.222, top-1 agreement0.719atbits=3(0.113/0.844atbits=4). The issue's~0.048/~95%figures are checkpoint-specific and were not reproduced with the repo's randomly initialized fixture; the structural bitwise claim is reproduced exactly.ROCm (
/opt/venvs/rocm101t,HIP_VISIBLE_DEVICES=2): the 8 new tests pass. The two repo recovery tests remain blocked by pre-existing ROCm issues, not by this change:test_moe_method_checkpoint_recovery[term-exl3]hitstorch.device("rocm")in the routed-expert Hessian-owner branch (exllamav3_processor.py:2188). The same failure occurs on unmodifiedorigin/main(b12cf3f).test_specialized_checkpoint_recovery[term-exl3]now gets past the META crash but failsassert_identical_tensorson a*.trelliskey. Two independent baseline quantizations of the same native model on ROCm already produce 11 differing trellis keys, so the bitwise resume assertion is blocked by pre-existing ROCm pipeline nondeterminism; onmainthe test crashes before this is observable.8. Reviewer notes
submodule_finalizeinstalls the packed module. That is the existing lifecycle for the post-process replay; the change only makes earlier subsets follow it too.ExllamaV3Linear, which this fix intentionally does not add.