[LLM:Feature] DFlash draft shares target's lm_head (no separate lm_head) - #4762
Merged
Conversation
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
|
|
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.
Automated sync from the internal MNN development repository.
sync/ali-to-githubCommits
7372d39b9c[LLM:Feature] DFlash draft shares target's lm_head (no separate lm_head) — 花熊 zhanghuaxiang.zhx@taobao.com