You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(models): project only the sampled row through the LM head at prefill for more families #1970
Follow-up to #1968 (PR #1969, which covered Llama 3.x, Mistral, Qwen2/2.5, and the vision wrapper). Eight more families still use the LanguageModel::forward_last_logits default (src/loaded_model.rs:448, plus forward_last_logits_with_sequence_id at :458 and forward_last_logits_with_embeddings_and_sequence_id at :485). That default computes [1, L, vocab] logits through the LM head during prefill and then keeps one row. The eight families are Qwen3, Qwen3-MoE, Phi-3, Mixtral, Gemma 2, Gemma 3, Jamba, and Nemotron-H.
Proposed Solution
Split each model's forward into a final-normed hidden-state path and the head. For Gemma 2 the head includes the final logit softcap, which is per position and so is applied after slicing. Then override all three forward_last_logits* entry points to slice the hidden state at last_pos before the head. Gemma 3 (wrapper), Jamba, and Nemotron-H keep per-sequence state, so for them the slice goes inside the same sequence-state closure that forward and forward_with_sequence_id already use.
Measured on M1 Ultra (pp512 prefill, main vs change, ABBA): Gemma 2 2B went from 2105 to 2662 tok/s (+26.5%), Gemma 3 4B from 1026 to 1222 (+19.2%), Qwen3 1.7B from 2170 to 2574 (+18.6%), and Qwen3-30B-A3B from 887 to 946 (+6.7%). Phi-3 mini gained about 3.8%, Nemotron 3 Nano 30B about 0.2 to 3%, Jamba 3B 0.8%, and Mixtral 8x7B 0.7%. Greedy output was identical on two prompts per model. The gain tracks vocabulary size relative to model size.
Out of scope: DeepSeek V3. No checkpoint is available locally to validate it.
Acceptance Criteria
A shared test helper checks all three entry points against the sliced full forward, at the last position and at an interior position. Every family with a tiny-model builder uses it, which means at least Qwen3 and Gemma 2.
Greedy output is identical to main on real checkpoints for all eight families.
A benchmark record is added under docs/benchmark_results/.
Activity
perf(models): project only the sampled row at prefill for 8 families (l…