Repository navigation
Conversation
TODO: - Currently complete microbatch needs to contain tokens which does not require the logits; need to optimize this further - There are a few more operations that are performed after the kv cache is calculated, need to safely optimize them.
|
Hi @ggerganov, @ngxson I was referring to the @max-krasnyansky 's recent PR on similar changes, and found that I was missing the crop of attention mask. I have added it in the latest commit. If you have more ideas on the tests that I can perform to check the correctness of this PR, please let me know. |
The other things you listed in the TODO in the description (ubatches) are already in that PR as well. |
|
Hi @max-krasnyansky , And regarding which PR should we move forward, I am fine with any option. |
|
OK. Sounds good. |
|
Sure Max, I am closing this one. We can continue on your PR. |
Overview
I have been discussing with @am17an regarding the high difference in prompt processing rate for Gemma 4 model on llama.cpp and mlx-lm. On debugging I found that the TODO in the
src/models/gemma4.cppby @ngxson states that the prompt processing can be improved by stripping the unused tokens after the last KV layer.This PR skips the computations that are happening after the calculation of attention for the tokens that do not require to calculate the logits. The improvement in the prompt processing rate is mentioned below:
The commit: 6c44591 has the following prompt processing rate:
Current PR's prompt processing rate:
I have tested this using the following command:
Additional information
I am testing this on the MacBook Air M3, 16GB RAM.
I have used the following model: ggml-org/gemma-4-E2B-it-GGUF
Requirements