You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a437f03
Browse filesBrowse the repository at this point in the historyBrowse files
Add GLM-5.2 (glm_moe_dsa) model support with DSA/IndexShare + full-attention fallback
Registers the `glm_moe_dsa` model_type (zai-org/GLM-5.2,
`GlmMoeDsaForCausalLM`) by reusing existing DeepSeek MLA/MoE/QMoE-fusion
machinery rather than merging draft PR #404 or sibling branch
`feat/glm-dsa-indexshare` wholesale. Both were audited hunk-by-hunk; several
correctness bugs found in the sibling branch (RoPE-split, 4D/3D MatMul
broadcast, and IndexShare non-f32 inputs) were fixed here instead of carried
over.
- `src/mobius/models/glm_moe_dsa.py` (new): `GlmMoeDsaIndexer` (DSA top-k
scoring/selection), `GlmMoeDsaAttention` (subclasses `DeepSeekMLA`,
exports the frozen `pkg.nxrt::IndexShare` op for the "full"/"shared"
indexer schedule), `GlmMoeDsaDecoderLayer`, `GlmMoeDsaTextModel`,
`GlmMoeDsaCausalLMModel` (subclasses `DeepSeekV3CausalLMModel`).
`config.use_dsa=False` (the new `--glm-full-attention` CLI feature)
switches to plain dense MLA attention executable on stock ONNX Runtime,
as a fallback until the native IndexShare runtime kernel lands.
- `src/mobius/_configs/_base.py`: 6 new `ArchitectureConfig` fields for DSA
(index_topk, index_head_dim, index_n_heads, index_topk_freq,
index_skip_topk_offset, use_dsa) and HF-config extraction, including a
`model_type == "glm_moe_dsa"`-conditional default so `scoring_func`/
`topk_method` correctly resolve to GLM's sigmoid/noaux_tc routing (the
real GlmMoeDsaConfig does not declare these as dataclass fields, so they
are silently absent instead of inheriting DeepSeek's softmax/greedy
defaults) when a config omits them.
- `src/mobius/_registry.py`, `src/mobius/models/__init__.py`: registration
wiring for `glm_moe_dsa`.
- `src/mobius/__main__.py`, `src/mobius/integrations/transformers/_builder.py`:
new `--glm-full-attention` cargo-style build feature, threaded through
both the `--config` (local directory) and `--model` (HF id, including the
diffusers-dispatch fallback branch) build paths as `glm_full_attention`,
validated to only apply to `model_type == "glm_moe_dsa"`.
- `src/mobius/models/glm_moe_dsa_test.py` (new, 21 tests): registry mapping,
indexer schedule formula (cross-checked against the real installed
`transformers.models.glm_moe_dsa` config's own derivation), HF config
extraction (scoring_func/topk_method regression), graph-build structural
tests for both the DSA and full-attention-fallback paths (IndexShare/
Attention op counts, indexer weight presence, QMoE fusion, and a
regression test asserting IndexShare's query/key/value inputs are cast to
float32 under a non-float compute dtype, matching the frozen op's f32-only
schema), `preprocess_weights` tests (MTP-layer and indexer-weight
dropping), and two numeric-parity tests against the real HF reference
implementation (raw index-score parity, and a tie-tolerant top-k
correctness property test -- selected-index-set equality is not asserted
because `torch.topk`/ONNX `TopK` have different, individually valid
tie-breaking conventions at degenerate/tied score boundaries).
- `src/mobius/integrations/transformers/_builder_test.py`: tests for the new
`glm_full_attention` override/validation, including the diffusers-dispatch
branch.
Not in scope for this PR (documented here as follow-ups, no open tracking
issue found for either): MTP (multi-token-prediction) layer export -- the
real `transformers.models.glm_moe_dsa` reference implementation itself has
no MTP module, so base-model logits correctly never include an unsupported
MTP path; `preprocess_weights` drops MTP-layer weights with a warning
instead. GGUF import support. CUDA residency/scheduler work.
Local evidence: 523/523 `src/mobius/models/` tests pass, 115/115 targeted
tests pass (glm_moe_dsa_test.py, deepseek_test.py, deepseek_v4_test.py,
_registry_test.py, integrations/transformers/*), 28/28 `_configs/` tests
pass. `ruff check`/`ruff format --check` clean (pinned lintrunner version
0.16.2).
Co-authored-by: Copilot <[email protected]>
0 commit comments