mindspore-ai / mindspore-ai/hyper-parallel

[Bug]: 分片后的 Qwen GatedDeltaNet 参数初始化发生 shape mismatch

Open
#602 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
53
Forks
63
Avg merge
23h 45m
Merged PRs (30d)
63

Description

Checklist
  • 1. I have searched the existing issues (https://gitcode.com/mindspore/hyper-parallel/issues)
  • 2. I have read the relevant documentation.
  • 3. I have created a minimal reproduction case that clearly demonstrates the issue, including a complete code example and the error message with full traceback and error logs.
🐛 Describe the bug

_materialize_and_load_model 在模型参数完成 sharding 后调用 Transformers
模型自身的初始化逻辑。

对于 Qwen3.5、Qwen3.5-MoE、Qwen3-Next 等包含 GatedDeltaNet 的模型,
A_logdt_bias 已经是本地 shard,但 Transformers _init_weights
仍按照全局 num_v_heads 创建临时 Tensor。

例如:

init.copy_(
    module.A_log,
    torch.empty(module.num_v_heads, device=module.A_log.device)
        .uniform_(0.01, 16)
        .log_(),
)

此时目标参数使用 local shape,源 Tensor 使用 global shape,导致
copy_ 报 shape mismatch。

此外,不同 Transformers 版本包含的模型集合不同。例如项目依赖的
Transformers 5.13 尚不包含 Qwen4Exp,直接导入相关实现会在测试收集或
运行期间触发 ModuleNotFoundError。

Expected behavior
  • 默认模型继续使用 Transformers 原生权重初始化。
  • 存在分片初始化问题的模型可以注册 family-local、shard-aware 初始化函数。
  • 模型 adapter 声明最低 Transformers 版本。
  • 当前 Transformers 版本低于最低版本时,不注册该模型,也不加载其实现。
  • 最低版本及更高版本均应注册,即使用 installed >= minimum。
Additional context

自定义初始化实现应位于对应模型目录中,避免引入跨模型共享的初始化组件。

Environment info
  • Transformers: 5.13.0
  • PyTorch: 2.9.0
  • torch_npu: 2.9.0
  • Hardware: Ascend 910B3

Thanks for contributing 🎉!

schema_version: 1
source: gitcode
gitcode_repo: mindspore/hyper-parallel
gitcode_issue: 393
source_url: https://gitcode.com/mindspore/hyper-parallel/issues/393

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at _materialize_and_load_model and trace how sharded parameters reach the Transformers _init_weights path for GatedDeltaNet models. Compare the local shapes of A_log and dt_bias with the temporary tensors created from global num_v_heads, and inspect adapter registration and minimum-version checks. Done means default initialization remains native, affected model families can use shard-aware initialization, and unsupported Transformers versions neither register nor load them.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.