Auto compile when static cache#34247
Conversation
a44e659 to
83a2c00
Compare
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
…s into generate-compile
There was a problem hiding this comment.
On principle this LGTM, however in practice I am not experiencing any speedup (but aggravated performance) until the number of new tokens is quite high, of the order of ~2500/3000 (quick test with Llama 3.1 8B)
Note sure if it comes only from compilation time and warmup, or some graph breaks somewhere
Did you try to compare performances a bit?
Co-authored-by: Cyril Vallez <[email protected]>
| model_kwargs = self._get_initial_cache_position(input_ids, model_kwargs) | ||
|
|
||
| def model_forward(model, *args, **kwargs): | ||
| return model.forward(*args, **kwargs) |
There was a problem hiding this comment.
@ArthurZucker This PR breaks some tests on PEFT :(
I checked why that is exactly, and I found that it has nothing to do with the compilation. The sole reason is that on 2nd iteration, we use this function, which effectively calls:
self.forward(**model_inputs, return_dict=True)
whereas on the first iteration (and before the PR), we would call:
self(**model_inputs, return_dict=True)
Is there any specific reason why forward is used? Using __call__ looks correct to me.
There was a problem hiding this comment.
Nice, thanks for the quick reply.
* generate with compile * nits * simple * generate with compile * nits * simple * safe * style * Update src/transformers/generation/utils.py Co-authored-by: Cyril Vallez <[email protected]> * remove TOKENIZER forked warning --------- Co-authored-by: Cyril Vallez <[email protected]>
What does this PR do?
Add automatic compile for
staticcache.This can be tested with:
which give 15sec for dynamic, 30 for the first generate, then 4seconds for the next one