Skip to content

[tests] fix autoencoderkl dtype tests#14190

Merged
sayakpaul merged 6 commits into
mainfrom
autoencoderkl-dtype-tests
Jul 18, 2026
Merged

[tests] fix autoencoderkl dtype tests#14190
sayakpaul merged 6 commits into
mainfrom
autoencoderkl-dtype-tests

Conversation

@sayakpaul

Copy link
Copy Markdown
Member

@sayakpaul
sayakpaul requested a review from dg845 July 15, 2026 06:00
@github-actions github-actions Bot added tests size/S PR with diff < 50 LOC labels Jul 15, 2026
# The reference and reloaded models hold identical weights, so any output difference is
# half-precision kernel nondeterminism between the two module instances rather than a save/load
# fidelity issue. The default 1e-4 tolerance is too tight for that fp16/bf16 noise on some GPUs.
super().test_from_save_pretrained_dtype_inference(tmp_path, dtype, atol=1e-3)

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.

It looks like even with an atol of 1e-3, the test still fails (https://github.com/huggingface/diffusers/actions/runs/29625018289/job/88027676669?pr=14190):

FAILED tests/models/autoencoders/test_models_autoencoder_kl.py::TestAutoencoderKL::test_from_save_pretrained_dtype_inference[bf16] - AssertionError: Loaded model output differs for torch.bfloat16
Tensors not close! Mismatched elements: 17/12288 (0.1%)
  Max diff: 3.906250e-03 at index (2, 1, 3, 13)
  Actual:   -5.625000e-01
  Expected: -5.585938e-01
  atol: 1.000000e-03, rtol: 0.000000e+00

I chatted with Claude about this and it suggested using a non-zero rtol, for example following the torch.testing.assert_close recommended tolerance values, which are atol=1e-5 and rtol=1.6e-2 for BF16. I think this makes sense as it makes the test more robust to the scale of the outputs (for example, if the outputs are really big, their absolute difference might be greater than 1e-3 even if they are relatively close and the difference is just due to numerical noise).

Claude also suggests per-dtype tolerances, which I also think make sense since the amount of expected noise should vary between FP16 and BF16 (for example, torch.testing.assert_close uses a rtol of 1e-3 for FP16).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Claude also suggests per-dtype tolerances, which I also think make sense since the amount of expected noise should vary between FP16 and BF16 (for example, torch.testing.assert_close uses a rtol of 1e-3 for FP16).

This is actually a good suggestion but perhaps the scope isn't quite there in this PR.

Rest -- I have addressed.

@sayakpaul
sayakpaul requested a review from dg845 July 18, 2026 03:20

@dg845 dg845 left a comment

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.

Thanks for the PR!

@sayakpaul
sayakpaul merged commit 4114946 into main Jul 18, 2026
14 checks passed
@sayakpaul
sayakpaul deleted the autoencoderkl-dtype-tests branch July 18, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S PR with diff < 50 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants