Repository navigation
Conversation
|
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. |
|
Hey! I don't think putting a runtime only attribute on the cache is a very good idea in general. If we want to do it, the way to go is at the very start of |
|
Thanks for the inputs, I'll try to come up with a better solution ! At least i tried to not create the masks at the very beginning and the CI was not happy at all ... |
|
Unsubscribing for a bit, feel free to ping me when it's ready 🫡 |
|
switching to draft for now |
ArthurZucker
left a comment
There was a problem hiding this comment.
this new update looks better! I don't think we need that much comments and etc, let's make this minimal!
|
Please ping me when ready for review @SunMarc! |
CI recapDashboard: View test results in Grafana |
|
closed in favor of #48814 ! |
What does this PR do?
This PR optimizes a bit the generation loop.
_ignore_causal_mask_sdpaalready decides that a padding mask with no padding can be ignored, but it decides it on every forward:fast_all(padding_mask)reduces the mask on the accelerator and reads the result back on the host, which stops the CPU from running ahead.Decoding only ever appends ones to the mask, so padding can only come from the prompt and the answer
is the same on every step. Settle it once, and don't hand the model a mask that says nothing:
Benchmark
MPS, 256 tokens, unpadded prompt
Why not drop the mask from
model_kwargs?Tried it: 607 CI failures. Its length and presence are load-bearing beyond masking.
_prefillcomparesinput_ids.shape[1] == attention_mask.shape[1]to tell whether the inputs arethe full sequence or only the new tokens — [generate] Completely stop relying on
cache_positionto prepare inputs #44130 removedcache_positionand promoted the mask'slength into that role.
_prepare_position_ids_for_generationswitches convention on its presence; without it, positionsovershoot by
past_length. That is silently wrong output, not an exception.custom_generaterecipes and the candidate generators index it directly, and live in other repos.