Repository navigation
Conversation
…ken embedding GQADSparkForCausalLM takes the target's embedding in load_weights_from_target_model, so the DFlash worker built every masked block slot from the target's row for the mask token, which the target never trained. A drafter checkpoint that ships its own embedding has trained that row. load_weights now keeps it as mask_token_embedding, and the worker's noise block (dflash_noise_block_embedding, the same computation moved into a function) uses it for every masked slot when the drafter has one for the mask id in use; slot 0 stays the bonus token's shared lookup. Every rank still embeds the mask id through embed_tokens.forward, as before. Drafts change; under greedy verification the target's tokens do not. Plain DFlash and MLA DSpark drafters set no mask_token_embedding and are unchanged. Signed-off-by: Vasanth Sabavat <[email protected]>
longlee0622
left a comment
There was a problem hiding this comment.
Thanks for the clear write-up and the E2E numbers. The diagnosis is convincing, and the change is safe: the shared embed_tokens.forward call is kept, so TP collectives stay symmetric. A few points before merge:
-
Why keep only the mask row instead of the drafter's whole embedding?
MLADSparkForCausalLMsetsWEIGHTS_SHARED_WITH_TARGET = ("lm_head",)and keeps its ownembed_tokens, because its values differ from the target's. The K3 GQA drafter also ships a full[163840, 7168]embedding. If any rows besides the mask token also differ from the target's, then slot 0 (the bonus token) still gets the target's row, which is the same train/inference mismatch, and there may be more acceptance to gain. Could you check whether the drafter's embedding is bit-exact with the target's outside the mask row?- If it is not, I'd suggest following the MLA approach: don't share
embed_tokenswhen the checkpoint ships one. That keeps one rule for both DSpark flavours instead of adding a third "share all but one row" behaviour. It also removes the special case in the worker. The cost is about 147 MB per rank at TP16. - If it is, a short comment saying so would help the next reader understand why only the mask row is kept.
- If it is not, I'd suggest following the MLA approach: don't share
-
Validate the row at load time.
weight[self.mask_token_id : self.mask_token_id + 1].reshape(-1)doesn't check thatmask_token_id < weight.shape[0]or that the row width equalshidden_size. An out-of-range id gives an empty tensor, and the failure only shows up later as an unclearexpanderror in the worker. An explicit check in_keep_trained_mask_embeddingwould make this fail early with a clear message. -
Minor:
.to("cuda")relies on the current device being set correctly. Using the drafter's own parameter device (e.g.self.fc.weight.device) would be more robust.trained_mask_embedding.to(embed_mask.dtype)runs on every step. Casting once at load time to the model dtype avoids that.
-
Related to 1 (pre-existing, not introduced here): when the checkpoint ships
embed_tokens.weight, the full embedding is first loaded into the drafter inDFlashForCausalLM.load_weightsand then thrown away byload_weights_from_target_model. Going the MLA route would fix this as well.
…ast it once Follow-ups on the trained mask-token row this branch keeps: - The row is checked at load, before any weight is copied: the shipped embedding must be [rows, hidden_size], and the drafter's mask_token_id must be one of its rows. A ValueError names the problem. Before, an id past the rows kept an empty row, which failed later in the worker's noise block. - The row is cast to the drafter's dtype and placed on the device of the drafter's own fc weight once, at load. The noise block uses it as given, with no per-step cast and no reliance on the current CUDA device. - The docstring says why only the mask row is kept: in the Kimi K3 drafter (RedHatAI/Kimi-K3-speculator.dspark) it is the only one of the 163,840 embedding rows that differs from the target's, and the shipped lm_head is bit-exact with the target's. Tests: test_gqa_dspark_mask_row_takes_the_drafter_dtype_and_device_at_load and test_gqa_dspark_rejects_a_mask_row_the_shipped_embedding_does_not_have (out-of-range, negative and wrong-width cases). Signed-off-by: Vasanth Sabavat <[email protected]>
… mask id eda9db2 raised for any mask id outside the shipped embedding, including DFlash's default (vocab_size). The drafter takes that default when its config names no mask token in a key it reads. The speculative config can still name the mask token then (a user value, or a key only it reads, such as dspark_noise_token_id), and such a drafter loaded before. It now keeps no row, as a checkpoint without an embedding does. Any other id outside the shipped rows still raises. Test: test_gqa_dspark_keeps_no_mask_row_when_its_config_names_no_mask_token. The out-of-range case of the rejection test now uses vocab_size + 1. Signed-off-by: Vasanth Sabavat <[email protected]>
|
Thanks for the review. Points 1-3 are addressed in eda9db2 and 0cbb559; point 4 is answered below.
Validation of 0cbb559:
|
|
Thanks for the updates and the bitwise comparison. Points 1-4 look resolved to me. One remaining concern, about the default-id branch you added in A GQA DSpark checkpoint that names its mask token only as Here is how the two sides pick the mask id:
So for such a checkpoint:
There is no error and no log message. Only the acceptance drops. The K3 RedHatAI checkpoint isn't affected, since its config names a key the drafter reads, but the next DSpark checkpoint could hit this. The row we should keep is actually known at load time: it's the id the worker will use. Could |
…mask id The worker embeds the speculative config's mask id when it has one, and that config also reads a checkpoint key the drafter's own config resolution does not: dspark_noise_token_id. For a checkpoint that names its mask token only that way, the drafter fell back to DFlash's default id (vocab_size) and kept no trained row. The worker's id check then failed, so every masked slot silently got the target's row again. The drafter's own ModelConfig carries no spec_config, so _build_dspark_draft now hands the speculative config's mask id to GQADSparkForCausalLM, which adopts it. The drafter keeps the row of the id the worker uses, and the worker's check matches. MLA DSpark keeps its own embedding and is unchanged. When a shipped embedding still keeps no row (no config names a mask token), the drafter logs a warning. Tests: test_gqa_dspark_keeps_the_trained_row_of_the_speculative_configs_mask_id and test_gqa_dspark_warns_when_its_shipped_embedding_keeps_no_mask_row. Signed-off-by: Vasanth Sabavat <[email protected]>
|
Thanks, good catch. Confirmed and fixed in b83f960, following your first option.
|
|
Superseded by the consolidated draft PR: #19988. Source commits and follow-ups are retained; prior reviews remain historical evidence, not approval of the replacement heads. |
Description
What goes wrong. A GQA DSpark drafter (
GQADSparkForCausalLM) shares the target's embedding and LM head:DFlashForCausalLM.load_weights_from_target_model(tensorrt_llm/_torch/models/modeling_dflash.py:1000-1004)replaces the drafter's
embed_tokenswith the target's, andGQADSparkForCausalLM(
tensorrt_llm/_torch/models/modeling_dspark.py:2646,load_weightsat :2673) inherits that and keeps nothing ofits own. The DFlash worker then builds every masked slot of the drafter's input block from that shared embedding:
DFlashWorker.prepare_1st_drafter_inputs(tensorrt_llm/_torch/speculative/dflash.py:1950, :2001-2004) embeds themask token id through
embed_tokensand copies that row into slots 1..K.A DSpark drafter checkpoint can ship its own embedding with a trained row for its mask token. The Kimi K3 DSpark
drafter (
RedHatAI/Kimi-K3-speculator.dspark) does:embed_tokens.weight[163840, 7168] bf16, mask token id163837. That row is what the drafter was trained on. With the target's row instead, the drafts degrade: on Kimi K3
(MXFP4), 16 GB200, max_draft_len 7, the acceptance (
avg_decoded_tokens_per_iter) on a set of fixed prompts is 2.45 wherethe trained row gives 3.40. Outputs are unaffected: greedy verification still decides every token.
Fix.
GQADSparkForCausalLM.load_weightskeeps the checkpoint's row for the mask token asmask_token_embeddingwhen thecheckpoint ships
embed_tokens.weight(ormodel.embed_tokens.weight).dflash_noise_block_embedding(the same computation, moved into a function).It uses
mask_token_embeddingfor every masked slot when the drafter has one for the mask id in use; slot 0 staysthe bonus token's row from the shared lookup. The lookup itself (
embed_tokens.forwardon the bonus tokens and themask id) is unchanged, so every rank still makes the same TP-sharded embedding call.
Blast radius. Only GQA DSpark drafters whose checkpoint ships an embedding, and the DFlash worker's noise block
for generation requests:
embedding already) set no
mask_token_embedding, so the worker builds the same block as before;mask_token_idoverride in the speculative config that differs from the drafter's keeps the shared lookup;Drafts change, and with them the acceptance; under greedy verification the generated tokens do not.
Test Coverage
tests/unittest/_torch/speculative/hw_agnostic/test_kimi_k3_dspark_semantics.py::test_gqa_dspark_keeps_its_trained_mask_row_over_the_target_embedding(GPU): a tiny GQA DSpark drafter whose checkpoint ships an embedding, given a target embedding with a different mask
row. After
load_weights_from_target_model, the drafter'smask_token_embeddingequals the checkpoint's row, anddflash_noise_block_embeddingreturns the bonus token's shared row in slot 0 and the trained row in every otherslot.
Results on GB200, main's own build:
AttributeError: 'GQADSparkForCausalLM' object has no attribute 'mask_token_embedding';test_kimi_k3_dspark_semantics.pyandtest_dflash_worker.py,test_dspark_worker.py,test_dspark_draft.py,test_dflash.py,test_dspark_cuda_graph.py: the same results on main and with this PR(no new failure).
End to end, Kimi K3 (MXFP4) with its DSpark drafter on 16 GB200 (TP16), max_draft_len 7, batch 8, CUDA graphs, main
and main with this PR:
(
avg_decoded_tokens_per_iter, weighted by tokens) goes from 2.45 to 3.40 (per-prompt mean 2.58 to 3.80);error). The verify steps fall from 55,076 to 32,196, so the acceptance rises from about 2.5 to 4.3 tokens per
step (137,404 generated tokens, from a run without speculation);
(-26 %) and the output throughput rises from 588 to 759 tokens/s (+29 %).
k3rest (#19841) carries the same commit (cherry-pick, same patch-id) so its DSpark acceptance is right; it drops out of k3rest when this PR merges.
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title. (No API change.)Any new dependencies have been scanned for license and vulnerabilities (No new dependencies.)
CODEOWNERS updated if ownership changes (No ownership change.)
Documentation updated as needed (No documentation change.)
Update tava architecture diagram if there is a significant design change in PR. (No design change.)
The reviewers assigned automatically/manually are appropriate for the PR. (To check once the PR is open.)
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.