4 Commits

Author SHA1 Message Date
  i-robot f2e32b6445
!7861 【master】更新三方依赖版本信息 4 days ago
  zyw_hw 94d293ae67 update transformers copyright 4 days ago
  i-robot 69ade06f59
!7743 【master】【infer】修复共享专家大于1场景下hidden_size赋值逻辑 4 days ago
  pengjingyou fe3e6a8fc3 【master】【infer】修复共享专家大于1场景下hidden_size赋值逻辑 2 weeks ago
7 changed files with 197 additions and 29 deletions
Split View
  1. +52
    -14
      Third_Party_Open_Source_Software_Notice
  2. +2
    -2
      mindformers/parallel_core/inference/transformer/mlp.py
  3. +17
    -1
      tests/st/test_multi_cards_cases/test_parallel_core/test_inference/test_transformer/test_moe/test_moe_layer/test_infer_moe_tp.py
  4. +2
    -2
      tests/st/test_ut/test_models/weight_struct.json
  5. +103
    -3
      tests/st/test_ut/test_parallel_core/test_inference/test_transformer/test_moe/data_gen_utils.py
  6. +4
    -4
      tests/st/test_ut/test_parallel_core/test_inference/test_transformer/test_moe/run_infer_moe.py
  7. +17
    -3
      tests/st/test_ut/test_parallel_core/test_inference/test_transformer/test_moe/test_infer_moe.py

+ 52
- 14
Third_Party_Open_Source_Software_Notice View File

@@ -4650,7 +4650,7 @@ License: Apache License V2.0
See the License for the specific language governing permissions and
limitations under the License.

Software: transformers 4.51.3
Software: transformers 4.57.1
Copyright notice:
Copyright 2022 Microsoft Research and The HuggingFace Inc. team. All rights reserved
Copyright 2021 Iz Beltagy, Matthew E. Peters, Arman Cohan and The HuggingFace Inc. team. All rights reserved
@@ -4659,11 +4659,11 @@ Copyright 2020 The HuggingFace Inc. team, Microsoft Corporation
Copyright 2024 JetMoe AI
Copyright 2021 Google AI, Ross Wightman, The HuggingFace Inc. team. All rights reserved
Copyright 2024 AI21 Labs Ltd.
Copyright 2025 The rednote-hilab team
Copyright 2021 Microsoft Research and The HuggingFace Inc. team. All rights reserved
Copyright 2022 Facebook AI Research (FAIR) and The HuggingFace Inc. team. All rights reserved
Copyright 2025 HuggingFace Inc.
Copyright 2022 Facebook AI Research (FAIR) and The HuggingFace Inc. team. All rights reserved
Copyright 2022 SenseTime and The HuggingFace Inc. team. All rights reserved
Copyright 2023 The HuggingFace Team All rights reserved
Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved
Copyright 2023 The HuggingFace Team. All rights reserved
Copyright 2021 NVIDIA Corporation and The HuggingFace Team
@@ -4679,15 +4679,19 @@ Copyright 2025 Cohere team. All rights reserved
Copyright 2021 Google AI and HuggingFace Inc. team
Copyright 2022 Facebook AI and The HuggingFace Inc. team. All rights reserved
Copyright 2018 Microsoft
Copyright 2025 Kyutai and The HuggingFace Inc. team. All rights reserved
Copyright 2024 Google Inc.
Copyright 2022 Microsoft Research and The HuggingFace Inc. team
Copyright 2021 AlQuraishi Laboratory
Copyright 2024 The Fairseq Authors
Copyright (c) 2025 Baidu, Inc. and HuggingFace Inc. team. All Rights Reserved
Copyright 2020 The Facebook AI Research Team
Copyright (c) 2021 THUML Tsinghua University
Copyright 2020 The Hugging Face Team
Copyright 2023 The HuggingFace and Baidu Team. All rights reserved
Copyright 2023 MBZUAI and The HuggingFace Inc. team. All rights reserved
Copyright 2025 Google LLC and HuggingFace Inc. team
Copyright 2024 Microsoft Research and The HuggingFace Inc. team. All rights reserved
Copyright 2025 Apple Inc. and The HuggingFace Team. All rights reserved
Copyright 2023 Meta AI and The HuggingFace Inc. team. All rights reserved
Copyright 2018 The Google AI Language Team
Copyright 2022 The HuggingFace Team and Microsoft Research AI4Science. All rights reserved
@@ -4705,7 +4709,6 @@ Copyright 2021 Facebook AI Research (FAIR) and The HuggingFace Inc. team. All ri
Copyright 2024 Zyphra Technologies
Copyright 2022 NAVER AI Labs and The HuggingFace Inc. team. All rights reserved
Copyright 2022 The HuggingFace Inc. team
Copyright 2021 Google T5
Copyright 2023 The HuggingFace Inc. team. All rights reserved
Copyright 2020 The HuggingFace Inc. team. All rights reserved
Copyright 2024 BigCode and The HuggingFace Inc. team. All rights reserved
@@ -4725,19 +4728,22 @@ Copyright 2018 LXMERT Authors, The Hugging Face Team
Copyright 2023 Adept AI
Copyright 2023, The T5 Authors and HuggingFace Inc.
Copyright 2020 Huggingface
Copyright 2025 TII
Copyright 2025 The HuggingFace Inc. team. All rights reserved
Copyright 2023 EleutherAI and The HuggingFace Inc. team. All rights reserved
Copyright 2019 The Google AI Language Team
Copyright 2023 The Salesforce Team
Copyright 2022 The Impira Team
Copyright 2022 University of Cambridge, Tencent AI Lab, DeepMind and The University of Hong Kong
Copyright 2025 SHI Labs and The HuggingFace Inc. team. All rights reserved
Copyright 2024 The Kyutai and HuggingFace Inc. teams. All rights reserved
Copyright 2023 Mistral AI
Copyright 2025 Deepseek AI and The HuggingFace Team. All rights reserved
Copyright 2019-present CNRS, Facebook Inc.
Copyright 2022 Google AI and The HuggingFace Inc. team. All rights reserved
Copyright 2022 EleutherAI
Copyright The HuggingFace team. All rights reserved
Copyright 2023 HuggingFace Inc. team and MosaicML NLP team
Copyright 2025 Microsoft Research and The HuggingFace Inc. team. All rights reserved
Copyright 2023 Google AI and The HuggingFace Team. All rights reserved
Copyright 2019-present
Copyright 2022 LongT5
@@ -4772,8 +4778,8 @@ Copyright 2021 ASAPP Inc.
Copyright Google AI and The HuggingFace Inc. team. All rights reserved
Copyright 2023 University of Wisconsin-Madison and The HuggingFace Inc. team. All rights reserved
Copyright 2021-2023 HuggingFace Inc.
Copyright 2023 The Mega Authors and The HuggingFace Inc. team
Copyright 2022, UCLA NLP, The Facebook AI Research Team and The HuggingFace Inc. team. All rights reserved
Copyright 2023 The Mega Authors and The HuggingFace Inc. team
Copyright 2018 Mesh TensorFlow
Copyright 2024 Tri Dao, Albert Gu, Technological Innovation Institute and HuggingFace Inc. team
Copyright 2020 Microsoft
@@ -4790,15 +4796,16 @@ Copyright 2025 Advanced Micro Devices, Inc. and The HuggingFace Team. All rights
Copyright 2024 TikTok and The HuggingFace Inc. team. All rights reserved
Copyright 2018 HuggingFace Inc
Copyright 2023 The Espnet authors, IMS Toucan
Copyright 2022 HuggingFace Inc.
Copyright 2024 Baidu Inc and The HuggingFace Inc. team
Copyright 2018- The Hugging Face team. All rights reserved
Copyright 2024 Baidu Inc and The HuggingFace Inc. team
Copyright 2022 HuggingFace Inc.
Copyright 2023 Meta Platforms Inc. and The HuggingFace Inc. team. All rights reserved
Copyright 2025 Google Inc. HuggingFace Inc. team. All rights reserved
Copyright 2024 Answer.AI, LightOn, and contributors
Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved
Copyright (c) Microsoft Corporation and HuggingFace
Copyright 2022, The LongT5 Authors and HuggingFace Inc.
Copyright (c) 2024 THL A29 Limited, a Tencent company and The HuggingFace Inc. team. All rights reserved
Copyright 2024 The Apple Research Team
Copyright 2020 The Allen Institute
Copyright 2022 Meta Platforms and The HuggingFace Inc. team. All rights reserved
@@ -4806,6 +4813,7 @@ Copyright 2021 Mesh TensorFlow
Copyright 2020-present Google Brain and Carnegie Mellon University
Copyright 2024 The Qwen team, Alibaba Group and The HuggingFace Inc. team. All rights reserved
Copyright 2021 NVIDIA The HuggingFace Inc. team. All rights reserved
Copyright 2025 The BitNet team and The HuggingFace Inc. team. All rights reserved
Copyright 2022 WenXiang ZhongzhiCheng LedellWu LiuGuang BoWenZhang The HuggingFace Inc. team. All rights reserved
Copyright 2024 Databricks Mosaic Research and The HuggingFace Inc. team. All rights reserved
Copyright 2023 The Fairseq Authors, Microsoft Research
@@ -4831,11 +4839,14 @@ Copyright 2023 EleutherAI
Copyright 2023 Google Research, Inc. and The HuggingFace Inc. team. All rights reserved
Copyright 2022 The Trajectory Transformers paper
Copyright 2025 Baidu Inc and The HuggingFace Inc. team
Copyright 2025 Johns Hopkins University, LightOn
Copyright 2022 WenXiang ZhongzhiCheng LedellWu LiuGuang BoWenZhang and The HuggingFace Inc. team. All rights reserved
Copyright 2020 The HuggingFace Team. Tutti
Copyright 2020 The HuggingFace Team Inc.
Copyright 2023 The Google Flax Team
Copyright 2025 The Meta AI
Copyright 2021, The Facebook AI Research Team and The HuggingFace Inc. team. All rights reserved
Copyright 2025 Technology Innovation Institute
Copyright (c) Facebook, Inc.
Copyright 2024 Kyutai and The HuggingFace Inc. team. All rights reserved
Copyright 2022 School of EIC, Huazhong University of Science & Technology and The HuggingFace Inc. team. All rights reserved
@@ -4846,16 +4857,19 @@ Copyright 2024 Meta Platforms, Inc.
Copyright 2020 The Google AI Language Team Authors, Allegro.pl, Facebook Inc.
Copyright 2024 Cohere Inc. HuggingFace Inc. team. All rights reserved
Copyright 2021 Deepmind and The HuggingFace Inc. team. All rights reserved
Copyright 2025 The Intel Labs Team Authors, The Microsoft Research Team
Copyright 2023 HuggingFace Inc. team
Copyright 2022 Salesforce
Copyright 2022 The Salesforce authors, The Open AI Team
Copyright 2022 The BAAI Teams
Copyright 2022 cookiecutter.authors . All rights reserved
Copyright 2025 Google LLC
Copyright 2020 The SqueezeBert authors and The HuggingFace Inc. team
Copyright 2021- NVIDIA Corporation and The HuggingFace Inc. team. All rights reserved
Copyright 2022 The Facebook AI Research Team
Copyright 2020 Hugging Face
Copyright 2023 MetaAI
Copyright 2024 The HuggingFace Team Inc.
Copyright 2022 The OFA-Sys Team
Copyright 2024 BigCode
Copyright 2022 The OpenAI team and The HuggingFace Team. All rights reserved
@@ -4863,11 +4877,13 @@ Copyright 2021 NVIDIA Corporation and The HuggingFace Team. All rights reserved
Copyright 2018 The Microsoft Research Asia LayoutLM Team
Copyright 2023 Amazon and The HuggingFace Inc. team. All rights reserved
Copyright 2019 Hugging Face inc.
Copyright 2025 The OFA-Sys Team
Copyright 2023, HuggingFace Inc.
Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved
Copyright 2022 Sea AI Lab and The HuggingFace Inc. team. All rights reserved
Copyright 2023 The Intel Labs Team Authors, The Microsoft Research Team
Copyright 2020 The HuggingFace Inc. team, The Microsoft Research team
Copyright 2025 Westlake Representational Learning Lab (Fajie Yuan Lab) team
Copyright 2023 NllbMoe
Copyright 2021 The UCLA NLP Authors and The HuggingFace Inc. team. All rights reserved
Copyright 2025 The Qwen team, Alibaba Group
@@ -4877,7 +4893,6 @@ Copyright 2021 The Eleuther AI and HuggingFace Inc. team. All rights reserved
Copyright 2022 Meta and The HuggingFace Inc. team. All rights reserved
Copyright 2023 Apple Inc. and The HuggingFace Inc. team. All rights reserved
Copyright 2022 Meta Platforms, Inc.and The HuggingFace Inc. team. All rights reserved
Copyright 2024 Mistral AI and The HuggingFace Inc. team. All rights reserved
Copyright 2023 HuggingFace Inc. Team and Bigscience Workshop. All rights reserved
Copyright 2022s HuggingFace Inc.
Copyright The HuggingFace Inc. team. All rights reserved
@@ -4900,12 +4915,14 @@ Copyright 2021 The HuggingFace Team
Copyright 2024, The HuggingFace Inc. team. All rights reserved
Copyright 2018 The Google AI Language Team Authors, The HuggingFace Inc. team
Copyright 2024 Intel Labs and The HuggingFace Inc. team. All rights reserved
Copyright 2022 The HuggingFace Inc. Team. All rights reserved
Copyright 2025 Bytedance-Seed Ltd
Copyright 2018 Salesforce and HuggingFace Inc. team
Copyright 2022 The Metaseq Authors and The HuggingFace Inc. team. All rights reserved
Copyright 2021 HuggingFace Inc.
Copyright 2022 HuggingFace Inc. team and BigScience
Copyright 2025 Meta AI and The HuggingFace Inc. team. All rights reserved
Copyright 2022 The HuggingFace Team and Microsoft Research AI4Science All rights reserved
Copyright 2025 The ZhipuAI Inc. team and HuggingFace Inc. team. All rights reserved
Copyright 2018 The Google Flax Team
Copyright 2020 Google and The HuggingFace Inc. team
Copyright 2021 ASAPP Inc. and The HuggingFace Inc. team. All rights reserved
@@ -4913,22 +4930,26 @@ Copyright 2023 Meta Platforms, Inc. and The HuggingFace Inc. team. All rights re
Copyright 2023 The Kakao Enterprise
Copyright 2023 HuggingFace Inc. team. All rights reserved
Copyright 2024 IDEA Research and The HuggingFace Inc. team. All rights reserved
Copyright 2025 Meta Platforms, Inc. and The HuggingFace Inc. team. All rights reserved
Copyright 2022 HuggingFace Inc. team
Copyright 2022 The Hugging Face Team
Copyright 2024 Mistral
Copyright Deepmind and The HuggingFace Inc. team. All rights reserved
Copyright Iz Beltagy, Matthew E. Peters, Arman Cohan and The HuggingFace Inc. team. All rights reserved
Copyright 2021 The EleutherAI and HuggingFace Teams. All rights reserved
Copyright 2023 The BigCode team and HuggingFace Inc. team
Copyright 2023 Mixtral AI and The HuggingFace Inc. team. All rights reserved
Copyright 2025 IBM
Copyright 2021 Facebook AI Research The HuggingFace Inc. team. All rights reserved
Copyright 2020, The T5 Authors and HuggingFace Inc.
Copyright 2021, The Facebook, Inc. and The HuggingFace Inc. team. All rights reserved
Copyright 2025 Meituan
Copyright (c) 2020, VinAI Research
Copyright 2019 The TensorFlow Authors, The Hugging Face Team. All Rights Reserved
Copyright 2024 The HuggingFace Inc. team
Copyright 2023 The Meta AI Team
Copyright 2023 IBM and HuggingFace Inc. team. All rights reserved
Copyright 2025 Meta Platforms, Inc.
Copyright 2025 MiniMaxAI and HuggingFace Inc. teams. All rights reserved
Copyright 2021 The Fairseq Authors, Microsoft Research, and The HuggingFace Inc. team. All rights reserved
Copyright 2019 The Open AI Team
Copyright 2018 The Microsoft Research Asia LayoutLM Team Authors, The Hugging Face Team
@@ -4937,6 +4958,7 @@ Copyright 2018 The Google AI Language Team Authors
Copyright 2022 Google AI, Ross Wightman, The HuggingFace Inc. team. All rights reserved
Copyright 2018 Amazon.com, Inc.
Copyright 2022 The HuggingFace Team The HuggingFace Inc. team. All rights reserved
Copyright 2025 Arcee AI
Copyright 2024 Microsoft and The HuggingFace Inc. team. All rights reserved
Copyright 2022 UW-Madison and The HuggingFace Inc. team. All rights reserved
Copyright 2022 The HuggingFace Team All rights reserved
@@ -4954,6 +4976,7 @@ Copyright 2023 Meta Platforms, Inc.
Copyright 2023 The Intel Team Authors, The HuggingFace Inc. team. All rights reserved
Copyright 2023 Toshiyuki
Copyright 2024 Microsoft Research and HuggingFace Inc. team
Copyright 2025 Eduard Durech and SGLang team
Copyright 2022 The Salesforce Team
Copyright 2022 Microsoft
Copyright 2021, The HuggingFace Inc. team. All rights reserved
@@ -4968,10 +4991,12 @@ Copyright 2024 IBM
Copyright Studio Ousia and The HuggingFace Inc. team
Copyright 2022, UCLA NLP, The Facebook AI Research Team
Copyright 2022 SHI Labs and The HuggingFace Inc. team
Copyright (c) 2025 THL A29 Limited, a Tencent company
Copyright 2021 HuggingFace Inc. team
Copyright 2023 MURGe-Lab and The HuggingFace Inc. team. All rights reserved
Copyright 2022 EleutherAI and The HuggingFace Inc. team. All rights reserved
Copyright 2023 Bo Peng and HuggingFace Inc. team
Copyright 2025 NXAI GmbH. All rights reserved
Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved
Copyright 2021 The Facebook AI Research Team
Copyright 2022 Microsoft Research Asia
@@ -4992,6 +5017,7 @@ Copyright 2019 Facebook AI Research
Copyright 2021 NVIDIA and The HuggingFace Inc. team. All rights reserved
Copyright 2025 Advanced Micro Devices, Inc. and The HuggingFace Inc. team. All rights reserved
Copyright 2021 The HuggingFace Team. All rights reserved
Copyright 2025 The LG AI Research and HuggingFace Inc. team. All rights reserved
Copyright 2022 Leon Derczynski. All rights reserved
Copyright 2024 Descript and The HuggingFace Inc. team. All rights reserved
Copyright 2021, The Microsoft Research Asia MarkupLM Team
@@ -5001,6 +5027,7 @@ Copyright 2018 HuggingFace Inc. team
Copyright 2024 The Qwen team, Alibaba Group
Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved
Copyright 2020 The Microsoft Authors and The HuggingFace Inc. team
Copyright 2025 Meta Inc. and The HuggingFace Inc. team. All rights reserved
Copyright 2022 Google AI and The HuggingFace Team. All rights reserved
Copyright 2022 Google LongT5
Copyright 2021 Google Research and The HuggingFace Inc. team
@@ -5010,10 +5037,12 @@ Copyright 2020 Ecole Polytechnique
Copyright 2022 The Fairseq Authors and The Google Flax Team
Copyright 2022 Microsoft Research and The HuggingFace Team. All rights reserved
Copyright 2024 Stability AI and The HuggingFace Inc. team. All rights reserved
Copyright 2025 The Fairseq Authors
Copyright 2022, The HuggingFace Inc. team. All rights reserved
Copyright 2023 Meta AI, EleutherAI
Copyright 2022 KAIST and The HuggingFace Inc. team. All rights reserved
Copyright 2022 NVIDIA and The HuggingFace Team. All rights reserved
Copyright 2025 Mobile Perception Systems Lab
Copyright 2024 Microsoft Research, Inc. and The HuggingFace Inc. team. All rights reserved
Copyright 2020 The HuggingFace Inc. team
Copyright 2022 Sea AI Labs and The HuggingFace Inc. team. All rights reserved
@@ -5023,8 +5052,10 @@ Copyright Meta Platforms and The HuggingFace Inc. team. All rights reserved
Copyright 2024 Meta Inc. and The HuggingFace Inc. team. All rights reserved
Copyright 2024 Meta and The HuggingFace Inc. team. All rights reserved
Copyright 2021 Google AI, Google
Copyright 2025 The LG AI Research and The HuggingFace Inc. team. All rights reserved
Copyright 2024 Microsoft Research & University of Wisconsin-Madison
Copyright 2021 The Marian Team
Copyright 2025 Mistral AI and The HuggingFace Inc. team. All rights reserved
Copyright 2021 The Fairseq Authors and The Google Flax Team
Copyright 2021 Studio Ousia
Copyright 2024 Cohere team. All rights reserved
@@ -5032,11 +5063,15 @@ Copyright 2010, The Microsoft Research Asia LayoutLM Team
Copyright 2020, The RAG Authors and The HuggingFace Inc. team
Copyright 2020, Microsoft
Copyright 2018 DPR Authors, The Hugging Face Team
Copyright 2025 The LG AI Research and The HuggingFace Team. All rights reserved
Copyright 2025 The BitNet Team and The HuggingFace Inc. team. All rights reserved
Copyright 2024 JetMoe AI and The HuggingFace Inc. team. All rights reserved
Copyright 2023 The Bigcode team and HuggingFace Inc. team
Copyright 2024 HuggingFace Inc. team. All rights reserved
Copyright 2025 Sesame and The HuggingFace Inc. team. All rights reserved
Copyright 2022 ABEJA, Inc. and The HuggingFace Inc. team. All rights reserved
Copyright 2018 The Google AI Language Team Authors, Facebook AI Research
Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved
Copyright 2021, Google and The HuggingFace Inc. team. All rights reserved
Copyright 2022 Apple Inc. and The HuggingFace Inc. team. All rights reserved
Copyright 2024 The HuggingFace Team. All rights reserved
@@ -5046,6 +5081,7 @@ Copyright 2024 HuggingFace Inc.
Copyright 2022 The HuggingFace Team. All rights reserved
Copyright 2023 IBM & Hugging Face. All rights reserved
Copyright 2023 The Pop2Piano Authors and The HuggingFace Inc. team. All rights reserved
Copyright 2025 The Nari Labs and HuggingFace Inc. team. All rights reserved
Copyright 2022 University of Wisconsin-Madison and The HuggingFace Inc. team. All rights reserved
Copyright 2024 Microsoft
Copyright 2022 Tsimur Hadeliya. All rights reserved
@@ -5054,8 +5090,8 @@ Copyright 2023 The Meta AI
Copyright 2021 The HuggingFace Team All rights reserved
Copyright 2021 Tel AViv University, AllenAI and The HuggingFace Inc. team. All rights reserved
Copyright 2021 The Google Flax Team
Copyright 2023 Mistral AI and The HuggingFace Inc. team. All rights reserved
Copyright 2021 The I-BERT Authors Sehoon Kim, Amir Gholami, Zhewei Yao, Michael Mahoney, Kurt Keutzer
Copyright 2023 Mistral AI and The HuggingFace Inc. team. All rights reserved
Copyright 2021 The HuggingFace Inc. team. All rights reserved
Copyright 2025 The LLAMA4 and HuggingFace Inc. team. All rights reserved
Copyright 2018 Salesforce and The HuggingFace Inc. team
@@ -5065,15 +5101,17 @@ Copyright 2021 The Facebook Inc. and The HuggingFace Inc. team. All rights reser
Copyright 2024 The GLM & ZhipuAI team and HuggingFace Inc. team. All rights reserved
Copyright 2022 cookiecutter.authors and The HuggingFace Inc. team. All rights reserved
Copyright 2018, Hao Tan, Mohit Bansal
Copyright 2025 Jingze Shi
Copyright 2025 Microsoft
Copyright 2023 The Salesforce Authors and The HuggingFace Team. All rights reserved
Copyright 2024 The ggml.ai team and The HuggingFace Inc. team
Copyright 2022 Meta Platforms
Copyright 2025 The HuggingFace Team Inc.
Copyright 2024 The Fairseq Authors and The HuggingFace Inc. team. All rights reserved
Copyright 2020 Mesh TensorFlow
Copyright 2023 Mesh TensorFlow
Copyright 2022 Hugging Face inc.
Copyright 2021 The Fairseq Authors
Copyright 2022 Hugging Face inc.
Copyright 2023 Microsoft Research and The HuggingFace Inc. team. All rights reserved
Copyright 2018 Google T5
Copyright 2022 NVIDIA The HuggingFace Inc. team. All rights reserved


+ 2
- 2
mindformers/parallel_core/inference/transformer/mlp.py View File

@@ -90,8 +90,8 @@ class MLP(nn.Cell):
self.tp_group = tp_group
self.tp_group_size = tp_group.size if tp_group is not None else 1

if is_expert and self.config.moe_ffn_hidden_size is not None:
ffn_hidden_size = self.config.moe_ffn_hidden_size
if is_expert and self.config.moe_shared_expert_intermediate_size is not None:
ffn_hidden_size = self.config.moe_shared_expert_intermediate_size
else:
ffn_hidden_size = self.config.ffn_hidden_size
self.ffn_hidden_size_per_partition = divide(ffn_hidden_size, self.tp_group_size)


+ 17
- 1
tests/st/test_multi_cards_cases/test_parallel_core/test_inference/test_transformer/test_moe/test_moe_layer/test_infer_moe_tp.py View File

@@ -41,6 +41,12 @@ MOE_CONFIG_WITHOUT_SHARED_EXPERTS = {
"num_experts_per_tok": 2, "n_group": 2, "topk_group": 2
}

MOE_CONFIG_WITH_TWO_SHARED_EXPERTS = {
"batch_size": 4, "seq_len": 4, "hidden_size": 32, "moe_intermediate_size": 8, "num_experts": 8,
"moe_shared_expert_intermediate_size": 16, "n_shared_experts": 2, "routed_scaling_factor": 2.5,
"num_experts_per_tok": 2, "n_group": 2, "topk_group": 2
}

FOUR_CARD_TEST_PARAM = "model_args, data_keys, expect_error, tensor_parallel, expert_parallel"
FOUR_CARD_DP1TP4EP1_TEST_CASES = [
(
@@ -62,7 +68,17 @@ FOUR_CARD_DP1TP4EP1_TEST_CASES = [
MOE_CONFIG_WITHOUT_SHARED_EXPERTS,
{"output": "tp1_no_shared"},
False,
4, 1)
4, 1),
(
# 并行策略: DP=1 TP=4 EP=1
# eg: input (4 * 4, H) -> [moe] -> output (4 * 4,H)
# seq_len: 4, batch_size: 4, hidden_size: 32, num_experts: 8,
# moe_intermediate_size: 8, moe_shared_expert_intermediate_size: 16
# expected result: 功能跑通, 精度对齐。
MOE_CONFIG_WITH_TWO_SHARED_EXPERTS,
{"output": "tp1_2_shared"},
False,
4, 1),
]




+ 2
- 2
tests/st/test_ut/test_models/weight_struct.json View File

@@ -657,11 +657,11 @@
128
],
"decoder.layers.1.mlp.shared_experts.linear_fc1.weight": [
512,
1024,
128
],
"decoder.layers.1.mlp.shared_experts.linear_fc1.w_scale": [
512
1024
],
"decoder.layers.1.mlp.shared_experts.linear_fc2.weight": [
128,


+ 103
- 3
tests/st/test_ut/test_parallel_core/test_inference/test_transformer/test_moe/data_gen_utils.py View File

@@ -15,15 +15,15 @@
"""Generate data for mcore MOE UT of inference."""
import numpy as np

def get_init_params(seq_len, batch_size, hidden_size, num_experts, moe_intermediate_size):
def get_init_params(seq_len, batch_size, hidden_size, num_experts, moe_intermediate_size, n_shared_experts):
"""Generate initialization parameters"""
np.random.seed(2025)
gate_weight_shape = (num_experts, hidden_size)
gate_e_score_correction_bias_shape = (num_experts,)
experts_fc1_weight_shape = (num_experts, hidden_size, moe_intermediate_size * 2)
experts_fc2_weight_shape = (num_experts, moe_intermediate_size, hidden_size)
shared_experts_fc1_weight_shape = (moe_intermediate_size * 2, hidden_size)
shared_experts_fc2_weight_shape = (hidden_size, moe_intermediate_size)
shared_experts_fc1_weight_shape = (moe_intermediate_size * n_shared_experts * 2, hidden_size)
shared_experts_fc2_weight_shape = (hidden_size, moe_intermediate_size * n_shared_experts)
return {
"input": np.random.rand(batch_size * seq_len, hidden_size),
"router.weight": 0.01 * np.random.rand(*gate_weight_shape),
@@ -232,9 +232,109 @@ def get_golden() -> dict[str, np.ndarray]:
0.000372, 0.0002728, 0.000286, 0.0002537, 0.0002708, 0.00037,
0.0003624, 0.000309]], dtype=np.float16)

tp1_2_shared = np.array(
[[0.0006523, 0.0007553, 0.0006714, 0.0006104, 0.0006714, 0.0007133,
0.000702, 0.000824, 0.0007477, 0.0007706, 0.0005913, 0.000725,
0.000725, 0.0006943, 0.000637, 0.000778, 0.000572, 0.0006104,
0.00066, 0.0006027, 0.000618, 0.000641, 0.0006943, 0.000675,
0.000763, 0.0006485, 0.0006676, 0.0005493, 0.0005226, 0.0007935,
0.00066, 0.000599],
[0.000717, 0.0008507, 0.000763, 0.0006866, 0.000763, 0.0008087,
0.0007896, 0.000931, 0.000839, 0.0008698, 0.0006485, 0.000824,
0.0008316, 0.000782, 0.0007324, 0.0008774, 0.000641, 0.000683,
0.0007477, 0.000679, 0.000702, 0.000717, 0.000782, 0.000763,
0.0008545, 0.000721, 0.0007553, 0.0006256, 0.0005875, 0.000889,
0.000763, 0.0006866],
[0.0004044, 0.000473, 0.0004253, 0.000389, 0.0004158, 0.0004463,
0.0004368, 0.0005226, 0.0004654, 0.000475, 0.0003643, 0.0004463,
0.0004616, 0.0004387, 0.0004005, 0.0004845, 0.0003586, 0.0003815,
0.00041, 0.00037, 0.0003967, 0.000393, 0.0004349, 0.0004158,
0.0004692, 0.0004025, 0.0004196, 0.0003433, 0.0003242, 0.0004997,
0.0004196, 0.0003777],
[0.000433, 0.0005074, 0.0004463, 0.0004063, 0.000454, 0.0004807,
0.0004654, 0.0005493, 0.0005074, 0.0005226, 0.000393, 0.0004768,
0.000492, 0.0004654, 0.0004349, 0.0005226, 0.0003815, 0.0004044,
0.0004444, 0.0004005, 0.0004177, 0.0004272, 0.0004692, 0.0004578,
0.000515, 0.0004387, 0.0004463, 0.000372, 0.000349, 0.000534,
0.0004501, 0.0004005],
[0.0004807, 0.000576, 0.000511, 0.0004768, 0.000519, 0.0005493,
0.0005302, 0.0006256, 0.000576, 0.0005875, 0.0004425, 0.000557,
0.0005646, 0.000534, 0.0004997, 0.0006065, 0.0004501, 0.000473,
0.0005035, 0.0004654, 0.000475, 0.000496, 0.0005302, 0.0005226,
0.00058, 0.000492, 0.0005074, 0.0004272, 0.0003948, 0.0006104,
0.0005264, 0.0004654],
[0.0007515, 0.0008774, 0.000763, 0.0007057, 0.0007935, 0.0008316,
0.0008163, 0.00095, 0.0008774, 0.0009003, 0.000679, 0.000839,
0.0008583, 0.0008125, 0.0007477, 0.0009117, 0.0006714, 0.0007057,
0.0007706, 0.0006943, 0.000717, 0.00074, 0.000801, 0.0007973,
0.0009003, 0.0007477, 0.0007706, 0.0006447, 0.0006027, 0.000931,
0.000778, 0.000702],
[0.0006294, 0.0007324, 0.000641, 0.0005913, 0.000656, 0.0006905,
0.0006866, 0.000801, 0.000725, 0.0007477, 0.0005646, 0.0006943,
0.0007133, 0.000679, 0.000622, 0.0007477, 0.0005493, 0.000599,
0.0006332, 0.000572, 0.000595, 0.0006104, 0.0006714, 0.000656,
0.0007477, 0.0006104, 0.000637, 0.000534, 0.0005035, 0.0007706,
0.0006485, 0.00058],
[0.0007744, 0.0009003, 0.0007935, 0.0007324, 0.0007973, 0.000847,
0.000824, 0.000992, 0.0008926, 0.0009155, 0.0006943, 0.0008583,
0.0008698, 0.000824, 0.000763, 0.000923, 0.0006714, 0.000717,
0.000778, 0.0007095, 0.000736, 0.0007477, 0.000828, 0.000801,
0.0009003, 0.000759, 0.000801, 0.00066, 0.0006104, 0.000942,
0.0007935, 0.000717],
[0.0006638, 0.0007706, 0.0006714, 0.000622, 0.000683, 0.0007286,
0.000717, 0.000847, 0.0007553, 0.000786, 0.000595, 0.0007324,
0.0007553, 0.000698, 0.0006485, 0.0007896, 0.0005875, 0.000618,
0.0006638, 0.000614, 0.0006332, 0.000641, 0.000702, 0.0006866,
0.000782, 0.000641, 0.000683, 0.000557, 0.0005264, 0.0008087,
0.0006866, 0.0006027],
[0.0005875, 0.000679, 0.000599, 0.000534, 0.0006027, 0.000641,
0.000622, 0.00074, 0.0006638, 0.000698, 0.000519, 0.000641,
0.000656, 0.000622, 0.000572, 0.0006943, 0.0005074, 0.000538,
0.0005875, 0.000538, 0.000557, 0.000572, 0.0006256, 0.0006104,
0.0006866, 0.00058, 0.0006104, 0.0005035, 0.000475, 0.0007095,
0.0005913, 0.000534],
[0.000576, 0.000683, 0.000595, 0.000553, 0.000614, 0.000641,
0.0006332, 0.0007324, 0.000683, 0.0006866, 0.0005302, 0.000656,
0.0006485, 0.000641, 0.0005875, 0.0007095, 0.000511, 0.000557,
0.000595, 0.000538, 0.0005493, 0.000572, 0.000622, 0.000614,
0.0006943, 0.000572, 0.0005836, 0.0004997, 0.0004654, 0.000717,
0.0006027, 0.0005493],
[0.0006485, 0.000763, 0.000656, 0.000614, 0.000683, 0.000721,
0.000702, 0.000824, 0.0007553, 0.000786, 0.0005875, 0.000717,
0.0007324, 0.000702, 0.000656, 0.0007935, 0.000576, 0.0006104,
0.0006638, 0.0006027, 0.000618, 0.000641, 0.000702, 0.0006943,
0.000763, 0.0006485, 0.0006714, 0.0005646, 0.0005226, 0.0007935,
0.0006866, 0.0006065],
[0.0003777, 0.0004425, 0.000389, 0.0003643, 0.0004005, 0.0004234,
0.000412, 0.0004845, 0.0004482, 0.000454, 0.0003452, 0.0004253,
0.000431, 0.0004215, 0.0003834, 0.0004692, 0.0003414, 0.0003662,
0.000393, 0.0003586, 0.0003624, 0.0003777, 0.0004082, 0.000412,
0.000452, 0.0003738, 0.0003853, 0.000328, 0.0003052, 0.000473,
0.0004005, 0.0003624],
[0.0005264, 0.000618, 0.0005493, 0.0005035, 0.0005493, 0.0005875,
0.00058, 0.0006866, 0.000614, 0.0006332, 0.0004787, 0.000595,
0.0006104, 0.000572, 0.0005302, 0.000641, 0.0004692, 0.000511,
0.0005417, 0.0004864, 0.0005074, 0.0005264, 0.0005684, 0.0005493,
0.0006256, 0.0005264, 0.0005493, 0.0004578, 0.000431, 0.0006523,
0.000557, 0.0005035],
[0.00041, 0.0004807, 0.0004292, 0.000391, 0.000431, 0.0004578,
0.0004501, 0.0005226, 0.000473, 0.0004845, 0.000372, 0.0004654,
0.0004692, 0.0004501, 0.0004158, 0.0004997, 0.00037, 0.000393,
0.0004196, 0.000389, 0.0003967, 0.0004063, 0.0004387, 0.0004387,
0.0004883, 0.0004044, 0.0004234, 0.0003529, 0.0003319, 0.000511,
0.0004349, 0.000389],
[0.00058, 0.000683, 0.000595, 0.0005455, 0.0006104, 0.000641,
0.0006256, 0.000744, 0.000675, 0.0006943, 0.000519, 0.000656,
0.0006676, 0.000618, 0.0005646, 0.000702, 0.0005264, 0.000538,
0.0005875, 0.0005417, 0.0005608, 0.000572, 0.0006256, 0.0006104,
0.0006905, 0.000576, 0.0006104, 0.000492, 0.0004654, 0.000717,
0.0006027, 0.0005417]], dtype=np.float16)

return {
"tp1": tp1,
"tp1_no_shared": tp1_no_shared,
"tp1_2_shared": tp1_2_shared,
}


GOLDEN_DATA = get_golden()

+ 4
- 4
tests/st/test_ut/test_parallel_core/test_inference/test_transformer/test_moe/run_infer_moe.py View File

@@ -23,6 +23,9 @@ from mindspore import Parameter, Tensor
import mindspore.common.dtype as mstype
from mindspore.communication import init, get_rank, get_group_size

from tests.st.test_ut.test_parallel_core.test_inference.test_transformer.test_moe.data_gen_utils import (
get_init_params,
)
from mindformers.parallel_core.transformer_config import TransformerConfig
from mindformers.parallel_core.utils.spec_utils import build_module
from mindformers.parallel_core.inference import parallel_state as ps
@@ -34,9 +37,6 @@ from mindformers.parallel_core.inference.utils import (
)
from mindformers.parallel_core.inference.tensor_parallel.mappings import gather_from_model_parallel_region

from tests.st.test_ut.test_parallel_core.test_inference.test_transformer.test_moe.data_gen_utils import (
get_init_params,
)

SCRIPT_DIR = Path(__file__).parent.resolve()

@@ -60,7 +60,7 @@ class MoERunner:
self.topk_group = self.args.topk_group

init_params = get_init_params(self.seq_len, self.batch_size, self.hidden_size,
self.num_experts, self.moe_intermediate_size)
self.num_experts, self.moe_intermediate_size, self.n_shared_experts)

self.input = ms.Tensor(init_params.pop("input"), dtype=mstype.bfloat16)
self.param_dict = init_params


+ 17
- 3
tests/st/test_ut/test_parallel_core/test_inference/test_transformer/test_moe/test_infer_moe.py View File

@@ -18,13 +18,13 @@ import subprocess
import pytest
import numpy as np

from mindformers.tools.logger import logger

from tests.st.test_ut.test_parallel_core.test_inference.test_transformer.test_moe.data_gen_utils import (
get_init_params,
GOLDEN_DATA
)

from mindformers.tools.logger import logger


SINGLE_CARD_TEST_PARAM = "model_args, data_keys, expect_error"
SINGLE_CARD_TEST_CASES = [
@@ -56,6 +56,20 @@ SINGLE_CARD_TEST_CASES = [
{"output": "tp1_no_shared"},
False,
),
(
# 并行策略: 单卡
# 配置:seq_len: 4, batch_size: 4, hidden_size: 32, num_experts: 8,
# moe_intermediate_size: 8, moe_shared_expert_intermediate_size: 8,
# n_shared_experts: 2, routed_scaling_factor: 2.5, num_experts_per_tok: 2,
# n_group: 2, topk_group: 2
# expected result: 功能跑通, 精度对齐。
{"seq_len": 4, "batch_size": 4, "hidden_size": 32,
"moe_intermediate_size": 8, "num_experts": 8, "moe_shared_expert_intermediate_size": 16,
"n_shared_experts": 2, "routed_scaling_factor": 2.5, "num_experts_per_tok": 2,
"n_group": 2, "topk_group": 2},
{"output": "tp1_2_shared"},
False,
),
]


@@ -118,7 +132,7 @@ class TestInferMoE:
output_data = output_ms_dict.get(key)
input_data = get_init_params(
model_args["seq_len"], model_args["batch_size"], model_args["hidden_size"],
model_args["num_experts"], model_args["moe_intermediate_size"])["input"]
model_args["num_experts"], model_args["moe_intermediate_size"], model_args["n_shared_experts"])["input"]

assert output_data.shape == input_data.shape, \
(f"The shapes of output data and input data are different, "


Loading…
Cancel
Save
Baidu
map