StepFun 3.5 MTP
Overview
MTP implementation for StepFun 3.5.
Additional information
Required a few changes to the core logic because StepFun uses a slightly different MTP architecture - it has 3 MTP layers which are used in a round-robin manner for tokens n+1, n+2 and n+3 respectively.
I'm running a suboptimal setup for testing this, but FWIW testing this on a --cpu-moe StepFun3.5 increased token generation from 15 to 18 t/s.
Requirements
- I have read and agree with the contributing guidelines
- AI usage disclosure: Yes, asked CC to mix this per vLLM implementation and Qwen3.5 reference, tested on live Step3.5 model.
Converting to draft while I try something out.
@ggerganov just FYI because it's related to the cleanup - I modified the TODO-annotated line with top-k - for multi-layer MTP it's a real blocker, the acceptance rate goes up from 0.6 to 0.9 on n = 3 when switching from top-k = 1 to top-k = 10.
Hey, thanks a lot for adding step3.5 support, great work. But One thing I wanted to flag: in process() only call llama_decode once with mtp_step=0, so only mtp1's KV gets the prefill/verify context, mtp2 and mtp3 never see it and end up attending over empty KV during drafting. The correct flow should be
Sigh. Back to draft, let's see if I can do anything about that.
@pwilkin The fill in llm_graph_input_mtp_chain_tokens::set_input writes contaminated KV entries, and the pad share is especially bad on the all-accept verify path. Nothing cleans them up afterwards, so they pile up across rounds. And block 0's last-position input should be the token target we just sampled, not a reuse of ubatch->token[n_tokens-1].
I think this needs two changes together. process() currently runs before the target sampler, so target new isn't visible to the chain graph. If we move the sampler call before process(), we can thread new token into llm_graph_input_mtp_chain_tokens. I haven't traced why the ordering is the way it is, so tell me if there's a constraint I'm missing.
And even with T_new threaded in, block k+1's tail still has k slots that no real token can fill. Those have to come from the previous block's chain sample, same as what the DRAFT branch already does. So for block k+1 in PREFILL: chain-sampled tokens from block k at the tail (last shift = k slots), ubatch-shifted tokens for the rest.
If the analysis holds up, I can put a PR on your step35mtp branch. Or take it yourself if you'd rather — no preference on my end, just let me know.
@forforever73 yeah, I see the problem. I've revised the goals for this PR - since doing proper multi-step MTP will require more significant changes, I'll stick to the simple version, which is to only use the first layer similarly to the Qwen3.5 MTP code and save the proper architecture for a future PR (so you're free to propose one).
All right, here are the benchmark stats for the single-layer version (only small changes to the iSWA cache code left from core stuff):
Non-MTP (llama-server -m stepfun/IQ4_XS/Step-3.5-Flash-IQ4_XS-00001-of-00004.gguf -c 140000 -ctk q8_0 -ctv q8_0 --cpu-moe):
code_python pred= 192 draft= 0 acc= 0 rate=n/a tok/s=14.2
code_cpp pred= 192 draft= 0 acc= 0 rate=n/a tok/s=14.4
explain_concept pred= 192 draft= 0 acc= 0 rate=n/a tok/s=14.4
summarize pred= 192 draft= 0 acc= 0 rate=n/a tok/s=14.5
qa_factual pred= 192 draft= 0 acc= 0 rate=n/a tok/s=14.3
translation pred= 192 draft= 0 acc= 0 rate=n/a tok/s=14.6
creative_short pred= 192 draft= 0 acc= 0 rate=n/a tok/s=14.1
stepwise_math pred= 192 draft= 0 acc= 0 rate=n/a tok/s=14.1
long_code_review pred= 192 draft= 0 acc= 0 rate=n/a tok/s=14.2
Aggregate: {
"n_requests": 9,
"total_predicted": 1728,
"total_draft": 0,
"total_draft_accepted": 0,
"aggregate_accept_rate": null,
"wall_s_total": 144.35
}
MTP (llama-server -m stepfun/IQ4_XS/Step-3.5-Flash-IQ4_XS-00001-of-00004.gguf -c 140000 -ctk q8_0 -ctv q8_0 --spec-type draft-mtp --spec-draft-n-max 3 -md stepfun-mtp.gguf --cpu-moe --spec-draft-p-min 0.65)
code_python pred= 192 draft= 123 acc= 105 rate=0.854 tok/s=18.2
code_cpp pred= 192 draft= 108 acc= 92 rate=0.852 tok/s=17.1
explain_concept pred= 192 draft= 102 acc= 84 rate=0.824 tok/s=16.1
summarize pred= 186 draft= 117 acc= 97 rate=0.829 tok/s=16.7
qa_factual pred= 192 draft= 131 acc= 111 rate=0.847 tok/s=18.3
translation pred= 192 draft= 116 acc= 93 rate=0.802 tok/s=16.9
creative_short pred= 192 draft= 95 acc= 85 rate=0.895 tok/s=16.6
stepwise_math pred= 192 draft= 121 acc= 112 rate=0.926 tok/s=19.0
long_code_review pred= 192 draft= 116 acc= 100 rate=0.862 tok/s=17.0
Aggregate: {
"n_requests": 9,
"total_predicted": 1722,
"total_draft": 1029,
"total_draft_accepted": 879,
"aggregate_accept_rate": 0.8542,
"wall_s_total": 123.49
}
I'd argue it's good enough.
4xMI50 32GB, 2xMI50 16GB
apohelios/step3p5_flash_Q4_1-00001-of-00005.gguf draft size 1 (higher crushes performance)
Non-MTP
code_python pred= 192 draft= 0 acc= 0 rate=n/a tok/s=40.4
code_cpp pred= 192 draft= 0 acc= 0 rate=n/a tok/s=40.4
explain_concept pred= 192 draft= 0 acc= 0 rate=n/a tok/s=40.2
summarize pred= 192 draft= 0 acc= 0 rate=n/a tok/s=40.2
qa_factual pred= 192 draft= 0 acc= 0 rate=n/a tok/s=40.2
translation pred= 192 draft= 0 acc= 0 rate=n/a tok/s=40.2
creative_short pred= 192 draft= 0 acc= 0 rate=n/a tok/s=40.6
stepwise_math pred= 192 draft= 0 acc= 0 rate=n/a tok/s=41.0
long_code_review pred= 192 draft= 0 acc= 0 rate=n/a tok/s=39.4
Aggregate: {
"n_requests": 9,
"total_predicted": 1728,
"total_draft": 0,
"total_draft_accepted": 0,
"aggregate_accept_rate": null,
"wall_s_total": 47.19
}
MTP
code_python pred= 192 draft= 89 acc= 84 rate=0.944 tok/s=52.3
code_cpp pred= 192 draft= 83 acc= 77 rate=0.928 tok/s=50.3
explain_concept pred= 192 draft= 80 acc= 69 rate=0.863 tok/s=47.8
summarize pred= 192 draft= 88 acc= 78 rate=0.886 tok/s=50.8
qa_factual pred= 192 draft= 86 acc= 83 rate=0.965 tok/s=53.1
translation pred= 182 draft= 87 acc= 81 rate=0.931 tok/s=53.8
creative_short pred= 192 draft= 76 acc= 63 rate=0.829 tok/s=46.1
stepwise_math pred= 192 draft= 86 acc= 79 rate=0.919 tok/s=51.3
long_code_review pred= 192 draft= 79 acc= 74 rate=0.937 tok/s=47.7
Aggregate: {
"n_requests": 9,
"total_predicted": 1718,
"total_draft": 754,
"total_draft_accepted": 688,
"aggregate_accept_rate": 0.9125,
"wall_s_total": 39.54
}
MTP from #20981
code_python pred= 192 draft= 104 acc= 87 rate=0.837 tok/s=54.2
code_cpp pred= 192 draft= 107 acc= 83 rate=0.776 tok/s=52.4
explain_concept pred= 192 draft= 115 acc= 76 rate=0.661 tok/s=49.3
summarize pred= 192 draft= 106 acc= 84 rate=0.792 tok/s=52.9
qa_factual pred= 192 draft= 100 acc= 90 rate=0.900 tok/s=56.3
translation pred= 192 draft= 105 acc= 85 rate=0.809 tok/s=54.2
creative_short pred= 183 draft= 111 acc= 71 rate=0.640 tok/s=49.4
stepwise_math pred= 192 draft= 104 acc= 87 rate=0.837 tok/s=55.3
long_code_review pred= 192 draft= 102 acc= 88 rate=0.863 tok/s=51.9
Aggregate: {
"n_requests": 9,
"total_predicted": 1719,
"total_draft": 954,
"total_draft_accepted": 751,
"aggregate_accept_rate": 0.7872,
"wall_s_total": 39.17
}
@pwilkin Is the stepfun-mtp.gguf from your cmd publicly available?
@toastytorque yeah, convert_hf_to_gguf.py --remote --outfile stepfun-mtp.gguf --outtype q8_0 --mtp stepfun-ai/Step-3.5-Flash :)
Also, try --spec-draft-p-min 0.65 with n=3, without p-min the performance above 1 token was indeed atrocious, but that helped a lot.
Tests above were indeed with --spec-draft-p-min 0.65.
With n=3 the performance is still lacking, might be a MI50 thing:
code_python pred= 192 draft= 128 acc= 102 rate=0.797 tok/s=43.1
code_cpp pred= 192 draft= 110 acc= 92 rate=0.836 tok/s=43.8
explain_concept pred= 192 draft= 89 acc= 73 rate=0.820 tok/s=42.6
summarize pred= 187 draft= 103 acc= 88 rate=0.854 tok/s=43.5
qa_factual pred= 192 draft= 127 acc= 104 rate=0.819 tok/s=43.4
translation pred= 192 draft= 117 acc= 99 rate=0.846 tok/s=44.3
creative_short pred= 155 draft= 77 acc= 54 rate=0.701 tok/s=39.2
stepwise_math pred= 192 draft= 127 acc= 105 rate=0.827 tok/s=43.9
long_code_review pred= 192 draft= 108 acc= 87 rate=0.806 tok/s=40.8
Aggregate: {
"n_requests": 9,
"total_predicted": 1686,
"total_draft": 986,
"total_draft_accepted": 804,
"aggregate_accept_rate": 0.8154,
"wall_s_total": 44.65
}
It seems I get best results with p-min default (0.0) and n=1:
code_python pred= 192 draft= 100 acc= 90 rate=0.900 tok/s=56.0
code_cpp pred= 192 draft= 103 acc= 87 rate=0.845 tok/s=54.4
explain_concept pred= 192 draft= 111 acc= 80 rate=0.721 tok/s=50.6
summarize pred= 192 draft= 106 acc= 84 rate=0.792 tok/s=52.6
qa_factual pred= 192 draft= 102 acc= 88 rate=0.863 tok/s=54.7
translation pred= 187 draft= 102 acc= 85 rate=0.833 tok/s=53.6
creative_short pred= 157 draft= 95 acc= 61 rate=0.642 tok/s=48.3
stepwise_math pred= 192 draft= 104 acc= 87 rate=0.837 tok/s=53.7
long_code_review pred= 192 draft= 104 acc= 86 rate=0.827 tok/s=51.1
Aggregate: {
"n_requests": 9,
"total_predicted": 1688,
"total_draft": 927,
"total_draft_accepted": 748,
"aggregate_accept_rate": 0.8069,
"wall_s_total": 37.24
}
Yeah, probably depends on the quant as well.