Fix shared transformer masks and temporal output channels#13711
Open
taivu1998 wants to merge 1 commit intohuggingface:mainfrom
Open
Fix shared transformer masks and temporal output channels#13711taivu1998 wants to merge 1 commit intohuggingface:mainfrom
taivu1998 wants to merge 1 commit intohuggingface:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #13651.
This PR addresses the shared transformer regressions covered by issue 13651:
attention_maskand per-conditionencoder_attention_maskthroughDualTransformer2DModelDualTransformer2DModelfrom the top-leveldiffuserspackage and refreshes the dummy PyTorch exportout_channelshandling explicit by accepting onlyNoneor values equal toin_channelsTransformer2DModellog-softmax path infloat32instead of promoting logits tofloat64Root Cause
DualTransformer2DModelwrappedTransformer2DModelinstances but did not accept or forward the attention masks that the wrapped transformer already supported, so masked cross-attention could not be preserved through the dual wrapper. The temporal transformer classes also exposed anout_channelsconfig field that was effectively ignored by the output projection, which made unsupported channel configurations look accepted. Finally, the discrete transformer output helper promoted logits to double precision beforelog_softmax, which required fp64 support where float32 is sufficient.Changes
encoder_attention_masktoDualTransformer2DModel.forwardand slice it alongsideencoder_hidden_statesfor each configured condition.attention_maskand the slicedencoder_attention_maskto the wrappedTransformer2DModel.CrossAttnDownBlock2Dsmoke test to cover the downstream wrapper path used in UNet-style blocks.DualTransformer2DModelinsrc/diffusers/__init__.pyand updateddummy_pt_objects.py.TransformerTemporalModelandTransformerSpatioTemporalModelchannel handling so unsupportedout_channels != in_channelsfails clearly.Validation
PYTHONPATH=src .venv/bin/python -m pytest tests/models/transformers/test_models_dual_transformer_2d.py tests/models/transformers/test_models_transformer_temporal.py tests/models/test_layers_utils.py::Transformer2DModelTests::test_spatial_transformer_discrete -q24 passed, 35 skipped, 1 warning in 8.29suvx ruff check src/diffusers/__init__.py src/diffusers/models/transformers/dual_transformer_2d.py src/diffusers/models/transformers/transformer_2d.py src/diffusers/models/transformers/transformer_temporal.py src/diffusers/utils/dummy_pt_objects.py tests/models/test_layers_utils.py tests/models/transformers/test_models_transformer_temporal.py tests/models/transformers/test_models_dual_transformer_2d.pyuvx ruff format --check src/diffusers/__init__.py src/diffusers/models/transformers/dual_transformer_2d.py src/diffusers/models/transformers/transformer_2d.py src/diffusers/models/transformers/transformer_temporal.py src/diffusers/utils/dummy_pt_objects.py tests/models/test_layers_utils.py tests/models/transformers/test_models_transformer_temporal.py tests/models/transformers/test_models_dual_transformer_2d.pyPYTHONPATH=src .venv/bin/python utils/check_dummies.pyPYTHONPATH=src .venv/bin/python -c "import sys; sys.path.append('utils'); import check_inits; check_inits.check_all_inits()"git diff --checkNote: running
utils/check_inits.pydirectly in this checkout looks forsrc/transformers/__init__.py; the underlyingcheck_all_inits()function passes when invoked withdiffusersonPYTHONPATH.