Repository navigation
fix(models): split dots3_note routed experts through the loader's Defuser pass - #6448
Merged
Merged
Conversation
…user pass
Dots3NoteQModel.before_model_load replaced
`modeling_dots3_note.Dots3NoteTextExperts` with a per-expert ModuleList
adapter, but the vendored port's Dots3NoteTextMoE builds
`Dots3NoteExperts`. The swap therefore never took effect: routed experts
stayed fused as 3-D `gate_up_proj`/`down_proj` parameters, the declared
`mlp.experts.#.{gate,up,down}_proj` specs resolved nothing (silently, since
`layer_modules_strict = False`), and quantizing a dots3_note checkpoint
failed with "Lazy forward direct-state materialization left META tensors
under `mlp.experts`". The hook also assigned onto the port module and
`Dots3NotePreTrainedModel._init_weights` at load time, which AGENTS.md
forbids.
Declare `defuser_generic_experts = True`, the mechanism the other native
fused-expert definitions without a Defuser registry entry use (kimi_linear,
mimo_v2_flash, gemma4). The loader's `_convert_model_with_defuser` now
splits the experts into per-expert `nn.Linear` modules under the checkpoint
names. Remove the adapter class and the load-time class patching, and
update the dots3 reference page.
The regression test builds the tiny vendored-config model, runs the
loader's hook + conversion, and checks every routed projection is an
nn.Linear resolved and declared by the module plan, that the split forward
matches the fused forward, and that the load hook leaves the port classes
untouched.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Dots3NoteQModel.before_model_loadswappedmodeling_dots3_note.Dots3NoteTextExpertsfor a per-expertModuleListadapter. The vendored port'sDots3NoteTextMoEbuildsDots3NoteExperts, a different class, so the swap never took effect. The routed experts stayed fused as 3-Dgate_up_proj/down_projparameters, and the declaredmlp.experts.#.{gate,up,down}_projspecs matched nothing. Because oflayer_modules_strict = Falsethis was silent. Quantizing a dots3_note checkpoint then failed with:The hook also assigned onto the port module and onto
Dots3NotePreTrainedModel._init_weightsat load time. AGENTS.md forbids that ("never assigns onto a model class at load time").The fix uses the existing declarative mechanism instead. The other native fused-expert definitions that have no Defuser registry entry (
kimi_linear,mimo_v2_flash,gemma4) setdefuser_generic_experts = True, and the loader's_convert_model_with_defuserthen splits the experts.What Changed
gptqmodel/models/definitions/dots3_note.py: declaresdefuser_generic_experts = True. Removes_SeparateDots3Expertsandbefore_model_load, so no port-class assignment happens at load time.module_tree,after_model_load(router recovery binding) andzero_route_recovery_contextare unchanged.tests/module_tree/test_dots3_note_fork_plan.py: two new regression tests (see below).docs/dots3-separate-experts.md: the reference page now describes the shipped mechanism; the removed adapter and hook are dropped from the diagram.dots3_note. Its routed experts are now real per-expertnn.Linearmodules under the checkpoint names (model.layers.N.mlp.experts.K.{gate,up,down}_proj). They run through Defuser's genericlinear_loopforward, the same one kimi_linear and mimo_v2_flash use.GPTQModel.loadof a saved dots3_note checkpoint fails inload_hf_tokenizeron main (see Notes).Tests
The new tests build the tiny vendored-config model on CPU and follow the loader's order:
_call_before_model_load, then construction, then_convert_model_with_defuser.test_dots3_note_routed_experts_split_into_declared_linearschecks four things:mlp.experts.<i>.{gate,up,down}_projon each sparse layer is annn.Linear;find_modules, declared bysimple_layer_modules(), and quantized according toModulePlan.find();test_dots3_note_load_hook_leaves_port_classes_untouchedchecks that the load hook leavesvars()of the port module and ofDots3NotePreTrainedModelunchanged.Measured Impact
Measured on CPU with a tiny random-init dots3_note built from
tests/fixtures/ports/native_parity/dots3_note.json(layer 0 dense, layer 1 MoE with 4 routed experts, SmolLM2 tokenizer vocab).GPTQModel.load(..., QuantizeConfig(bits=4, group_size=16), device="cpu").quantize(...)mlp.expertssave()writes 12 per-expertmlp.experts.{0..3}.{gate,up,down}_proj.qweight, no fused expert keys; in-session quantized logits are finiteThe split forward differs from the fused forward only by fp32 rounding. Defuser's generic
linear_loopadds up the top-k slots, while the fused loop accumulates per expert withindex_add_. The fused path runsgrouped_mm, which rejects fp64, so an fp64 comparison is not possible.No shared code is touched; only the dots3_note definition changes. Its
module_tree, so its registry plan fixture, is unchanged.Model Support / Module Plan
MODEL_MAPentry has an explicit registry plan case. (No new entry; the existingDots3NoteQModel/gptqcase passes unchanged.)find_modules,simple_layer_modulesandModulePlan.find.)experts.<i>.<proj>keys.)fusable_models.json: unchanged, an existing non-applicability reason.model.module_plan(): not applicable, because no fusion changes.Model test node IDs and results:
tests/module_tree/test_dots3_note_fork_plan.py::test_dots3_note_owns_declared_routed_projectionPASSEDtests/module_tree/test_dots3_note_fork_plan.py::test_dots3_note_load_hook_leaves_port_classes_untouchedPASSED (FAILED on main)tests/module_tree/test_dots3_note_fork_plan.py::test_dots3_note_routed_experts_split_into_declared_linearsPASSED (FAILED on main)tests/test_native_definition_loading_0.py::test_definition_loader_builds_vendored_classes[dots3_note]PASSEDtests/module_tree/test_moe_expert_coverage.py::test_every_defined_model_type_resolves_routed_experts[dots3_note]PASSED (SKIPPED on main)AWQ onboarding safety
AWQ evidence and per-variant policy: not applicable, with one caveat. This PR makes no AWQ grouping, search, replay or fold changes, and
module_treeis unchanged. It does make the routed experts reachable, so AWQ now sees them. AWQ on dots3_note already crashes on main with_AWQScaleGroupError ... kv_a_proj_with_mqa has multiple scaling groupson sliding-attention layers, and that is being fixed in a separate PR. Only GPTQ was validated end-to-end here.Logic Flow Documentation
defuser_generic_expertsmetadata. The existing reference pagedocs/dots3-separate-experts.md(linked fromdocs/proposed-feature-reference-pages.md) is updated.gptqmodel/models/definitions/dots3_note.py:14_SeparateDots3Expertsand:83before_model_loadon main, both deleted.after_model_loadstill raisesRuntimeErroron a router-count mismatch.docs/proposed-feature-reference-pages.md, as before; no new page was added.Diagram summary: the existing page now shows
Dots3NoteQModelwithout the removed adapter and hook.Review Requirements
Kernel Accuracy Requirements
Notes
GPTQModel.load()of a saved dots3_note checkpoint fails before the model loads. The error isAttributeError: 'dict' object has no attribute 'bos_token', raised fromload_hf_tokenizer->Tokenicer.auto_fix_model_config. It reproduces on main with an all-dense tiny dots3_note, so it is independent of this change. Because of it, quantized reload could not be exercised.🤖 Generated with Claude Code