Skip to content

The shared test resets the seed before eager and compiled runs, then … - #49808

Open
sywangyi wants to merge 3 commits into
huggingface:mainfrom
sywangyi:compile_training
Open

sywangyi wants to merge 3 commits into
huggingface:mainfrom
sywangyi:compile_training

Conversation

@sywangyi

@sywangyi sywangyi commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🤗 Transformers CI

…compares their gradients. On XPU, the two paths generate different attention-dropout masks, so this comparison fails even though compiled SDPA's output and gradients match a reference calculation using its actual mask.

We could not find a PyTorch documentation guarantee that eager execution
and torch.compile must produce element-wise identical dropout masks from the same seed.
The reproducibility documentation discusses repeatability within the same environment,
not equivalence between these execution paths.
This change sets attention dropout to 0 only for EuroBERT's compile-training test,
preserving its gradient comparison without relying on that undocumented assumption.

@IlyasMoutawwakil please help review

…compares their gradients. On XPU, the two paths generate different attention-dropout masks, so this comparison fails even though compiled SDPA's output and gradients match a reference calculation using its actual mask.

We could not find a PyTorch documentation guarantee that eager execution
 and torch.compile must produce element-wise identical dropout masks from the same seed.
The reproducibility documentation discusses repeatability within the same environment,
 not equivalence between these execution paths.
This change sets attention dropout to 0 only for EuroBERT's compile-training test,
 preserving its gradient comparison without relying on that undocumented assumption.

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>
@sywangyi

Copy link
Copy Markdown
Contributor Author

EuroBERT is not uniquely affected by a model bug. The shared compile-training test resets the seed before the eager and compiled runs, then compares their gradients element by element. That comparison assumes both runs generate the same dropout mask, which is not guaranteed. In this environment, even standalone F.dropout produces different masks across the two paths with the same seed, while each path is reproducible on its own. EuroBERT exposes the assumption because its test configuration actually passes attention_dropout=0.1 into attention.

Other participating models generally use zero attention dropout in this test. T5Gemma, for example, has a fixture field set to 0.1, but its final encoder and decoder attention_dropout values are both 0.0; some models with nonzero dropout do not opt into the shared test. Setting EuroBERT’s dropout to zero therefore makes this deterministic gradient-equivalence test valid, but it does not test compiled training with dropout. That deserves separate coverage using a controlled mask or checks that do not require eager and compiled RNG streams to match.

@Rocketknight1

Copy link
Copy Markdown
Member

cc @ydshieh

@require_torch_accelerator
@pytest.mark.torch_compile_test
def test_torch_compile_for_training(self):
self.model_tester.attention_probs_dropout_prob = 0.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm shouldnt we reset to initial value afterwards? but overall fine to me, id just do this after all the setups, prepare_xx etc

…piled runs, then compares their gradients.

the two runs can produce different attention-dropout masks despite using the same seed, making EuroBERT's gradient comparison fail.

This PR sets `attention_dropout=0.0` only for EuroBERT's compile-training test. The setting is applied to the prepared config before model creation, without modifying or restoring shared tester state. Other EuroBERT tests retain their original dropout setting.

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>
@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: eurobert

Comment thread tests/test_modeling_common.py Resolved
Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>

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.

3 participants