feat(megamoe): expose fp4 weight preparation helper

Add a top-level MegaMoE helper that handles source/runtime FP4 weight granularity before applying the existing MegaMoE weight layout transform.

Use the helper from the synthetic MegaMoE benchmark so SGLang can later follow the same contract for GLM-5.2 NVFP4 group16 checkpoints.

Tested: PYTHONPYCACHEPREFIX=/private/tmp/deepgemm_pycache python3 -m py_compile deep_gemm/__init__.py deep_gemm/mega/__init__.py tests/test_mega_moe.py

Tested: git diff --check

Not-tested: CUDA build, SM100/B300 runtime, and GLM-5.2 accuracy validation are not available locally.
This commit is contained in:
LuminolT
2026-07-08 18:36:40 +08:00
parent 8ad348fb11
commit 2c7543130b
4 changed files with 33 additions and 7 deletions
@@ -18,6 +18,9 @@ carried an implicit group32 assumption.
- `requant_fp4_to_gran_k(...)` provides an explicit experiment path for
converting a group16 FP4 checkpoint tensor into a group32 tensor that the
existing block32 kernels can consume.
- `prepare_fp4_weights_for_mega_moe(...)` wraps the source/runtime granularity
decision for callers such as SGLang: source group16 can be requantized to
runtime group32 and then passed through the normal MegaMoE weight transform.
- The fused SM100 MegaMoE compute API now performs an explicit capability check
for `recipe=(1, 1, 16)` instead of failing earlier with
`Unknown SF transformation`.