-
Notifications
You must be signed in to change notification settings - Fork 25
[model] support qwen3_asr #78
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| # Copyright (c) ModelScope Contributors. All rights reserved. | ||
| from . import glm, internvl, kimi_vl, llama4, llava, qwen, qwen3_5, qwen3_5_gdn, qwen3_omni, qwen3_vl | ||
| from . import glm, internvl, kimi_vl, llama4, llava, qwen, qwen3_5, qwen3_5_gdn, qwen3_asr, qwen3_omni, qwen3_vl |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Copyright (c) ModelScope Contributors. All rights reserved. | ||
| import torch | ||
| from transformers import PretrainedConfig | ||
|
|
||
| from mcore_bridge.bridge import MultimodalGPTBridge | ||
|
|
||
| from ..constant import ModelType | ||
| from ..register import ModelMeta, register_model | ||
| from .utils import HuggingFaceVit | ||
|
|
||
|
|
||
| class Qwen3ASRBridge(MultimodalGPTBridge): | ||
| hf_layers_prefix = 'thinker.model.layers' | ||
| hf_embed_key = 'thinker.model.embed_tokens.weight' | ||
| hf_final_layernorm_key = 'thinker.model.norm.weight' | ||
| hf_lm_head_key = 'thinker.lm_head.weight' | ||
| hf_score_key = 'thinker.score.weight' | ||
|
|
||
|
|
||
| class Qwen3ASRVit(HuggingFaceVit): | ||
| module_mapping = {'thinker.audio_tower': 'audio_tower'} | ||
| _vision_tower = ['audio_tower'] | ||
| _aligner = ['audio_tower.proj1', 'audio_tower.proj2'] | ||
| test_mm_type = 'audio' | ||
|
|
||
| def prepare_model(self, hf_config: PretrainedConfig): | ||
| from qwen_asr.core.transformers_backend.modeling_qwen3_asr import (Qwen3ASRAudioEncoder, | ||
| Qwen3ASRThinkerForConditionalGeneration) | ||
| self.audio_tower = Qwen3ASRAudioEncoder._from_config(hf_config.thinker_config.audio_config) | ||
| self.model_cls = Qwen3ASRThinkerForConditionalGeneration | ||
|
|
||
| def get_inputs_embeds(self, inputs_embeds, **kwargs): | ||
| input_ids = kwargs['input_ids'] | ||
| hf_config = self.hf_config.thinker_config | ||
| input_features = kwargs.get('input_features') | ||
| feature_attention_mask = kwargs.get('feature_attention_mask') | ||
|
|
||
| if input_features is None: | ||
| input_features = input_ids.new_zeros([1, 128, 128], dtype=self.audio_tower.dtype) | ||
| feature_attention_mask = input_ids.new_ones([1, 128], dtype=torch.bool) | ||
|
Jintao-Huang marked this conversation as resolved.
|
||
| audio_embeds = self.get_audio_features(input_features, feature_attention_mask) | ||
| inputs_embeds = inputs_embeds + audio_embeds.mean() * 0. | ||
| else: | ||
| audio_embeds = self.get_audio_features(input_features, feature_attention_mask) | ||
| audio_mask = (input_ids == hf_config.audio_token_id).unsqueeze(-1).expand_as(inputs_embeds) | ||
| audio_embeds = audio_embeds.to(inputs_embeds.device, inputs_embeds.dtype) | ||
| inputs_embeds = inputs_embeds.masked_scatter(audio_mask, audio_embeds) | ||
| return inputs_embeds | ||
|
|
||
| def get_audio_features(self, *args, **kwargs): | ||
| with self.patch_hf_config(): | ||
| return self.model_cls.get_audio_features(self, *args, **kwargs) | ||
|
|
||
|
|
||
| register_model(ModelMeta( | ||
| ModelType.qwen3_asr, | ||
| ['qwen3_asr'], | ||
| bridge_cls=Qwen3ASRBridge, | ||
| visual_cls=Qwen3ASRVit, | ||
| )) | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.