glm5.3_flash训练dsa报oom

Open
#10,386 4 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@hjh0119 is already working on this.

Since Oct 19, 2026.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python, pytorch

Research direction

Start with packages/megatron/core/transformer/experimental_attention_variant/dsa.py around line 145 and the reported dsa_masking.py masked_softmax call around line 373. Check how the DSA attention computation handles the reported 16,384 token sequence and masking, then reproduce with the supplied training configuration. Done when training completes without the reported 4 GB CUDA allocation failure or a reproducible workaround is documented.

Written by the indexing model from the issue text.

Description

bug
Checklist / 检查清单
  • I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。
Bug Description / Bug 描述

训练过程中,64卡L20X,dsa的attention计算始终报oom,有办法绕过去吗?
packages/megatron/core/transformer/experimental_attention_variant/dsa.py", line 145, in _unfused_absorbed_dsa_fn
[rank38]: scores_chunk = dsa_masking.masked_softmax(scores_chunk.float(), valid_chunk, dim=-1)
[rank38]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank38]: File "/opt/nas/p/conda/envs/tcxia_swift_head/lib/python3.12/site-packages/megatron/core/transformer/experimental_attention_variant/dsa_masking.py", line 373, in masked_softmax
[rank38]: return probs.masked_fill(~valid_mask, 0.0)
[rank38]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank38]: torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 4.00 G

How to Reproduce / 如何复现

训练配置如下
python -m mcore_bridge.tools.apply_megatron_patch &&
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 megatron sft
--model $MODELPATH
--tuner_type full
--dataset $data
--loss_scale ignore_empty_think
--agent_template glm5_1
--tensor_model_parallel_size 2
--pipeline_model_parallel_size 2
--context_parallel_size 1
--expert_model_parallel_size 16
--moe_grouped_gemm true
--moe_aux_loss_coeff 1e-3
--micro_batch_size 1
--global_batch_size 64
--recompute_granularity full
--recompute_method uniform
--recompute_num_layers 2
--num_train_epochs 3
--finetune true
--cross_entropy_loss_fusion true
--lr 1e-5
--lr_warmup_fraction 0.05
--min_lr 1e-6
--save_total_limit 5
--output_dir $OUTPUTDIR
--save_steps 50
--max_length 16384
--packing true
--sequence_parallel true
--bf16 true
--dataloader_num_workers 8
--dataset_num_proc 8
--no_save_optim true
--no_save_rng true
--report_to swanlab
--swanlab_project $project_name
--swanlab_exp_name $exp_name
--attention_backend flash
--language_model_only true
--vit_attn_impl sdpa \

环境参数如下
megatron-core 0.19.0+ee743d3ef
mcore_bridge 1.7.0.dev0
transformers 5.19.0
ms_swift 4.6.0

Additional Information / 补充信息

No response

Dominant language
Python
Stars
16.2k
Forks
1.8k
Avg merge
1d 14h
Merged PRs (30d)
68

Getting set up

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.

More from modelscope/ms-swift

All issues in modelscope/ms-swift

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.