Skip to content

Detect packed sequences when the cache is still empty - #50190

Open
ArthurZucker wants to merge 4 commits into
mainfrom
fix-packed-mask-empty-cache
Open

ArthurZucker wants to merge 4 commits into
mainfrom
fix-packed-mask-empty-cache

Conversation

@ArthurZucker

@ArthurZucker ArthurZucker commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

🤗 Transformers CI

With the default use_cache=True, models create an empty DynamicCache even in training, which skipped packed-sequence detection on position_ids and let packed sequences attend to each other with sdpa/eager/flex (max logit diff ~0.65 on tiny Llama). Detection now also runs when no tokens were seen yet; static caches are untouched, and the common padding-free test covers the default-cache forward.

With the default use_cache=True, models create an empty DynamicCache even in training, which disabled the packed
sequence detection on position_ids and let packed sequences attend to each other (sdpa/eager/flex).
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: flint

@vasqu

vasqu commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Any updates here? Imo we should consider something to turn of use cache to false when we call train maybe? Anyways seems like a few have noticed this issue

@Cyrilvallez

Copy link
Copy Markdown
Member

Agreed with @vasqu here, the better fix is probably to set use_cache = False by default while in train() mode, as otherwise we create and populate a cache that is completely wasted

@vasqu

vasqu commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Rebumping here

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants