Repository navigation
fix(module-tree): order consumers after producers and declare missing linears (#4041) - #4048
Merged
Merged
Conversation
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 #4041
TL;DR
Module-tree subset digits are a quantization order: the looper captures one subset block, then installs its quantized weights. Five definitions put a consumer in the same (or an earlier) subset as its producer, silently discarding sequential compensation. Two definitions left called
nn.Linearmodules undeclared. Six dense families gained verified:in=tags so Hessian dedup is active. Net: 16 files, two commits, no numeric code changes.1. The problem
BaseQModel._build_layer_modules_for_treegroups leaves by their subset digit. A subset is processed atomically, so a consumer that shares a subset with its producer is calibrated and quantized against the producer's unquantized output.flowchart LR subgraph bad["old: one subset"] P0["q_a_proj:0"] --> C0["q_b_proj:0"] end subgraph good["new: producer first"] P1["q_a_proj:0"] --> C1["q_b_proj:1"] end bad -. "consumer sees dense producer output" .-> X["lost compensation"]Audited declarations (all
file:linefrom the branch):gptqmodel/models/definitions/deepseek_v4.py:1447-1451q_b_proj:0,o_b_proj:1,kv_proj:2q_b_proj:1,o_b_proj:2,kv_proj:0gptqmodel/models/definitions/deepseek_v2.py:37:0:0, q_b/kv_b:1,o_proj:2gptqmodel/models/definitions/lfm2.py:27conv: (in_proj, out_proj)conv: (in_proj:0, out_proj:1)gptqmodel/models/definitions/falcon_mamba.py:23x_proj:0,out_proj:1x_proj:1,out_proj:2gptqmodel/models/definitions/minimax_m2.py:90-91out_proj:1,output_gate:1output_gate:1,out_proj:2gptqmodel/models/definitions/jamba.py:47mamba: (in_proj:0, out_proj:1)x_proj:1added;out_proj:2gptqmodel/models/definitions/axk2.py:53-60:!leaveslayer_modules_strict = False(Jamba, AXK2) makes an undeclared called linear silently stay in the source dtype. Jamba'smamba.x_projis now quantized like Falcon Mamba's; AXK2's gated-norm MLPs and indexer linears are intentionally excluded but declared, so the exclusion is reviewable.Before (origin/main @ e6b19c5)
After
2. The new flow
flowchart TD A["definition module_tree"] --> B["BaseQModel._build_layer_modules_for_tree"] B --> C["subset blocks in ascending digit order"] C --> D["BaseQModel.simple_layer_modules"] D --> E["ModuleLooper forward + Hessian capture"] E --> F["quantize and install block"] F --> G{"more blocks?"} G -- yes --> E G -- no --> H["packed checkpoint"] D --> I["BaseQModel.shared_input_plan"] I --> J["same-subset followers reuse leader Hessian"] J --> Eflowchart TD A["layer.named_modules yields nn.Linear"] --> B{"plan.find name"} B -- no --> C["undeclared: silent source dtype"] B -- yes --> D{"spec.quantize"} D -- yes --> E["must be in a subset block"] D -- no --> F{"flags include ! or ?"} F -- yes --> G["explicit exclusion"] F -- no --> H["contract test fails"]The committed reference page is docs/module-tree-ordering.md, linked from
README.mdnext to the model-tree resolution section. It carries the same diagrams, the before/after table, and the failure contract.3. Shared-input tags (item 3, additive only)
The issue listed siblings with bitwise-identical input and no
:in=tag, so Hessian dedup stayed off. This PR covers a verified subset:optin=xoptstarcoder2in=xstarcoder2gptjin=xgptjphiin=xphijambain=xjambalfm2in=xlfm2Safety argument, both halves tested:
build_layer_modulesemits byte-identical blocks with and without the tags (test_in_tags_do_not_change_quantization_blocks), so subset membership and order cannot change.probe_shared_inputsruns a real tiny forward and requires every group's inputs to be bitwise identical (test_plan_matches_real_forward_inputs).A skipped follower Hessian is therefore the leader's Hessian, and the packed tensors are unchanged.
Left out deliberately: families whose native layout needs remote code (
deepseek_v2,deepseek_v4,kimi_k25, ...) and parallel attention/MLP blocks whose leaves sit under different parents (falcon,gpt_neox, ...); tags are parent-scoped, so those need a different mechanism or their own real-forward case first.4. Change inventory
deepseek_v4.py,deepseek_v2.py,lfm2.py,falcon_mamba.py,minimax_m2.pyjamba.py,axk2.pyx_proj; explicit:!leavesopt.py,starcoder2.py,gptj.py,phi.py,jamba.py,lfm2.py:in=tagstest_definition_subset_ordering.py(new),test_shared_input_cpu_forward.pyregistered_module_plans.jsondocs/module-tree-ordering.md(new),README.md5. Validation
Hardware: CPU-only plan/forward tests. CUDA venv
cu130t(RTX 4090GPU-1ece7ec2-d88d-9284-93c8-d2578d90ad7e); ROCm venvrocm101twithHIP_VISIBLE_DEVICES=1. No GPU kernels were exercised; no timing run was needed.ruff check gptqmodel docs/eora tests setup.pypytest tests/module_tree/test_registered_module_plans.py tests/module_tree/test_definition_subset_ordering.py tests/module_tree/test_jamba_model_tree_consumption.py -q(CUDA)pytest tests/module_tree/test_shared_input_cpu_forward.py tests/module_tree/test_shared_input.py -q(CUDA)The new
test_definition_subset_ordering.pyfails onorigin/main: it asserts the exact subset index per producer/consumer pair and that every called AXK2nn.Linearresolves through the plan. It passes on this branch.6. Reviewer notes