Repository navigation
Conversation
…language model generation
This branch has not been deployed
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.
Fixes #15497
What does this PR do?
In
AudioLDM2Pipeline.generate_language_model, GPT-2 runs a custom generation loop usinginputs_embedsandattention_maskviaprepare_inputs_for_generation(), which previously omittedposition_ids. BecauseAudioLDM2ProjectionModelconcatenates[sos, clap, eos, sos_1, t5 tokens, eos_1]where T5 tokens are padded in the middle when batching prompts of different lengths, omittingposition_idsshiftedeos_1and all generated tokens by the padding length for shorter prompts in the batch.This PR updates
prepare_inputs_for_generation()insrc/diffusers/pipelines/audioldm2/pipeline_audioldm2.pyto deriveposition_idsfromattention_maskwhen present (andposition_idsis not already supplied inkwargs), slicing to[:, -inputs_embeds.shape[1] :]on cached decoding steps (past_key_values is not None).Changes
src/diffusers/pipelines/audioldm2/pipeline_audioldm2.py: compute mask-derivedposition_idsinprepare_inputs_for_generation().tests/pipelines/audioldm2/test_audioldm2.py: addtest_prepare_inputs_for_generation_position_idsandtest_generate_language_model_batched_matches_singletoTestAudioLDM2Pipelinecovering middle-padded batches, cached decoding slices,attention_mask=None, and explicitposition_ids.Verification
pytest tests/pipelines/audioldm2/test_audioldm2.py -k "test_prepare_inputs_for_generation_position_ids or test_generate_language_model_batched_matches_single" -v: 2 passed (45 deselected) on CPU (torch 2.15.0+cpu,transformers 5.23.0).ruff check src/diffusers/pipelines/audioldm2/pipeline_audioldm2.py tests/pipelines/audioldm2/test_audioldm2.py: passed.ruff format --check src/diffusers/pipelines/audioldm2/pipeline_audioldm2.py tests/pipelines/audioldm2/test_audioldm2.py: passed.cc @sayakpaul