Faster prompt eval w/ early exit after last layer's kv cache write #253
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.
Prompt evaluation's only side effect is to build the kv cache for all the layers, so we can exit early at the last layer once we've cached its k & v vectors (and also skip the final rmsnorm & logits computation)
Tested:
make runfast
w/ hyperfine on M2 Max Mac and adjusted-n
to only test prompt eval using prompts generated w/ lorem:hyperfine -L bin run,run_baseline -L model llama2.c.stories110M.bin,llama-2-7b-chat.llama2.c.bin --warmup=1 './{bin} "{model}" -n 100 -i "$( lorem -n 100 )"'
(103 tok/s)
(lorem -n 128)
(96 tok/s)
(1.76 tok/s)
(1.84 tok/s)
(lorem -n 750)
Notes:
master
and dominates the execution time. I've added figures after merging the fast tokenizer from Faster tokenization (log(n) lookups & caching of possible merges) #251 and using it as baseline