Skip to content

[LLM:Feature] DFlash draft shares target's lm_head (no separate lm_head) - #4762

Merged
wangzhaode merged 1 commit into
masterfrom
sync/ali-to-github
Aug 12, 2026
Merged

[LLM:Feature] DFlash draft shares target's lm_head (no separate lm_head)#4762
wangzhaode merged 1 commit into
masterfrom
sync/ali-to-github

Conversation

@wangzhaode

Copy link
Copy Markdown
Collaborator

Automated sync from the internal MNN development repository.

  • Pending commits: 1
  • Head branch: sync/ali-to-github
  • Commit authors are preserved from the source commits.

Commits

The DFlash draft's lm_head is identical to the target's (tie_word_embeddings),
but was baked into dflash.mnn, duplicating the vocab x hidden weights on disk
and in memory (~219 MB for Qwen3-4B int4).

Export: DFlash.forward now outputs post-final-norm hidden_states instead of
logits, so dflash.mnn contains no lm_head. The separate dflash_lmhead.mnn
export path (--dflash_export_separate_lmhead) is removed: the shared
subgraph already covers its use case -- mixed precision (fp16 transformer +
int4 lm_head) -- via the target's own lm_head.

Engine: DFlash load() requires dflash_shared_lmhead_input and loads the
subgraph {input -> logits} from llm.mnn with Module::Config{base=target,
rearrange=true}. The embedded-lmhead and separate-lmhead fallbacks are gone:
a draft without the config field is refused at load time with a re-export
hint. Refusal is enforced through Generation::load(), which now returns
bool; on failure of any module the draft step dereferences (draft graph,
lm_head, fc) Llm::load() aborts and status stays NOT_LOADED, so every
inference entry is fenced by CHECK_LLM_RUNNING instead of reaching a null
module.

Verify (M5 iPad, 2B int4 b8 greedy): acceptance 4.59 -> 4.63, indistinguishable
from the separate-lm_head baseline (difference < 0.04 across 9 prompts).

Discussed-in: Merge-Request 28763320 , URL: https://code.alibaba-inc.com/AliNN/AliNNPrivate/codereview/28763320
GitOrigin-RevId: 318842e009b5067f67b1b5aa53b35c44df23536c
@wangzhaode
wangzhaode merged commit bc85588 into master Aug 12, 2026
8 checks passed
@wangzhaode
wangzhaode deleted the sync/ali-to-github branch August 12, 2026 07:54
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

3 participants