AttributeError when linear_decoupled_in_proj is enabled
Checklist / 检查清单
- [x] I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。
Bug Description / Bug 描述
问题描述
在 linear_decoupled_in_proj 模式下,新创建的线性层(in_proj_qkvz 和 in_proj_ba)是在 super().__init__ 之后才创建的,没有被 DDP 正确处理,导致 main_grad 属性缺失。
当 gradient_accumulation_fusion 启用时,反向传播会访问 weight.main_grad.dtype,但由于 main_grad 是 None,会出现:
AttributeError: 'NoneType' object has no attribute 'dtype'
在 1.4 版本和 Qwen3.5 适配中,gradient_accumulation_fusion 是默认启用的(通过 --no-gradient-accumulation-fusion 可以禁用)。
临时解决通过配置 --no-gradient-accumulation-fusion 来避免这个问题。
How to Reproduce / 如何复现
mindspeed 0.16 megatron-core 0.16 mcore-bridge 1.4 ms-swift 4.2 Ascend 910B megatron sft qwen3.5 35b-a3b
Additional Information / 补充信息
No response
我这里测试没问题啊,DDP处理是在完整创建模型之后,不应该有这个问题啊。是sft嘛
这个和 [https://github.com/modelscope/mcore-bridge/pull/109(url) 都是megatron pt场景, 没有用FLA算子,配置如下
export USE_MCORE_GDN=1 export TASK_QUEUE_ENABLE=2 megatron pt \ --tensor_model_parallel_size 4 \ --pipeline_model_parallel_size 4 \ --context_parallel_size 1 \ --expert_model_parallel_size 2 \ --model_type qwen3_5 \ --sequence_parallel true \ --use_distributed_optimizer true \ --optimizer_cpu_offload true \ --micro_batch_size 1 \ --global_batch_size 2 \ --recompute_granularity full \ --recompute_method uniform \ --recompute_num_layers 20 \ --cross_entropy_loss_fusion true \ --lr 1e-4 \ --lr_warmup_fraction 0.05 \ --min_lr 1e-5 \ --num_train_epochs 1 \ --max_length 8196 \ --dataloader_num_workers 4 \ --no_save_optim true \ --no_save_rng true \ --dataset_num_proc 4 \