Skip to content

spark-model: skip Phase G lm_head FP8 quantize when the shared head is NVFP4-packed - #43

Closed
AzeezIsh wants to merge 1 commit into
mainfrom
fix/dflash-fp8-lmhead-nvfp4-main
Closed

AzeezIsh wants to merge 1 commit into
mainfrom
fix/dflash-fp8-lmhead-nvfp4-main

Conversation

@AzeezIsh

@AzeezIsh AzeezIsh commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cherry-pick of f977c9af0 (written 2026-09-18 on the DFlash2 line, validated on AzeezStrix gfx1151) onto current main; applied cleanly over #37/#38.

On NVFP4-packed checkpoints the shared lm_head DenseWeight pointer addresses PACKED bytes (nvidia/Qwen3.8-27B-NVFP4 ships lm_head.weight as U8 [248320, 2560], ~636 MB — not ~2.5 GB of BF16). The decode path already guards this (drafter logits via the NVFP4 twin through w4a16). DFlash Phase G (ATLAS_DFLASH_DRAFTER_FP8=1) missed the guard in two places:

  1. from_weights.rs quantized lm_head_shared as BF16 unconditionally → deterministic hipErrorIllegalAddress at load on gfx1151 (90+ gfxhub page faults) after all 35 per-layer quantizes succeeded.
  2. The fp8 decode branches in batch_forward.rs / forward_block.rs fell back to dense_gemm_bf16_pipelined on lm_head_shared when the FP8 mirror was absent — the same 4×-oversized read, deferred to first decode.

Fix mirrors the existing non-fp8 dispatch: skip the lm_head quantize when lm_head_nvfp4 is Some, and collapse the fp8 branch into the shared dispatch so a missing FP8 mirror drafts logits through the NVFP4 twin exactly like the BF16 path. Checkpoints whose lm_head is genuinely BF16 are unchanged.

Validated (original commit, AzeezStrix): ATLAS_DFLASH_DRAFTER_FP8=1 boots clean — Phase G logs "drafter weights ready as FP8" with the lm_head quantize skipped — and a probe request drafted via the nvfp4 fallback (mean_na=2.583, p1=0.917, coherent). Not re-run on the box after the cherry-pick (the diff applied without conflicts).

Test plan

  • cargo fmt --all -- --check; ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy -p spark-model --tests clean on the pinned 1.93.1 toolchain
  • cargo test -p spark-model dflash on a CUDA/stub host (the Mac cannot link libcuda)
  • exercise the FP8 drafter arm on GB10 (on main's strix-hip target the arm is unreachable: fp8_gemm_t_row_scaled(_m16) are not in that w4a16 module — see comment)

Generated with Devin

…s NVFP4-packed

On NVFP4-packed checkpoints the shared lm_head DenseWeight pointer
addresses PACKED bytes (e.g. nvidia/Qwen3.8-27B-NVFP4 ships lm_head.weight
as U8 [248320, 2560] — ~636 MB, not ~2.5 GB of BF16). The decode path
already guards this: the drafter's logits GEMM routes through the NVFP4
twin via w4a16, with a comment naming the exact failure — a BF16 GEMM on
packed bytes reads 4x the buffer and faults (CUDA-700 ILA).

Phase G missed that guard in two places:

1. from_weights.rs quantized lm_head_shared as BF16 unconditionally.
   With ATLAS_DFLASH_DRAFTER_FP8=1 the load crashed deterministically on
   gfx1151 — 90+ gfxhub page faults, hipErrorIllegalAddress — after all
   35 per-layer quantizes succeeded, at the lm_head launch.
2. The fp8 decode branches in batch_forward.rs and forward_block.rs fell
   back to dense_gemm_bf16_pipelined on lm_head_shared when the FP8
   mirror was absent — the same OOB read, deferred to first decode.

Fix mirrors the existing non-fp8 dispatch: skip the lm_head quantize
when lm_head_nvfp4 is Some (the packed-twin signal), and collapse the
fp8 branch into the shared dispatch — when no FP8 mirror exists the head
drafts logits through the NVFP4 twin exactly like the BF16 path. On
checkpoints whose lm_head is genuinely BF16 (no nvfp4 twin) the quantize
and the fp8 row-scaled path are unchanged.

Validated on AzeezStrix gfx1151: ATLAS_DFLASH_DRAFTER_FP8=1 now boots
clean — Phase G logs "drafter weights ready as FP8" with the lm_head
quantize skipped — and a probe request drafted via the nvfp4 fallback
(mean_na=2.583, p1=0.917, coherent output). cargo fmt clean.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Box re-run on AzeezStrix (gfx1151, ROCm 10, main + this cherry-pick @ b1f532707, binary ed694779…, ~/dp4a-ab/out/pr43-verify-20260920T0532Z/): the FP8 drafter arm is unreachable on main's strix-hip target, so this change is not exercised there —

WARN dflash_head::from_weights: ATLAS_DFLASH_DRAFTER_FP8=1 but fp8_gemm_t_row_scaled(_m16) kernels are not in this target's w4a16 PTX module — staying on the BF16 draft

The 2026-09-18 validation cited in the description ran on a branch whose strix-hip w4a16 module carried those row-scaled kernels (fix/strix-hip-dflash-fp8-rowscl); main does not. Both probes therefore ran the BF16 drafter and are byte-identical (2036 chars), each Done: 512 tokens (length) 14.3–14.4 tok/s, mean_na=5.241 tok_step=6.241, zero fault lines — a null result for this PR, not a pass. The code path can be exercised on GB10 (the kernels exist there) or on strix-hip once the row-scaled FP8 kernels land; test plan updated accordingly. The fix itself remains the right guard (a BF16 GEMM over NVFP4-packed lm_head bytes reads 4× the buffer) and is unreachable-by-construction on checkpoints whose lm_head is genuinely BF16.

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Folded into the Linux follow-ups PR (port/qwen38-strix-linux-followups) — cherry-picked as a238405.

@AzeezIsh AzeezIsh closed this Sep 21, 2026
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