Repository navigation
Falcon: pass position_ids to create_causal_mask so packed sequences stay isolated - #50894
Conversation
|
Thank you for your contribution 🤗! CI Security Gate — waiting for maintainer approvalCI is approved automatically only for authors who already have a contribution merged in this repository. A maintainer will review this PR and approve CI to run on it. |
vasqu
left a comment
There was a problem hiding this comment.
Small nit but lgtm overall
| seq_a = torch.randint(0, config.vocab_size, (1, 5), device=torch_device) | ||
| seq_b = torch.randint(0, config.vocab_size, (1, 7), device=torch_device) |
There was a problem hiding this comment.
hmm can we not reuse the already prepared input ids? but nit
There was a problem hiding this comment.
Thanks for the review. Done in 8fc031c:
- The test no longer draws its own random ids. It takes the first row of
input_idsfromprepare_config_and_inputs_for_common(), cuts it in half, and packs the two halves back into one row with per-documentposition_ids. - The test keeps its meaning: with the
position_ids=position_idsline removed fromFalconModel.forwardit fails (1 failed), with the fix it passes. tests/models/falcon/test_modeling_falcon.py: 163 passed, 172 skipped.ruff checkandruff format --checkpass on the file.
|
run-slow: falcon |
|
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. |
CI (Nvidia + AMD)Nvidia · ✅ No new failures 🎉👏 · ⚙️ Workflow · 📊 Dashboard Failures (1 pre-existing)Pre-existing failures (still failing) — 1 total: Same error (1): - falcon: AMD · ✅ No new failures 🎉👏 · ⚙️ Workflow · 📊 Dashboard Failures (2 pre-existing)Pre-existing failures (still failing) — 2 total: Same error (2): - falcon: |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: falcon |
What does this PR do?
Padding-free training (
DataCollatorWithFlattening, noattention_mask) relies oncreate_causal_maskrecovering the document boundaries fromposition_ids.FalconModel.forwardcalls it withoutposition_ids, so with eager and sdpa each document attends to the documents packed before it, and the packed logits (and loss) differ from the per-sequence ones.Trainerruns withuse_cache=Falseby default, so aTrainer+DataCollatorWithFlatteningrun on Falcon takes this path.The fix passes
position_ids(already computed a few lines above) the same wayLlamaModeldoes. The mask only changes for packed inputs (position_idsgiven, noattention_mask, no cache).Reproducer (published checkpoint, CPU), fails on
main, passes with the fix:main:0.1989. With this PR:1.2e-07.Test:
FalconModelTest.test_packed_sequences_do_not_attend_across_documentsfails onmainand passes here. The commontest_{eager,sdpa}_padding_matches_padding_free_with_position_idstests skip Falcon (_supports_attention_backendisFalse), which is why CI didn't catch this.OPT and XGLM also call
create_causal_maskwithoutposition_idsand leak the same way. I kept this PR to Falcon. Theuse_cache=Truecase (an empty cache disables the detection for every model) is #50419 / #50190 and is independent of this change.Who can review?
@vasqu @ArthurZucker