Coverage for transformer_lens/model_bridge/supported_architectures/qwen2_audio.py: 100%
12 statements
« prev ^ index » next coverage.py v7.10.1, created at 2026-08-11 18:50 +0000
« prev ^ index » next coverage.py v7.10.1, created at 2026-08-11 18:50 +0000
1"""Qwen2-Audio architecture adapter.
3``Qwen2AudioForConditionalGeneration``: a Whisper-style audio encoder at
4``model.audio_tower``, a linear projector at ``model.multi_modal_projector``,
5and a Qwen2 text decoder at ``model.language_model`` with a top-level
6``lm_head`` (the transformers >= 5.13 layout). Text-only forwards work without
7audio; audio features enter via ``input_features``.
8"""
10from typing import Any
12from transformer_lens.model_bridge.generalized_components.base import (
13 GeneralizedComponent,
14)
15from transformer_lens.model_bridge.supported_architectures.qwen2 import (
16 Qwen2ArchitectureAdapter,
17)
20class Qwen2AudioArchitectureAdapter(Qwen2ArchitectureAdapter):
21 """Architecture adapter for Qwen2AudioForConditionalGeneration models."""
23 _testing_lm_attr = "model.language_model"
24 _testing_eager = "config"
26 def __init__(self, cfg: Any) -> None:
27 """Initialize the Qwen2-Audio architecture adapter."""
28 super().__init__(cfg)
30 self.cfg.is_multimodal = True
31 self._reprefix_components("model.", "model.language_model.")
33 # The Whisper-style encoder and projector are wrapped opaquely
34 # (hook_in/hook_out only) — audio features are injected by the HF
35 # forward when input_features is passed.
36 self.components["audio_encoder"] = GeneralizedComponent(name="model.audio_tower")
37 self.components["audio_projector"] = GeneralizedComponent(
38 name="model.multi_modal_projector"
39 )