modelscope / modelscope/ms-swift

megatron 微调 qwen3vl-235b-a22b OOM

Open
#7,119 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
15.7k
Forks
1.7k
Avg merge
1d 16h
Merged PRs (30d)
136

Description

以下是我用megatron lora sft qwen3vl-235b-a22b 模型的配置(8x8H800-80G),但是如果seq_len调整到 32k以上会OOM,可以怎么优化么:

#!/bin/bash
set -euo pipefail
set -x

########################

自动分布式环境设置

NNODES=$WORLD_SIZE RANK=$RANK MASTER_ADDR=$MASTER_ADDR MASTER_PORT=$MASTER_PORT

########################

单机模式检测,如果没有 MASTER_ADDR,则默认为单机

if [ -z "${MASTER_ADDR:-}" ]; then
export MASTER_ADDR=127.0.0.1
export MASTER_PORT=$(shuf -n 1 -i 20000-65000)
export NNODES=1
export NODE_RANK=0
export NPROC_PER_NODE=8
export WORLD_SIZE=8
else
# 多机模式,平台需要提供 MASTER_ADDR, RANK, WORLD_SIZE
export MASTER_ADDR=$MASTER_ADDR
export MASTER_PORT=$MASTER_PORT
export NNODES=${WORLD_SIZE:-1} # 平台的WORLD_SIZE是节点数
export NODE_RANK=${RANK:-0} # 节点排名
export RANK=${RANK:-0}
export NPROC_PER_NODE=8 # 默认每个节点8张卡

fi

动态调整批处理大小(可选,根据节点数量调整)

MICRO_BATCH_SIZE=${MICRO_BATCH_SIZE:-1}

全局批处理大小应该根据节点数量进行调整

GLOBAL_BATCH_SIZE=${GLOBAL_BATCH_SIZE:-$((4 * NNODES))}

其他配置

export TF_CPP_MIN_LOG_LEVEL=3

echo "=== 分布式配置信息 ==="
echo "MASTER_ADDR: ${MASTER_ADDR}"
echo "MASTER_PORT: ${MASTER_PORT}"
echo "NNODES: ${NNODES}"
echo "NODE_RANK: ${NODE_RANK}"
echo "NPROC_PER_NODE: ${NPROC_PER_NODE}"
echo "TOTAL_PROCESSES: $((NNODES * NPROC_PER_NODE))"
echo "MICRO_BATCH_SIZE: ${MICRO_BATCH_SIZE}"
echo "GLOBAL_BATCH_SIZE: ${GLOBAL_BATCH_SIZE}"
echo "========================"

export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
export NCCL_DEBUG=INFO

export WANDB_NAME=1217_h800_8node_image_85w
export WANDB_API_KEY=""
export WANDB_PROJECT=default
export WANDB_MODE=online

image

export MAX_PIXELS=1003520

video

export VIDEO_MAX_TOKEN_NUM=64 # 256x256
export FPS_MAX_FRAMES=140

PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True'

export MEGATRON_LM_PATH='/Megatron-LM'
export MODELSCOPE_CACHE='/shared_8node'

$(which megatron) sft
--model /mnt/tidalfs-bdsz01/dataset/llm_ckpt/video_agent/models/Qwen3-VL-235B-A22B-Instruct
--load_safetensors true
--save_safetensors true
--dataset
/gaea_train/gaea_train_10w_msformat.jsonl
--load_from_cache_file true
--train_type lora
--lora_rank 8
--lora_alpha 32
--target_modules all-linear
--moe_permute_fusion true
--tensor_model_parallel_size 2
--expert_tensor_parallel_size 1
--expert_model_parallel_size $((8 * NNODES))
--moe_grouped_gemm true
--moe_shared_expert_overlap false
--moe_aux_loss_coeff 1e-3
--micro_batch_size ${MICRO_BATCH_SIZE}
--global_batch_size ${GLOBAL_BATCH_SIZE}
--recompute_granularity full
--recompute_method uniform
--recompute_num_layers 1
--max_epochs 1
--finetune true
--cross_entropy_loss_fusion true
--lr 1e-4
--lr_warmup_fraction 0.05
--min_lr 1e-5
--save 1217_h800_8node_image_85w
--eval_interval 8000
--save_interval 8000
--max_length 9000
--num_workers 4
--dataset_num_proc 4
--no_save_optim true
--no_save_rng true
--sequence_parallel true
--attention_backend flash
--model_author xiangyi
--model_name 1217_h800_8node_image_85w
--wandb-project $WANDB_PROJECT
--wandb-exp-name $WANDB_NAME

Contributor guide

Open the contributing guide

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 by reproducing the supplied Megatron SFT command with the listed 8x8 H800 configuration, comparing the reported sequence length above 32k with the command's --max_length 9000 setting. Inspect memory usage around recomputation, parallelism, MoE, and multimodal token limits. Done means identifying a reproducible cause and documenting a validated configuration or optimization that avoids OOM.

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
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.