| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | # Copyright 2025 Horizon team, Xiaomi MiLM Plus. |
| 4 | # Copyright 2024 The Qwen team. |
| 5 | # Copyright 2023 The vLLM team. |
| 6 | # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved. |
| 7 | # |
| 8 | # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX |
| 9 | # and OPT implementations in this library. It has been modified from its |
| 10 | # original forms to accommodate minor architectural differences compared |
| 11 | # to GPT-NeoX and OPT used by the Meta AI team that trained the model. |
| 12 | # |
| 13 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 14 | # you may not use this file except in compliance with the License. |
| 15 | # You may obtain a copy of the License at |
| 16 | # |
| 17 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 18 | # |
| 19 | # Unless required by applicable law or agreed to in writing, software |
| 20 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 21 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 | # See the License for the specific language governing permissions and |
| 23 | # limitations under the License. |
| 24 | |
| 25 | from transformers import PreTrainedConfig |
| 26 | from transformers.models.qwen2_5_omni.configuration_qwen2_5_omni import ( |
| 27 | Qwen2_5OmniTextConfig, |
| 28 | ) |
| 29 | |
| 30 | |
| 31 | class DashengConfig(PreTrainedConfig): |
| 32 | model_type = "midashenglm_dasheng_encoder" |
| 33 | |
| 34 | def __init__( |
| 35 | self, |
| 36 | embed_dim: int = 768, |
| 37 | outputdim: int = 527, |
| 38 | patch_size: int | tuple[int, int] = 16, |
| 39 | patch_stride: int | tuple[int, int] = 16, |
| 40 | input_channels: int = 1, |
| 41 | target_length: int = 1012, |
| 42 | depth: int = 12, |
| 43 | num_heads: int = 12, |
| 44 | mlp_ratio: float = 4.0, |
| 45 | qkv_bias: bool = True, |
| 46 | init_values: float | None = None, |
| 47 | drop_rate: float = 0.0, |
| 48 | attn_drop_rate: float = 0.0, |
| 49 | f_min: float = 0.0, |
| 50 | f_max: float = 8000.0, |
| 51 | center: bool = True, |
| 52 | win_length: int = 512, |
| 53 | hop_length: int = 160, |
| 54 | sample_rate: int = 16000, |
| 55 | n_fft: int = 512, |
| 56 | n_mels: int = 64, |
| 57 | **kwargs, |
| 58 | ): |
| 59 | self.embed_dim = embed_dim |
| 60 | self.outputdim = outputdim |
| 61 | self.patch_size = patch_size |
| 62 | self.patch_stride = patch_stride |
| 63 | self.input_channels = input_channels |
| 64 | self.target_length = target_length |
| 65 | self.depth = depth |
| 66 | self.num_heads = num_heads |
| 67 | self.mlp_ratio = mlp_ratio |
| 68 | self.qkv_bias = qkv_bias |
| 69 | self.init_values = init_values |
| 70 | self.drop_rate = drop_rate |
| 71 | self.attn_drop_rate = attn_drop_rate |
| 72 | self.f_min = f_min |
| 73 | self.f_max = f_max |
| 74 | self.center = center |
| 75 | self.win_length = win_length |
| 76 | self.hop_length = hop_length |
| 77 | self.sample_rate = sample_rate |
| 78 | self.n_fft = n_fft |
| 79 | self.n_mels = n_mels |
| 80 | super().__init__(**kwargs) |
| 81 | |
| 82 | |
| 83 | class MiDashengLMConfig(PreTrainedConfig): |
| 84 | model_type = "midashenglm" |
| 85 | |
| 86 | def __init__( |
| 87 | self, |
| 88 | audio_encoder_config: dict | None = None, |
| 89 | subsample_factor: int = 5, |
| 90 | text_config: dict | None = None, |
| 91 | audio_token_id: int | None = None, |
| 92 | **kwargs, |
| 93 | ): |
| 94 | self.audio_encoder_config = DashengConfig(**(audio_encoder_config or {})) |
| 95 | self.subsample_factor = subsample_factor |
| 96 | self.text_config = ( |
| 97 | Qwen2_5OmniTextConfig(**text_config) |
| 98 | if text_config |
| 99 | else Qwen2_5OmniTextConfig() |
| 100 | ) |
| 101 | self.text_config.rope_parameters = None # uses_mrope is false |
| 102 | self.audio_token_id = audio_token_id |
| 103 | super().__init__(**kwargs) |