Repository navigation
fix(models): resolve module roles from explicit model trees - #3565
Merged
Merged
Conversation
Add $gptqmodel-logic-flow-diagrams skill, wire it into AGENTS.md and the PR template, and commit the resolved model-tree flow as a reference page. - .agents/skills/gptqmodel-logic-flow-diagrams: when the rule applies, required artifacts (new-flow diagram, before/after evidence, docs page), accuracy rules, Mermaid authoring rules for GitHub rendering, and a review checklist. - AGENTS.md: repo-wide instruction to apply the skill before opening a PR. - .github/PULL_REQUEST_TEMPLATE.md: reviewable checklist for the same gate. - docs/model-tree-resolution.md: the PR #3565 flow, diagrams and contracts, kept for future reference. - README.md: link the new page from the quantization support section.
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.
Summary
Module classification and quantization selection now use the architecture's declared
module_tree, compiled into a layer-relativeModulePlan. Paths that merely resemble a declared module no longer inherit its expert family or rotation behavior. Unknown architectures require an explicit definition or injected tree.The PR also exposes
model.module_plan()for inspection and adds an always-run contract for every active model registry entry. New model support must add both a registry case and a model-specific module-plan unit test.Measured diff against
main(0aaf40e): 45 files, +5,468 / −234. The explicit registry expectation fixture accounts for 2,461 added lines. Flow reference: docs/model-tree-resolution.md.1. Removed decisions and their replacements
Source references in the “before” column refer to base commit
0aaf40e.looper/module_looper.py:924: split on.experts.,.shared_experts., or.shared_expert.ModulePlan.find()looper/module_looper.py:947: substring checks forattn/attentionmodels/base.py:836: substring/suffix membershipmodels/loader.py:1926,models/writer.py:1322: suffix-based quantizabilitymodels/loader.py:676:endswith("mlp.down_proj")down; no suffix fallback for undeclared pathsFor example, declaring
mlp.experts.#.gate_projpermitsmlp.experts.3.gate_proj. It does not permitmlp_extra.experts.3.gate_projormlp.experts.3.undeclared. Hymba's literalmoe.experts.0is also recognized as an expert family; it is not classified as a shared branch.2. Compilation and ownership
flowchart TD LOAD["model loaded"] --> RES["_resolve_effective_module_tree()"] RES --> INJECT{"explicit injected tree?"} INJECT -->|"yes"| OVERRIDE["apply method override"] INJECT -->|"no"| DEF["registered definition.module_tree"] DEF --> OVERRIDE OVERRIDE --> CHECK{"tree exists?"} CHECK -->|"no"| ERROR["ValueError: explicit definition required"] CHECK -->|"yes"| FREEZE["freeze effective_module_tree"] FREEZE --> PLAN["ModulePlan.from_tree()"] PLAN --> API["model.module_plan()"] API --> CONSUMERS["AWQ / loopers / rotation / GSQ"] API --> HOOKS["per-instance copied MoE hooks"] style ERROR fill:#ffa39e,stroke:#a8071a style PLAN fill:#d9f7be,stroke:#237804The effective tree is stable for the instance. Live model consumers obtain the compiled plan through
model.module_plan(). Definition-level planning remains available before a wrapper exists. Unbound lifecycle hooks compile from the definition or call the live wrapper accessor; they do not mistake the accessor method for a plan object. Hook copies keep instance-specific trees from leaking to later models.ModuleSpecrecords exact template paths and flags. Explicit projection tags override legacy canonical names declared in the tree. The legacyPROJECTION_ROLE_NAMESfallback (q_proj,w1,gate_up_proj, etc.) remains; this PR does not claim that every existing definition has been migrated to explicit role tags.q_proj:0:q:in=xxnorm:!:normmlp:moe:?experts.#experts.0gate_proj|w13. Exact expert queries and lifecycle consumption
flowchart TD ROOT["declared MoE root"] --> CHILD{"declared child structure"} CHILD -->|"# placeholder"| ROUTED["expert_containers()"] CHILD -->|"numeric child with projection leaves"| ROUTED CHILD -->|"other projection family"| SHARED["shared_expert_containers()"] ROUTED --> FIND{"ModulePlan.find(path)"} FIND -->|"declared"| GROUP["is_expert() / expert_root()"] FIND -->|"undeclared"| REJECT["False / None"] GROUP --> LOOP["ModuleLooper / WeightOnlyLooper grouping"] ROUTED --> HOOK["MoE lifecycle container lookup"] SHARED --> HOOK style REJECT fill:#ffa39e,stroke:#a8071aShared containers are derived from declared projection structure rather than an allow-list of names. Fixed numeric expert branches are excluded from shared-container classification. The new regressions cover both unbound routed/shared hooks and Hymba's fixed index, including rejection of an undeclared index.
4. Public debugging and extraction API
flowchart LR MODEL["model.module_plan()"] --> PLAN["ModulePlan"] PLAN --> TUI["print() / render()"] PLAN --> EXPORT["to_dict() / to_json() / summary()"] PLAN --> QUERY["find() / roles() / expert_root()"]The renderer shows quantization/exclusion/capture flags, projection roles, normalization and input tags, and expert/shared container structure.
to_dict()exposes a separatecontainerfield: structural containers must not be interpreted as weight-bearing quantization targets merely because they lack an exclusion flag.ModulePlanandModuleSpecare exported fromgptqmodelandgptqmodel.models.5. Consumer changes and rotation guarantees
normflags andq/k/v/o/gate/up/downrolesNormalization is a tag, not a projection role.
fuse_layer_norms()now readsnormflags directly; querying projection roles fornormwould always produce an empty list. A real tiny Llama test initializes non-unit norm weights and verifies logits before and after fusion atatol=rtol=1e-6. Both explicit-plan and public-default calls are tested.flowchart TD P["rotation plan"] --> N["root specs with norm flag"] N --> COUNT{"exactly two layer norms?"} COUNT -->|"no"| FAIL["ValueError"] COUNT -->|"yes"| FUSE["fuse_layer_norms()"] P --> PATH["declared decoder-relative path"] PATH --> DOWN{"down role?"} DOWN -->|"yes"| HAD["attach online Hadamard state"] DOWN -->|"no / undeclared"| IGNORE["leave module untouched"] style FAIL fill:#ffa39e,stroke:#a8071aThe legacy online-rotation suffix default is retained only for public calls that supply no plan. With a plan, a quantized module outside the declared decoder cannot acquire a transform through a matching suffix. GSQ's existing Llama/Qwen3 staged-capture limits remain; accepting declared inventories does not imply arbitrary architecture support.
6. Checkpoint-owned weight coverage
The compiled plan is a layer-relative decoder inventory. Base-module/embedding metadata remains separate. The real Flash-family tests audit every checkpoint-weight owner within their decoder layers, including non-quantized routers, norms, compressors, and other inference weights.
flowchart TD FIX["real model architecture fixture: state_dict()"] --> OWNER["deepest owning module"] CKPT["actual checkpoint keys + conversion mappings"] --> OWNED{"checkpoint-owned?"} OWNED -->|"yes"| OWNER OWNED -->|"runtime-created only"| OUT["not a definition obligation"] OWNER --> FIND{"ModulePlan.find(owner)"} FIND -->|"missing"| FAIL["undeclared-weight failure"] FIND -->|"found"| QUANT{"quantizable inventory?"} QUANT -->|"yes"| OK["declared quantization target"] QUANT -->|"no"| TAG{"explicit exclusion/capture tag?"} TAG -->|"no"| FAIL TAG -->|"yes"| DENSE["declared non-quantized weight"] style FAIL fill:#ffa39e,stroke:#a8071astate_dict()is an architecture fixture, not proof of checkpoint provenance after runtime tensors have been created. Actual checkpoint audits use checkpoint keys and declared conversion mappings. Runtime-created buffers/parameters do not create declaration obligations solely because they appear in memory.The real model tests cover Qwen 3.8 (
qwen3_5), GLM 5.3 Flash, MiniMax M3.1 Flash, DeepSeek V4 Flash, and Ripple's real remote-code fixture. The DeepSeek V4.1 test remains conditional on upstreamdeepseek_v41support and does not relabel V4 coverage as V4.1 coverage.7. Every registered model has a module-plan unit test
The always-run registry contract covers 198 model-type entries, 173 definition classes, and 175 definition/method cases in the tested environment. It pins decoder prefixes and ordered quantization/capture/exclusion blocks in a reviewed fixture derived from the independent subset planner. It checks plan agreement with the subset/shared-input/norm/MoE planners, exact path rejection, looper expert grouping, per-variant compilation, and printable/serializable output.
Original
dbrxis a documented unsupported registry sentinel and receives a rejection test.dbrx_convertedreceives positive coverage. Thus the suite contains 197 positive model-type contracts, one explicit rejection case, and one registry-completeness gate: 199 passed, zero skipped.flowchart TD REG["MODEL_MAP entry"] --> CASE{"explicit inventory case?"} CASE -->|"missing"| FAIL["test failure: add model-plan case"] CASE -->|"present"| TREE["definition and method override"] TREE --> PLAN["ModulePlan.from_tree()"] TREE --> SUB["build_layer_modules() / shared-input metadata"] PLAN --> CHECK["compare paths, flags, norms, MoE and exact lookup"] SUB --> CHECK CHECK --> USE["loopers via module_plan()"] TREE --> REAL["separate real-model tests: actual layout and weight owners"] style FAIL fill:#ffa39e,stroke:#a8071aThis registry suite is compiler/consumer unit coverage, not a claim that all remote checkpoints have been instantiated. Real model validation is separate.
AGENTS.md,.agents/skills/gptqmodel-model-plan-tests/SKILL.md, and the PR template now require every new model/alias to add an explicit case plus a model-specific test using the real model class, including variants, method overrides, weight tags, and relevant consumers. Missing optional implementations must be reported precisely; blanket exception skips and tree-generated fake models do not qualify as real-model validation.8. Validation
Final head validation on Python 3.14, Torch 2.15.0+cu132, Transformers 5.22.1:
pytest tests/module_tree/test_registered_module_plans.py -q --disable-warningspytest tests/test_rotation_persistence.py -q --disable-warningsCUDA_VISIBLE_DEVICES=0 pytest tests/module_tree tests/test_rotation_persistence.py tests/test_afmoe_support.py -q --disable-warningspython -m compileall -q gptqmodelgit diff --checkExisting broader-suite skips remain; the registry contract does not require opt-in flags, checkpoint downloads, or GPUs and has no skips.
The Llama 3.2 1B E2E tests also passed on earlier PR head
2d0ecbd. These used fast mode (final 2/16 layers quantized, 512 calibration examples). GPTQ's evaluation used eager attention because the configured FlashAttention2 package was absent. These scores are not presented as a full 16-layer quantization run:9. Change inventory
Measured against
0aaf40e; grouped totals include all changed files.No quantization math, checkpoint format, or public quantization-config schema is changed. The new rules and diagrams are committed in the repository so future model support can follow the same contracts.