Skip to content

test: compare fp32 model outputs with assert_close - #142

Merged
dengqiaoyu merged 1 commit into
apple:mainfrom
dengqiaoyu:u/qiaoyu_deng/fp32-output-tolerance
Oct 20, 2026
Merged

dengqiaoyu merged 1 commit into
apple:mainfrom
dengqiaoyu:u/qiaoyu_deng/fp32-output-tolerance

Conversation

@dengqiaoyu

Copy link
Copy Markdown
Contributor

torch.equal fails with max diff of 5.96e-08, use assert_close instead.

test_fold_quantize_is_noop @pkmandke
test_finalize_mmap_is_file_backed_and_output_preserving @pkmandke
test_finalize_mmap_preserves_weight_sharing @pkmandke
TestKMeansPalettizer::test_finalize_mmap_matches_non_mmap_output @vineet-g
TestKMeansPalettizer::test_finalize_state_dict_safetensors_roundtrip @vineet-g
TestKMeansPalettizerLoadFromStateDict::test_reproduces_prepared_model @crowbat
TestEagerQuantizer::test_prepare_basic @crowbat
TestEagerQuantizer::test_e2e_workflow @u-simha
TestKMeansPalettizer::test_finalize_torch_backend @NehalBhandari
TestGraphModeQuantizer::test_end_to_end_workflow @NehalBhandari

torch.testing.assert_close(
default_final(input_data), folded_final(input_data), atol=0, rtol=0
)
torch.testing.assert_close(folded_final(input_data), default_final(input_data))

@pkmandke pkmandke Oct 19, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test doesn't exercise mmap and only tests to ensure that the fold_quantize flag is a no-op. We should ideally get/expect bit-exact match. Are we seeing this to be flaky?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you think deepcopy would change memory layout?

I'd say if this particular test hasn't been observed to be flaky then let's have a torch.equal for it.

@pkmandke pkmandke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might be better to use torch.equal for test_fold_quantize_is_noop unless it has been observed to be flaky.

@apple apple deleted a comment from dengqiaoyu Oct 20, 2026
@dengqiaoyu
dengqiaoyu merged commit e9e2797 into apple:main Oct 20, 2026
14 checks passed
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.

5 participants