Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[qwen2 audio] remove redundant code and update docs #36282

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gante
Copy link
Member

@gante gante commented Feb 19, 2025

What does this PR do?

Carved from #36238: Removes redundant code and updates outdated docs in qwen2_audio.

In a nutshell, the attention layers were copied from whisper. However, in qwen2_audio, the attention layers are exclusively used in the encoder, and thus never use cache. Removing cache-related code there prevents us from having to refactor every time we revisit caches, and results in more readable code.

The following bits were also updated in this PR:

  • Missing/outdated docs
  • Redundant overwrites

@@ -851,7 +776,7 @@ def forward(self, audio_features):
class Qwen2AudioForConditionalGeneration(Qwen2AudioPreTrainedModel, GenerationMixin):
def __init__(self, config: Qwen2AudioConfig):
super().__init__(config)
self.audio_tower = AutoModel.from_config(config.audio_config)
self.audio_tower = AutoModel.from_config(config.audio_config) # Usually a `Qwen2AudioEncoder` instance
Copy link
Member Author

Choose a reason for hiding this comment

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

There were no references of Qwen2AudioEncoder usage in our codebase nor on the hub. However, upon closer inspection of checkpoints, we can see it is used here. Added a comment for clarification.

(btw, Qwen2AudioEncoder is untested 😢 )

@@ -1259,78 +1184,5 @@ def forward(
attention_mask=attention_mask,
)

def prepare_inputs_for_generation(
Copy link
Member Author

@gante gante Feb 19, 2025

Choose a reason for hiding this comment

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

Doesn't seem to be needed? No tests fail. (the only custom code is in L1280-L1285, and _merge_input_ids_with_audio_features is related to the legacy processing)

It has the old, outdated pattern, so we would have to rewrite it anyway. If we get issues, then we can add the new prepare_inputs_for_generation pattern, with the correction

Comment on lines -1332 to -1333
def _reorder_cache(self, *args, **kwargs):
return self.language_model._reorder_cache(*args, **kwargs)
Copy link
Member Author

Choose a reason for hiding this comment

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

Only used in models that use the legacy cache format (not the case here)

@gante gante requested review from ArthurZucker and eustlb February 19, 2025 11:27
@HuggingFaceDocBuilderDev

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.

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.

2 participants