Skip to content

WIP: reconcile GLM-5.2 glm_moe_dsa (spec-decode + #130) - #158

Merged
drunkcoding merged 7 commits into
devfrom
reconcile/glm-5.2-fp8-onto-dev
Aug 15, 2026
Merged

WIP: reconcile GLM-5.2 glm_moe_dsa (spec-decode + #130)#158
drunkcoding merged 7 commits into
devfrom
reconcile/glm-5.2-fp8-onto-dev

Conversation

@drunkcoding

Copy link
Copy Markdown
Contributor

DRAFT — do not merge. Base: dev. This PR reconciles the two divergent glm_moe_dsa
implementations (spec-decode's, already on dev via #140; and PR #130's) into one canonical
stack by salvaging only #130's genuinely-unique, non-conflicting deltas onto dev.

Strategy

dev @ 0e4904f (post-#140/#150) is the canonical baseline: it already registers glm_moe_dsa
(type 5), ships its own DSA/MTP-integrated SyncGlmMoeDsaMoEBlock, the native FP8 e4m3 block-scale
dequant-on-copy path, DSA indexer/IndexShare, and MTP spec-decode. PR #130 branched from an older
dev (b33d5fa) and re-implemented an overlapping-but-divergent GLM/FP8 stack. Per the written
reconciliation plan, we canonicalize on dev and salvage only #130's unique wanted deltas —
dropping everything spec-decode already provides.

Full auditable triage (git cherry, range-diff, per-commit verdicts, and every deviation with evidence)
is in docs/superpowers/plans/2026-08-14-glm-5.2-reconciliation.decision-log.md (in this PR).

What landed (net wanted deltas) — 4 files

File Source What
moe_infinity/utils/fp8.py #130 707cc06 (subset) Append dequant_fp8_state_dict + stack_expert_scales (+re/typing/EXPERT_SCALE_KEY_RE). Byte-identical to #130's tested helpers; dev's dequant_fp8_blockwise untouched.
core/model/model_topology.cpp #130 b5a015a Coalesce sparse-expert partition reads into one sequential bulk read per file (struct TensorPlacement + posix_fadvise(SEQUENTIAL)); fixes multi-day cold-cache store reloads. clang-format clean.
tests/python/unit/test_glm_moe_dsa.py #130 9b49f43 Reconciled unit suite — the only coverage for the two new fp8 helpers. Two guards adapt it to dev (below).
docs/superpowers/plans/2026-08-14-glm-5.2-reconciliation.decision-log.md new Evidence + verdicts + deviations.

Per-commit verdicts (9 unique #130 commits)

git cherry -v origin/feat/dflash-spec-decode origin/feat/glm-5.2-fp8-support → 9 + commits:

SHA Verdict Why
707cc06 fp8 utils PARTIAL-KEEP Keep only dequant_fp8_state_dict + stack_expert_scales; dev owns dequant_fp8_blockwise (d797138).
038c149 register DROP dev already registers glmmoedsa (constants.py, hf_config.py).
98a5a39 block DROP (alt) dev owns SyncGlmMoeDsaMoEBlock (b02c3bd); #130's is a divergent alternative.
c8ae160 on-GPU dequant DROP (alt) Canonical = dev's dequant-on-copy (3167500+c16cb46, Option A==B parity).
b5a015a partition-read perf KEEP model_topology.cpp untouched by spec-decode; self-contained.
187048c offload wiring DROP (alt) Superseded by dev's 5b2c2b6.
9b49f43 tests+docs KEEP (reconcile) Unit suite is unique; README row/note + registry assertion already on dev.
3dc4e72 NVTX DROP (build-breaking as shipped) See deviation 3 — vendored header breaks the build; superseded by ba56518.
3444ed9 smoke e2e DROP (covered) dev's test_glm_smoke.py already has the MOE_GLM_SMOKE gate.

Divergence summary (spec-decode/dev vs #130)

Deviations from the plan (dev evolved past plan assumptions — all evidence-backed)

  1. Task 4.2 (README row/note + registry assertion) — SKIPPED, already on dev. README already has
    a GLM-5.2 table row + a more detailed note + a full usage section; test_model_registry.py lines
    29-30 already assert glmmoedsa. Re-adding would duplicate (violates the no-dup rule). README.md
    and test_model_registry.py left untouched.
  2. test_glm_routing_parity_vs_hf — GUARDED. It calls sync.route_tokens_to_experts(...) (feat(glm): support zai-org/GLM-5.2-FP8 (glm_moe_dsa) with FP8-in-store expert offload #130's
    block API); dev's canonical block has no such method (hasattr == False) and this env ships
    transformers.glm_moe_dsa, so verbatim would AttributeError. Added a hermetic class-level
    hasattr guard that skips cleanly (parity is already covered by
    test_glm_routing.py::test_routing_parity, which uses block._route).
  3. NVTX salvage (3dc4e72) — DROPPED with compile-probe evidence. The partially-vendored
    nvtx3.hpp (only nvtx3.hpp, not its #include "nvToolsExt.h" sibling) shadows the working
    system header (dev already puts core/include first on the include path) and fails to compile
    on this CUDA-13.1 host: P1 (vendored wins) → fatal error: nvToolsExt.h: No such file or directory;
    P2 (dev current) → OK. dev already solves CUDA≥12.9 NVTX header-only via ba56518 (does not link
    libnvToolsExt); feat(glm): support zai-org/GLM-5.2-FP8 (glm_moe_dsa) with FP8-in-store expert offload #130's setup.py hunk would reverse that and re-add fp4-kernel/CUDA-stub/
    python_requires>=3.8 regressions if blind-applied. Landed neither file. Reviewer options in the
    decision log.

Verification

  • Unit suite (required): test_glm_moe_dsa.py + test_model_registry.py15 passed, 2 skipped,
    0 failed
    (stable ×3). Skips: _store conftest-stubbed (cpp parity) and the routing-parity guard.
  • fp8 helpers: import GREEN; dequant_fp8_blockwise defined exactly once; ruff check+format clean.
  • model_topology.cpp: clean git apply --3way (no conflict markers); clang-format 0 violations;
    a faithful port of the already-compiled b5a015a. -fsyntax-only reached the file's own body with
    no syntax errors (only a pre-existing env torch/extension.h resolution issue). Full CUDA
    pip install -e . build deferred to CI (plan-sanctioned; _store is not built in this env).
  • LSP diagnostics: clean on fp8.py and test_glm_moe_dsa.py (no errors/warnings). clangd not
    installed here → C++ relied on clang-format + clean apply.
  • No-duplicate checks: one SyncGlmMoeDsaMoEBlock, one glm_moe_dsa module, one each of
    dequant_fp8_blockwise/dequant_fp8_state_dict/stack_expert_scales; all DROP-list files
    (glm_moe_dsa.py, model_offload.py, constants.py, hf_config.py, C++ parallel/+
    py_archer_prefetch.cpp, test_glm_smoke.py, setup.py, README.md, test_model_registry.py)
    unmodified vs origin/dev.

Known pre-existing issue (not introduced here)

tests/python/unit/test_glm_routing.py::test_routing_parity (dev-owned, byte-identical to origin/dev)
is a flaky test: it passes in isolation / the dev-only batch / the required suite, but under one
multi-file ordering it nondeterministically produces all-NaN routing (1 failed then 39 passed on
identical re-runs). Our guard is hermetic (skips before constructing any model), so this branch
contributes no RNG/side-effects — the flake is dev-side. Out of scope to fix here; recommend hardening
that test separately.

git diff --stat origin/dev...HEAD

 core/model/model_topology.cpp                                        | 112 +++++-----
 docs/superpowers/plans/2026-08-14-glm-5.2-reconciliation.decision-log.md | 246 +++++++++++
 moe_infinity/utils/fp8.py                                            |  62 ++++
 tests/python/unit/test_glm_moe_dsa.py                                | 228 +++++++++
 4 files changed, 591 insertions(+), 57 deletions(-)

drunkcoding added 7 commits August 15, 2026 09:58
Salvages #130's unit suite (the only coverage for the new dequant_fp8_state_dict + stack_expert_scales helpers). Two guards reconcile it to dev: skip test_glm_cpp_dequant_matches_python when moe_infinity._store is conftest-stubbed, and skip test_glm_routing_parity_vs_hf on dev's HF-delegating SyncGlmMoeDsaMoEBlock (parity already covered by test_glm_routing.py).
… on dev

Move the route_tokens_to_experts capability check ahead of model construction so the test skips cleanly on dev's HF-delegating block without touching global RNG. Also record in the decision log that dev already ships the GLM README row/note and the glmmoedsa registry assertion (Task 4.2), so neither is re-added.
@drunkcoding
drunkcoding marked this pull request as ready for review August 15, 2026 18:23
@drunkcoding
drunkcoding merged commit 088c72e into dev Aug 15, 2026
9 checks passed
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.

1 participant