Skip to content

Initialize ZImage pad tokens deterministically#13805

Merged
dg845 merged 1 commit into
huggingface:mainfrom
sywangyi:Zimage_fix
May 26, 2026
Merged

Initialize ZImage pad tokens deterministically#13805
dg845 merged 1 commit into
huggingface:mainfrom
sywangyi:Zimage_fix

Conversation

@sywangyi
Copy link
Copy Markdown
Contributor

This PR fixes a determinism issue in ZImageTransformer2DModel by initializing its pad tokens with zeros instead of torch.empty().

The model's pad tokens participate in the forward path when padded caption or image tokens are present. Because they were previously created with torch.empty(), direct model instantiation from config could pick up uninitialized values, which made outputs unstable across runs and could surface NaNs in layerwise casting tests.

pytest tests/models/transformers/test_models_transformer_z_image.py::ZImageTransformerTests::test_layerwise_casting_inference
this case sometimes pass, sometimes fail

This PR fixes a determinism issue in ZImageTransformer2DModel by initializing its pad tokens with zeros instead of torch.empty().

The model's pad tokens participate in the forward path when padded caption or image tokens are present. Because they were previously created with torch.empty(), direct model instantiation from config could pick up uninitialized values, which made outputs unstable across runs and could surface NaNs in layerwise casting tests.

Signed-off-by: Wang, Yi <yi.a.wang@intel.com>
@github-actions github-actions Bot added models size/S PR with diff < 50 LOC labels May 25, 2026
@sywangyi
Copy link
Copy Markdown
Contributor Author

@sayakpaul please help review

@sayakpaul sayakpaul requested a review from dg845 May 25, 2026 02:58
Copy link
Copy Markdown
Collaborator

@dg845 dg845 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@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.

@dg845 dg845 merged commit 3bc3e52 into huggingface:main May 26, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants