From ac77a5ca5ad5d8719238d21b29635b8c02006ef2 Mon Sep 17 00:00:00 2001 From: Yule100 Date: Thu, 24 Jul 2025 11:25:03 +0800 Subject: [PATCH] =?UTF-8?q?telechat2=20mcore=20=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model_executor/models/mf_models/config.py | 15 +++++-- .../models/mf_models/telechat2.py | 45 +++++++++++++++++++ .../model_executor/models/registry.py | 1 + 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 vllm_mindspore/model_executor/models/mf_models/telechat2.py diff --git a/vllm_mindspore/model_executor/models/mf_models/config.py b/vllm_mindspore/model_executor/models/mf_models/config.py index dd11efc27..ae9c259cb 100644 --- a/vllm_mindspore/model_executor/models/mf_models/config.py +++ b/vllm_mindspore/model_executor/models/mf_models/config.py @@ -48,12 +48,12 @@ MODEL_COMMON_MAPPING = { 'attention_dropout': ('model_config.hf_config.attention_dropout', None), 'hidden_act': ('model_config.hf_config.hidden_act', None), 'hidden_size': ('model_config.hf_config.hidden_size', None), - 'intermediate_size': ('model_config.hf_config.intermediate_size', None), + #'intermediate_size': ('model_config.hf_config.intermediate_size', None), 'max_position_embeddings': ('model_config.hf_config.max_position_embeddings', None), 'num_attention_heads': ('model_config.hf_config.num_attention_heads', None), - 'rms_norm_eps': ('model_config.hf_config.rms_norm_eps', None), + #'rms_norm_eps': ('model_config.hf_config.rms_norm_eps', None), 'num_hidden_layers': ('model_config.hf_config.num_hidden_layers', None), 'num_layers': ('model_config.hf_config.num_layers', None), 'num_key_value_heads': @@ -78,6 +78,9 @@ MODEL_COMMON_MAPPING = { 'router_aux_loss_coef': ('model_config.hf_config.router_aux_loss_coef', None), 'mlp_only_layers': ('model_config.hf_config.mlp_only_layers', None), + 'n_layer': ('model_config.hf_config.n_layer', None), + 'n_head': ('model_config.hf_config.n_head', None), + 'ffn_hidden_size': ('model_config.hf_config.ffn_hidden_size', None), } # model default config @@ -90,7 +93,13 @@ MODEL_RELATED_MAPPING = { 'layernorm_compute_dtype': 'bfloat16', 'rotary_dtype': 'bfloat16', 'router_dense_type': 'bfloat16', - } + }, + 'telechat': { + 'params_dtype': 'float16', # need an input + 'layernorm_compute_dtype': 'float32', + 'rotary_dtype': 'float16', + 'compute_dtype': 'float16', + }, # Add anther model type... } diff --git a/vllm_mindspore/model_executor/models/mf_models/telechat2.py b/vllm_mindspore/model_executor/models/mf_models/telechat2.py new file mode 100644 index 000000000..1374f66b8 --- /dev/null +++ b/vllm_mindspore/model_executor/models/mf_models/telechat2.py @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Copyright 2025 Huawei Technologies Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from mindformers.models.telechat2.configuration_telechat2 import Telechat2Config +from mindformers.models.telechat2.modeling_telechat2 import ( # noqa + Telechat2ForCausalLM as Telechat2ForCausalLM_MF) +from mindspore.nn.utils import no_init_parameters +from vllm.config import VllmConfig +from vllm.logger import init_logger + +from vllm_mindspore.model_executor.models.mf_models.config import ( + gen_model_config) +from vllm_mindspore.model_executor.models.mf_models.qwen3 import ( + Qwen3ForCausalLM) + +logger = init_logger(__name__) + + +class TeleChat2ForCausalLM(Qwen3ForCausalLM): + + def __init__(self, *, vllm_config: VllmConfig, prefix: str = "") -> None: + super().__init__(vllm_config=vllm_config, prefix=prefix) + + def _generate_model_config(self): + self.mf_model_config = gen_model_config(self.mf_config, Telechat2Config) + logger.debug("=====mf_model_config====\n%s", self.mf_model_config) + + def _create_network(self): + # Initial network + with no_init_parameters(): # Delay initialization + network = Telechat2ForCausalLM_MF(self.mf_model_config) + return network, network.model.output_layer diff --git a/vllm_mindspore/model_executor/models/registry.py b/vllm_mindspore/model_executor/models/registry.py index ed7e5ceb5..1a0ebba4f 100644 --- a/vllm_mindspore/model_executor/models/registry.py +++ b/vllm_mindspore/model_executor/models/registry.py @@ -31,6 +31,7 @@ _MINDFORMERS_MODELS = { "Qwen2ForCausalLM": ("qwen2", "Qwen2ForCausalLM"), "Qwen3ForCausalLM": ("qwen3", "Qwen3ForCausalLM"), # MCore "Qwen3MoeForCausalLM": ("qwen3_moe", "Qwen3MoeForCausalLM"), # MCore + "TeleChat2ForCausalLM": ("telechat2", "TeleChat2ForCausalLM"), # MCore "DeepseekV3ForCausalLM": ("deepseek_v3", "DeepseekV3ForCausalLM"), "DeepSeekMTPModel": ("deepseek_mtp", "DeepseekV3MTPForCausalLM"), } -- Gitee