Skip to content

factory: keep the BF16 lm_head while an MTP drafter holds it (fixes #264: Flash-Next + NVFP4 head + MTP faulted on the first request) - #272

Merged
AzeezIsh merged 1 commit into
mainfrom
fix/q4e-mtp-head-use-after-free
Oct 30, 2026
Merged

AzeezIsh merged 1 commit into
mainfrom
fix/q4e-mtp-head-use-after-free

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

Fixes #264.

Bug. factory/build.rs copies the BF16 head into q4e_mtp_lm_head = lm_head (and v4_mtp_lm_head for DeepSeek-V4) early in the build. Later, when an NVFP4 head exists, bf16_lm_head_is_dead frees that same buffer. The Qwen3.8-Flash-Next drafter keeps the stale pointer, and its first vocab projection (grid 25000 = --mtp-vocab 100000 / 4 rows per block) reads freed memory: hipErrorIllegalAddress on the first request under the serve-amd.sh defaults (LM_HEAD=nvfp4, MTP K=4).

Fix. Skip the free while either drafter is loaded. Cost: vocab × hidden × 2 B ≈ 1.27 GB on Flash-Next.

Verified on framework (desktop Strix Halo, gfx1151), f106, the exact serve-amd.sh default that faulted before (f97/f98/f101/f105):

  • NVFP4 head + MTP: all four probes answer coherently, 0 illegal / 0 errors, 256-token decode 22.8 tok/s (1.98 tokens/step);
  • LM_HEAD=fp8 control: 22.6 tok/s, 0 faults.

The bisect that led here is on #264. It ruled out the padded transposed twin (ATLAS_NO_LMHEAD_TGEMM=1 still faulted) and showed that fp8/bf16 heads and NUM_DRAFTS=0 never reach the freed buffer.

🤖 Generated with Claude Code

)

Qwen3.8-Flash-Next served with --lm-head-dtype nvfp4 and MTP (the
serve-amd.sh default) hit an illegal address on its first propose: a
launch with grid [25000,1,1], which is the draft vocab projection over
--mtp-vocab 100000 (#264).

build.rs copies the BF16 head into q4e_mtp_lm_head (and v4_mtp_lm_head
for DeepSeek-V4) early on. Later, when an NVFP4 head exists, it frees the
same buffer as dead weight. The drafter kept the stale pointer.

That explains every bisect arm (framework f98/f101/f105):
- the fp8 and bf16 heads never reach the free;
- NUM_DRAFTS=0 never reads the head;
- the padded transposed twin is unrelated (ATLAS_NO_LMHEAD_TGEMM=1 still
  faulted).

The free now skips when either drafter was loaded. That costs
vocab x hidden x 2 B of memory, which is ~1.27 GB on Flash-Next.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

gfx1151: Flash-Next NVFP4 + MTP + --lm-head-dtype nvfp4 (serve-amd.sh default) -> illegal address on the first request

1 participant