Generators: FP8 emission + expert unfusing + download tool#244
Closed
woolcoxm wants to merge 3 commits into
Closed
Generators: FP8 emission + expert unfusing + download tool#244woolcoxm wants to merge 3 commits into
woolcoxm wants to merge 3 commits into
Conversation
Both test-model generators (make_glm_oracle.py, make_glm_bench_model.py) can now emit weights as FP8 e4m3 + 128x128 block scale_inv, in the same layout as the real GLM-5.2-FP8 checkpoint. This lets convert_fp8_to_int4.py exercise its FP8->int4 dequant path on a local fixture without the 379 GB download. - New shared helper glm_fp8_emit.py: FP8 block quantize/dequantize (FBGEMM/TE scale=amax/448 convention) + state_dict emitter. Only exactly-2-D tensors are quantized; 1-D/3-D and norms/router/e_score_correction_bias are kept as f32, mirroring the converter's classify() + ndim!=2 guard. - make_glm_bench_model.py: opt-in --fp8 writes model.safetensors in FP8 layout (config.json written explicitly since the FP8 path bypasses save_pretrained); manifest gains a 'format' field. Default bf16 behavior unchanged. - make_glm_oracle.py: opt-in --fp8 round-trips quantizable weights through FP8 before computing ref_glm.json, so the reference reflects exactly the FP8 model the converter ingests. Default bf16 oracle contract unchanged. Verified end-to-end: FP8 model -> converter --indir -> int4 U8 + .qs F32 output, bit-identical dequant between helper and converter (maxdiff 0.0).
β¦ download tool Consolidates all experiment branches into one Windows-dev branch: 1. Group-scaled int4 (fmt=4, gs=128) β glm.c - QT struct: added gs field - matmul_i4_grouped: AVX2 kernel, verified to 3e-08 vs f32 - Format detection: auto-detects from .qs scale array size - expert_load: both mmap and slab+pread paths handle fmt=4 - qt_bytes: fmt=4 case added 2. Per-tensor-type mixed precision β convert_fp8_to_int4.py - Split classify() into sh/o/kvb/attn/dmlp sub-types - New args: --shared-bits, --o-bits, --kvb-bits, --attn-bits, --dmlp-bits - Plan: shared expert + o_proj + kv_b_proj at int8, rest grouped int4 - Only +5.3 GB RAM vs +0 for pure int4 3. EXPERT_BUDGET (miss-aware) β glm.c - Caps distinct experts per layer across batch-union - Always keeps cache hits, only drops misses - Up to 1.8x faster decode on low-RAM hosts 4. Two-step shared-expert prediction (PILOT_TWO) β glm.c - la_predict kind==2 + pilot_prefetch integration - +3.1% recall over baseline PILOT 5. FP8 download tool β download_fp8.py - ModelScope + HuggingFace dual-source - Parallel shard download with stall recovery 6. Tiny model generation β make_glm_oracle.py - Generated and tested locally for pipeline validation
woolcoxm
force-pushed
the
feat/generators-fp8-unfuse
branch
from
July 15, 2026 06:29
4f2b9b6 to
8513b6c
Compare
This was referenced Jul 16, 2026
Owner
|
Closing β like #243, this is already on I checked each file rather than guessing:
Zero unique content left. The Also closing #238 (FP8 emission + unfusing) and #239 (dual-source download tool) β I verified Nothing lost here except the bookkeeping. |
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
Three changes to the test-model generators:
gate_up_projinto the per-expert 2-D layout the real checkpoint, converter, and C engine all expect. Fixes a silent data-loss bug.download_fp8.pywith ModelScope+HF dual-source, parallel shards, resume.Closes #238, closes #239.
Problem 1: No local FP8 fixture
The converter's FP8βint4 dequant path could only be exercised by downloading the 379 GB checkpoint. There was no way to test it locally, meaning dequant bugs would only surface during the multi-hour production conversion.
Fix: New
glm_fp8_emit.pyhelper withfp8_block_quantize/fp8_block_dequantize/save_fp8_safetensors. Both generators gained--fp8flag. The oracle round-trips weights through FP8 before computing the reference.Problem 2: Fused expert weights (bug)
HF's
GlmMoeDsaForCausalLMfusesgate_proj+up_projinto a 3-Dgate_up_proj [E, 2M, I]. But the real checkpoint stores experts unfused as per-expert 2-D tensors:The converter's
ndim != 2guard silently skipped the 3-D fused tensors. The engine then crashed withmissing tensor: model.layers.3.mlp.experts.5.gate_proj.weight.Fix:
unfuse_experts()inglm_fp8_emit.pysplitsgate_up_proj [E, 2M, I]β per-expertgate_proj [M, I]+up_proj [M, I], anddown_proj [E, I, M]β per-expertdown_proj. Called after reference generation but before saving, in both generators.Also fixed:
make_glm_oracle.pyFP8 round-trip guardp.dim() < 2βp.dim() != 2(3-D fused experts crashedfp8_block_quantize).Problem 3: Download tool
The 379 GB FP8 download is the pipeline bottleneck. HuggingFace per-stream throttling drops throughput after ~50 GB.
download_fp8.pytries ModelScope first (no throttling), falls back to HF, with parallel shards + resume.Changes
c/tools/glm_fp8_emit.pyunfuse_experts,save_fp8_safetensorsc/tools/make_glm_oracle.py--fp8flag, FP8 round-trip, unfuse, dim guard fixc/tools/make_glm_bench_model.py--fp8flag, unfuse, manual config.json in FP8 pathc/download_fp8.pyValidation
Test plan
--fp8produces valid FP8 checkpoint with per-expert 2-D tensors