Skip to content

fix(ernie4_5_vl_moe): expand routed text/vision expert indices - #3754

Merged
Qubitium merged 5 commits into
mainfrom
fix/ernie4-5-vl-moe-expert-index
Nov 10, 2026
Merged

Qubitium merged 5 commits into
mainfrom
fix/ernie4-5-vl-moe-expert-index

Conversation

@ZX-ModelCloud

@ZX-ModelCloud ZX-ModelCloud commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR

Ernie4_5_VLMoeQModel declared no dynamic_expert_index, so simple_layer_modules() returned the literal {expert_index} placeholder for both routed-expert families. Quantization matches concrete module names, so create_named_modules() could never hit those six entries; with layer_modules_strict = False each one was only recorded as a miss and both the text and the vision experts stayed in the source dtype.

The fix declares the expert cardinality, resolves it from the config object that actually owns it, and adds registry-wide plus real-model regression coverage. Declaring the field also exposes an independent defect on the published checkpoints — a per-modality moe_num_experts = [64, 64] list that previously fed a bare range() — so the same change makes a non-scalar count resolve to "unresolved" instead of raising.

Measured on the converted ERNIE 4.5 VL MoE config (64 experts): before 16 specs with 6 placeholders, after 394 specs with 0 placeholders (192 per expert family). dbrx_converted had the same class of defect and is fixed in the same change.

1. The problem

1a. Placeholder never expanded

# in a module tree is a placeholder, not a path. build_moe_modules_if_need() only expands it when the definition declares dynamic_expert_index (gptqmodel/models/base.py:1146). On main (c9704b72c) gptqmodel/models/definitions/ernie4_5_vl_moe.py:24-65 sets layer_modules_strict = False but never declares that attribute, so the placeholder survives into create_named_modules() (gptqmodel/looper/module_looper.py:2056-2067):

mlp.text_moe.experts.{expert_index}.gate_proj
mlp.text_moe.experts.{expert_index}.up_proj
mlp.text_moe.experts.{expert_index}.down_proj
mlp.vision_moe.experts.{expert_index}.gate_proj
mlp.vision_moe.experts.{expert_index}.up_proj
mlp.vision_moe.experts.{expert_index}.down_proj

Because the definition is non-strict, the miss is recorded rather than raised: quantization "succeeds" while every text and vision routed expert remains unquantized.

1b. The field is not on the top-level config

For the converted snapshots this work was measured on, moe_num_experts lives on the nested text_config; the multimodal wrapper does not expose it. The legacy resolver only followed text_config / thinker_config.text_config, so DBRX — which keeps moe_num_experts under ffn_config — could not declare the field at all:

Config layout top-level moe_num_experts owner
converted ERNIE (ernie4_5_vl_moe, text_config present) absent text_config
dbrx absent ffn_config
published ERNIE VL (ernie4_5_moe_vl, flat) [64, 64] top level

1c. The published checkpoints carry a per-modality list

baidu/ERNIE-4.5-VL-28B-A3B, ...-28B-A3B-PT and ...-424B-A47B-PT ship a flat remote-code config: model_type = "ernie4_5_moe_vl" (the backward-compatibility alias mapped to this same definition), auto_map present, no text_config, and moe_num_experts = [64, 64]. has_native_transformers_causallm_support() is false for those repos, so the remote-code load path is reachable.

Declaring dynamic_expert_index on its own turns that into a hard failure:

TypeError: 'list' object cannot be interpreted as an integer
  gptqmodel/models/base.py:1228  for index in range(expert_count(n))

On main the same config produced 16 specs with 6 placeholders and only recorded a miss. An attribute-only fix therefore converts a silent, non-fatal defect into a crash for the checkpoints users actually download.

Summing the list is not a valid fix: the remote-code model fuses both families under mlp.experts and splits them by modality through mlp_text, while the converted layout exposes text_moe / vision_moe with 64 each. One summed cardinality expands the wrong number of names for either family.

1d. Undeclared checkpoint-owned weights

dbrx_converted also left norm_attn_norm.norm_1, norm_attn_norm.norm_2 and ffn.router.layer undeclared, so a real checkpoint audit reported checkpoint weights with no owning plan spec.

2. The new flow

flowchart TD
    T["definition.module_tree contains #"] --> G{"dynamic_expert_index declared?"}
    G -->|"no"| RAW["simple_layer_modules returns the literal<br/>EXPERT_INDEX_PLACEHOLDER path"]
    G -->|"yes"| R["get_num_experts(config)"]
    R --> C["_expert_count_config(config, field)"]
    C --> T1{"config.text_config?"}
    T1 -->|"yes"| USE1["text_config"]
    T1 -->|"no"| T2{"config.thinker_config?"}
    T2 -->|"yes"| USE2["thinker_config.text_config"]
    T2 -->|"no"| T3{"ffn_config declares field?"}
    T3 -->|"yes"| USE3["ffn_config"]
    T3 -->|"no"| USE4["top-level config"]
    USE1 --> N["expert count"]
    USE2 --> N
    USE3 --> N
    USE4 --> N
    N --> S{"_coerce_expert_count:<br/>scalar value?"}
    S -->|"yes"| EXP["expand # to 0..N-1"]
    S -->|"no, e.g. [64, 64]"| NONSCALAR["returns None"]
    NONSCALAR --> KEEP["build_moe_modules_if_need keeps<br/>literal placeholder, warns once"]
    KEEP --> MISS
    RAW --> MISS["create_named_modules: record_miss<br/>no exception when strict is False"]
    EXP --> HIT["concrete names resolve"]
    style RAW fill:#ffa39e,stroke:#a8071a
    style MISS fill:#ffa39e,stroke:#a8071a
    style NONSCALAR fill:#ffe7ba,stroke:#ad6800
    style KEEP fill:#ffe7ba,stroke:#ad6800
    style HIT fill:#d9f7be,stroke:#237804
Loading

A missing field is not on this diagram on purpose: getattr(config, field) keeps raising AttributeError, because that means the definition and the config disagree rather than that the value is unexpandable.

2a. Nested-config resolution

gptqmodel/models/base.py:

@classmethod
def _expert_count_config(cls, model_config, field_name: Optional[str] = None):
    """Return the config object that owns the routed-expert cardinality."""
    if hasattr(model_config, "text_config"):
        return model_config.text_config
    if hasattr(model_config, "thinker_config"):
        return model_config.thinker_config.text_config
    ffn_config = getattr(model_config, "ffn_config", None)
    if ffn_config is not None and (
        field_name is None or getattr(ffn_config, field_name, None) is not None
    ):
        return ffn_config
    return model_config

Both get_num_experts() and get_num_experts_for_module() use it, so the precedence stays identical for the existing definitions and only the previously-unresolvable ffn_config case changes.

The ffn_config branch is guarded by the field lookup: an unrelated architecture that happens to carry an ffn_config object without the expert-count field would otherwise select it and newly raise AttributeError, shadowing a cardinality kept on the top-level config. test_ffn_config_does_not_shadow_a_top_level_expert_count pins that behaviour.

I walked every MODEL_MAP definition that declares dynamic_expert_index and compared old against new resolution: 0 regressions (only dbrx_converted gains a resolvable field).

2b. Non-scalar cardinality is unresolved, not a crash

_coerce_expert_count() returns a non-negative int for a scalar value and None for a list/tuple/dict/set/bool. build_moe_modules_if_need() keeps the literal placeholder for an unresolved count, warns once per definition, and lets create_named_modules() record the miss. ModuleLooper skips the routing override when the count is unresolved instead of calling routing_override(None).

@classmethod
def _coerce_expert_count(cls, value) -> Optional[int]:
    if value is None or isinstance(value, bool):
        return None
    if isinstance(value, (list, tuple, dict, set, frozenset)):
        return None
    try:
        return max(int(value), 0)
    except (TypeError, ValueError):
        return None

2c. Definitions

File Change
ernie4_5_vl_moe.py dynamic_expert_index = "moe_num_experts"; moe_statics:! on both routers (independent fix, see below)
dbrx_converted.py dynamic_expert_index = "moe_num_experts"; explicit norm_1:!, norm_2:!, router.layer:!

The routers and their score-correction bias are checkpoint-owned but never quantized, so they carry an explicit :! tag rather than relying on a default.

moe_statics:! is an independent fix, not a consequence of the placeholder bug. gate.moe_statics.e_score_correction_bias is a separate checkpoint-owned tensor under the router path; declaring only gate:! leaves that bias with no owning spec, so it would surface as an undeclared owner in a checkpoint audit even after the expert indices expand correctly. It is included here because it is the same declaration site and the same "checkpoint weight, no plan owner" defect class.

3. Before / after and the failure contract

Mechanism Before (main) After Evidence (old → new)
Config owner lookup duplicated inline in get_num_experts and get_num_experts_for_module; text_config, thinker_config, else top level single _expert_count_config(); adds a guarded ffn_config step base.py:1236-1244, :1273-1277 → base.py:_expert_count_config
ERNIE dynamic_expert_index unset "moe_num_experts" ernie4_5_vl_moe.py declaration
ERNIE expert specs (converted, 64) 6 literal placeholders 384 concrete names base.py:build_moe_modules_if_need
ERNIE total specs (converted, 64) 16 394 measured
ERNIE placeholder leaks (converted) 6 0 measured
ERNIE scalar count (64) expands expands unchanged
ERNIE list count ([64, 64]) TypeError in range() unresolved → placeholder kept → miss base.py:1228 → _coerce_expert_count
Missing cardinality field AttributeError AttributeError unchanged
DBRX dynamic_expert_index unset "moe_num_experts" dbrx_converted.py
DBRX placeholder leaks 3 0 measured
DBRX undeclared weight owners norm_1, norm_2, router.layer explicit :! each dbrx_converted.py
Silent-miss path placeholder reaches create_named_modules and is only recorded concrete names, no expert miss module_looper.py:2063-2066

Situation → outcome for the cardinality value:

Situation Before After
scalar (64) expands to 64 expands to 64
non-scalar ([64, 64]) TypeError, quantization aborts None → placeholder kept, warned once, recorded as miss
field absent AttributeError AttributeError

4. Validation

The real Transformers config and the real Defuser conversion are used throughout; no mocked dispatch.

pytest module_tree/test_registered_module_plans.py \
       module_tree/test_moe_tags.py \
       module_tree/test_shared_input.py \
       module_tree/test_shared_input_cpu_forward.py \
       module_tree/test_moe_expert_coverage.py \
       module_tree/test_ernie_vl_moe_expert_coverage.py \
       module_tree/test_ernie_expert_projections.py \
       module_tree/test_module_tree_variants.py \
       module_tree/test_explicit_module_plan.py
  1026 passed, 136 skipped

pytest module_tree/test_ernie_vl_moe_expert_coverage.py
  9 passed

pytest module_tree/test_registered_module_plans.py -k "non_scalar or missing_expert_field or ffn_config"
  5 passed

New tests:

Test Invariant
test_definition_declares_the_text_config_expert_count field name resolves via text_config, not the wrapper
test_defuser_layout_splits_the_fused_checkpoint_experts real conversion yields both text_moe / vision_moe expert lists
test_layer_modules_expand_every_expert 3 × N concrete specs per family, no placeholder
test_every_quantizable_spec_resolves_on_the_real_layers every spec hits a decoder layer
test_every_checkpoint_weight_owner_is_declared_with_the_right_tag all state_dict() owners resolve through ModulePlan.find(); non-quantized owners are explicitly tagged
test_routers_and_score_correction_bias_are_not_quantized gate / moe_statics excluded, every expert projection quantized
test_module_plan_exposes_both_expert_containers plan-level expert containers and family identity
test_looper_records_no_miss_for_expanded_expert_specs no expert name is a miss
test_ffn_config_does_not_shadow_a_top_level_expert_count an ffn_config without the field does not shadow a top-level count
test_quantized_model_covers_both_expert_families tiny end-to-end load → quantize; every text/vision expert projection is a TorchLinear
test_non_scalar_expert_count_fails_closed_instead_of_raising (both aliases) list count returns None, keeps every placeholder, does not raise; scalar count still expands
test_missing_expert_field_still_raises an absent field keeps raising AttributeError

Registry-wide guards added to test_registered_module_plans.py:

  • test_every_expert_placeholder_expands_to_concrete_names — every definition whose tree declares the placeholder must also declare dynamic_expert_index, and expansion must leave no placeholder (covers all nesting precedences generically).
  • test_dbrx_converted_nested_ffn_config_expert_count — DBRX cardinality plus explicit non-quantized tags.

test_moe_expert_coverage.py: the PLACEHOLDER_EXPERT_MODELS xfail for ernie4_5_vl_moe is removed; the model moves into FIXED_MODELS so a regression fails loudly instead of being tolerated.

ruff check is clean on all changed files.

Pre-existing, unrelated

  • test_flash_model_tree_consumption.py::...[glm5_next] fails identically on clean main (owner count 41 ≠ 37).
  • test_fusable_models.py cohere_compass / flint fail on clean main (missing transformers.models.flint).
  • test_subset.py::test_stage_subset_early_stop_and_callbacks and test_qwen3_5_moe_subset_early_stop_follows_module_tree_execution_order fail identically on clean main (_DummyQwen3_5Model has no prepare_layer_replay_keep_mask).

Scope limit

A full 28B checkpoint quantization was not run. The evidence here is the real meta model through the real Defuser conversion, a real-checkpoint key audit (all 28 layers, text_config.moe_num_experts=64, keys model.layers.N.mlp.experts.{0..127} split 0–63 text / 64–127 vision by the HF conversion mapping), and a tiny local end-to-end quantization. This local reproduction is not a substitute for a full-model quantization result. The published flat-config layout is covered at the resolution/expansion level (the non-scalar tests), not by instantiating its remote code.

5. Flow documentation

Expert cardinality is a resolution decision, so it is documented as one:
docs/model-tree-resolution.md gains an Expert cardinality resolution page
(### Expert cardinality resolution) containing the same Mermaid flow drawn from
the shipped code, the before/after evidence table with file:line references,
and the explicitly marked failure path. README.md links that page directly.

The page also records the non-scalar contract: _coerce_expert_count() returns
None, build_moe_modules_if_need() keeps the placeholder and warns once, and
the miss is recorded downstream. Follow-up changes to the same flow update the
same page.

6. Reviewer notes

  • The ffn_config branch is the only behavioural addition to the resolution chain; the text_config / thinker_config / top-level precedence is byte-for-byte preserved. The branch is field-guarded (see 2a), so it cannot shadow a top-level count.
  • The scalarity guard (2b) only narrows the non-scalar case. Scalar counts expand exactly as before, and a missing field still raises.
  • layer_modules_strict stays False on Ernie4_5_VLMoeQModel, now with an in-code rationale: one tree serves both dense and sparse layers, so every decoder layer legitimately misses the other branch's specs (a dense layer has mlp.gate_proj/up_proj/down_proj but no experts; a sparse layer has both MoE families and no dense MLP). Strictness would fail on every layer for reasons unrelated to expert coverage; the expanded-expert invariants are asserted by test_layer_modules_expand_every_expert and test_looper_records_no_miss_for_expanded_expert_specs instead.
  • The DBRX tree matches the converted (dbrx_converted) layout that this definition loads via remote code: ffn.experts.mlp.{i}.w1/v1/w2, norm_attn_norm.norm_1/norm_2, ffn.router.layer. Defuser's dbrx entry does not rewrite that layout, so no second mapping is needed here.
  • deepseek_vl_v2 overrides get_num_experts() for language_config and is unaffected.
  • DBRX is fixed here rather than in a separate PR because it is the same root cause (an expert-cardinality field the resolver could not reach) plus the same missing non-quantized tags; splitting it would leave a known-broken definition in MODEL_MAP.

`Ernie4_5_VLMoeQModel` declared no `dynamic_expert_index`, so
`simple_layer_modules()` returned the literal `{expert_index}` placeholder for
both expert families. Quantization matches concrete module names, so
`create_named_modules` could never hit those entries; with
`layer_modules_strict = False` each one was only recorded as a miss and both
the text and vision routed experts stayed in the source dtype.

Set `dynamic_expert_index = "moe_num_experts"` on the definition. The field is
owned by the nested `text_config`, not the multimodal wrapper, so resolve it
through `BaseQModel._expert_count_config()`, which follows `text_config`, then
`thinker_config.text_config`, then `ffn_config`, then the top-level config.
`ffn_config` covers DBRX, which had the same class of defect: no
`dynamic_expert_index`, and undeclared `norm_1`, `norm_2` and router weights.

Both ERNIE families are also fully declared now: the routers and their
`moe_statics` score-correction bias carry `:!`, and the DBRX norms and router
layer do too, so every checkpoint-owned weight has a declared owner with the
right tag.

Measured on the default ERNIE config (64 experts): before, 16 specs with 6
placeholders; after, 394 specs with 0 placeholders, 192 per expert family.

Tests:
- registry-wide placeholder-expansion guard over every `MODEL_MAP` definition
- real-model Defuser layout, layer-spec expansion, weight-ownership and plan
  contract for ERNIE text/vision experts
- tiny end-to-end load/quantize asserting each expert projection becomes a
  quantized linear
- DBRX nested `ffn_config` cardinality and explicit non-quantized tags

Docs: `docs/module-plan-guide.md` records the nested-config resolution rule and
the silent-miss consequence.
The new `_expert_count_config()` returned `ffn_config` whenever the
attribute existed, before falling back to the top-level config. For a config
that carries an unrelated `ffn_config` sub-config but keeps its routed-expert
cardinality at the top level, that branch selected an object without the
field and `get_num_experts()` raised `AttributeError` instead of reading the
top-level value. Existing definitions were unaffected only because no
HF-resolvable model type in `MODEL_MAP` currently exposes `ffn_config` other
than DBRX; a remote-code config would hit it.

Resolve `ffn_config` only when it actually declares the requested field, so
the added branch cannot shadow a resolvable top-level cardinality. Document
the narrowed condition and add a regression test covering the top-level-only,
`ffn_config`-owned, and both-declared cases.

Tests: 1023 passed, 136 skipped across the module-plan suites;
ruff check clean.

@ZX-ModelCloud ZX-ModelCloud left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: verified, plus one resolution bug fixed on the branch

I reproduced the defect on c9704b72c and validated the fix on a2076de3c, then
pushed one follow-up commit (cf4da26fd) for a resolution regression the change
introduced. Details below.

Claims I reproduced independently

Claim Result
ERNIE default config: 16 specs / 6 placeholders → 394 specs / 0 placeholders, 192 per family confirmed exactly
moe_num_experts absent on the multimodal wrapper, present on text_config confirmed
DBRX: 3 placeholder leaks and undeclared norm_1 / norm_2 / router.layer on main confirmed exactly
End-to-end ERNIE expert coverage fails on main confirmed: mlp.text_moe.experts.0.gate_proj stays HookedLinear; passes on the branch
A surviving placeholder is a silent miss under layer_modules_strict = False confirmed at module_looper.py:2066
"0 regressions" walking every dynamic_expert_index definition confirmed. I compared old vs. new resolution for all 70 such definitions against real HF configs; only dbrx_converted gains a resolvable field

The new tests are real guards, not snapshots. Deleting dynamic_expert_index from
the definition fails 7 tests, including the registry-wide one. The suite the PR
lists reports 1020 passed, 136 skipped here (the PR says 1022; the two extra are
test_ernie_expert_projections.py, which I ran separately and also passes). The
test_fusable_models.py cohere_compass/flint failures are identical on main
(22/22 same node IDs), so they are pre-existing.

I also audited the real converted DBRX checkpoint (dbrx_converted,
ffn_config.moe_num_experts = 16): 52 concrete specs, 0 placeholders, 0 missing
specs, and 0 undeclared state_dict() owners. The experts.mlp.#.{w1,v1,w2} and
separate q/k/v layout matches the definition. The PR only tests DBRX at config
level, so this closes that gap; it would be worth committing as a test if a
checkpoint is available in CI.

Bug introduced by this change (fixed in cf4da26fd)

_expert_count_config() returned ffn_config whenever the attribute existed,
before falling back to the top-level config. For any config that carries an
unrelated ffn_config sub-config but keeps its expert count at the top level, the
new branch selected an object without the field and get_num_experts() raised
AttributeError instead of reading the top-level value:

qwen3_moe  with SimpleNamespace(ffn_config=..., num_experts=8)
  before this PR: 8
  as submitted:   AttributeError: no attribute 'num_experts'

It is latent today only because dbrx is the sole HF-resolvable MODEL_MAP type
exposing ffn_config; any remote-code config would hit it. The fix selects
ffn_config only when it actually declares the requested field, and adds a
regression test for the top-level-only, ffn_config-owned, and both-declared
cases. The PR note that "the text_config / thinker_config / top-level
precedence is byte-for-byte preserved" was therefore not accurate as written; the
doc and test now state the narrowed condition.

Remaining review points (not blocking)

  1. Flow documentation. The PR argues no diagram is needed because this only
    sets an attribute and adds a fallback. The second half is a change to a
    resolution order inside a new function (_expert_count_config) and it converts
    a silent no-op into quantization work, which the repository guidance lists as
    diagram-qualifying. A compact before/after table plus one flowchart in the
    existing docs/module-plan-guide.md section would satisfy it without a new
    page. Your call, but I would not waive it on the current justification.
  2. layer_modules_strict stays False. With the experts now expanded, the
    remaining per-layer misses are only the dense/sparse branch difference
    (mlp.gate_proj etc. on sparse layers, the 384 expert specs on dense layers),
    which is expected. Flipping to strict still fails the end-to-end test, so
    leaving it is correct — worth one sentence in the PR so a future reader does
    not assume it was overlooked.
  3. moe_statics scope. The PR description frames the ERNIE change as
    dynamic_expert_index plus router tags; the moe_statics:! addition is a
    third, independently necessary fix (verified: mlp.vision_moe.gate.moe_statics
    is an undeclared checkpoint owner on main). Worth listing explicitly.

No GPU/accelerator-specific results are included here by request; device coverage
was checked separately.

…s rationale

Add an expert-cardinality resolution reference page under docs/ (Mermaid
flow plus before/after evidence table) and link it from README. Annotate
the ERNIE declaration in place: why layer_modules_strict stays False for a
tree that serves both dense and sparse layers, and why moe_statics needs
its own :! entry instead of riding on gate:!.
@ZX-ModelCloud

Copy link
Copy Markdown
Collaborator Author

All three non-blocking points are addressed in b1215dfd6.

  1. Flow documentation — added a committed reference page section,
    docs/model-tree-resolution.md → Expert cardinality resolution: a Mermaid
    flowchart drawn from the shipped code (build_moe_modules_if_need →
    get_num_experts → _expert_count_config), the before/after evidence table,
    and the silent-miss branch marked explicitly. README.md links that section
    directly. The PR description's "no diagram needed" argument is replaced.
  2. layer_modules_strict = False — rationale now lives in the definition
    itself, next to the flag, and is restated in the PR's reviewer notes: one tree
    serves dense and sparse layers, so each layer legitimately misses the other
    branch's specs; the expanded-expert invariants are covered by
    test_layer_modules_expand_every_expert and
    test_looper_records_no_miss_for_expanded_expert_specs.
  3. moe_statics scope — now called out as an independent fix in section 2b,
    with the reason it is not implied by gate:!
    (gate.moe_statics.e_score_correction_bias is a separate checkpoint-owned
    tensor under the router).

Re-validated after the edits: 1023 passed, 136 skipped on the nine module-tree
suites, ruff check clean on every changed file. Line references in the docs were
re-checked against the committed file (ernie4_5_vl_moe.py:44, :74,81).

ZX-ModelCloud and others added 2 commits November 10, 2026 08:14
`Ernie4_5_VLMoeQModel` now declares `dynamic_expert_index =
"moe_num_experts"`, but the *published* ERNIE 4.5 VL repositories
(`baidu/ERNIE-4.5-VL-28B-A3B`, `...-28B-A3B-PT`, `...-424B-A47B-PT`) do not
use the converted `text_config` layout this branch measured. They ship a flat
remote-code config with `model_type = "ernie4_5_moe_vl"` (mapped to the same
definition) and a per-modality `moe_num_experts = [64, 64]`.

`build_moe_modules_if_need()` fed that list straight to `range()`:

    TypeError: 'list' object cannot be interpreted as an integer
      gptqmodel/models/base.py:1228  for index in range(expert_count(n))

On `main` the same config returned 16 specs with 6 placeholders and only
recorded a miss. The branch therefore turned a silent, non-fatal defect into a
hard quantization failure for the checkpoint users actually download.

`_coerce_expert_count()` accepts a non-negative scalar and returns None for
list/tuple/dict/set/bool, and both expansion paths now keep the literal
placeholder, warn once per definition, and let `create_named_modules()` record
the miss. A *missing* field still raises `AttributeError`, so a real
definition/config mismatch stays loud.

`ModuleLooper` skips a routing override when the count is unresolved instead
of calling `routing_override(None)`.

Do not sum the list: the remote-code model fuses both families under
`mlp.experts` and `mlp.mlp_text` splits them by modality, so a single summed
cardinality would expand the wrong number of names for either family. The
converted layout that Defuser produces (`text_moe`/`vision_moe`, 64 each) is
unaffected because its `text_config.moe_num_experts` is the scalar 64.

Tests: new registry cases for both aliases (non-scalar → placeholder kept, no
exception; scalar → expands) and for a missing field still raising.
1026 passed, 136 skipped across the module-plan suites; ruff clean.

Copy link
Copy Markdown
Collaborator

Review notes: I checked cardinality lookup and concrete expert expansion against the real Transformers + Defuser ERNIE layout, DBRX's ffn_config, the module plan, and the checkpoint-owner tags. The integrated module-tree suites pass locally (435 passed, 137 skipped), including a tiny end-to-end ERNIE quantization that replaces both text and vision expert families with TorchLinear. Ruff and diff checks pass. I merged current main into the PR at 5df80cb before this run.

Scope note: the published flat remote-code ERNIE configs with moe_num_experts=[64,64] still leave routed placeholders unresolved; this PR preserves the pre-existing non-strict miss for that distinct runtime layout and fixes the converted Transformers/Defuser layout. The PR body documents that limitation. I have not treated the published remote-code checkpoints as validated quantization targets here.

@Qubitium
Qubitium marked this pull request as ready for review November 10, 2026 09:59

@Qubitium Qubitium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the converted ERNIE text/vision expert expansion and DBRX cardinality/owner fixes. The integrated module-tree suites pass (435 passed, 137 skipped), including an end-to-end tiny ERNIE quantization, and Ruff/diff checks pass. The PR discussion records the distinct published flat remote-code config limitation.

@Qubitium
Qubitium merged commit 1994570 into main Nov 10, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/ernie4-5-vl-moe-expert-index branch November 10, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants