modelscope / modelscope/ms-swift
qwen3vl megatron-bridge 和swift sft精度差异过大
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 1.7k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 136
Description
Checklist / 检查清单
- I have searched existing issues, and this is a new question or discussion topic. / 我已经搜索过现有的 issues,确认这是一个新的问题与讨论。
Question Description / 问题描述
使用官方镜像3.10.3,qwenvl-4b 5w数据, 单机8卡,分别用megatron sft (并行和无并行) 和swift sft 保持参数一致微调,测试均使用vllm,调用使用openai方式,测试mmbench,megatron训练精度在66左右,swift在76左右,差异10个点。
megatron 训练脚本:
PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True'
NPROC_PER_NODE=8
MAX_PIXELS=1638400
MIN_PIXELS=784
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
megatron sft
--model ./Qwen3-VL-4B-Instruct/
--load_safetensors true
--save_safetensors true
--dataset './5w.json'
--load_from_cache_file false
--pipeline_model_parallel_size 1
--tensor_model_parallel_size 1
--sequence_parallel false
--context_parallel_size 1
--packing false
--bf16 True
--freeze_vit true
--freeze_llm false
--freeze_aligner false
--micro_batch_size 1
--global_batch_size 8
--finetune false
--cross_entropy_loss_fusion false
--lr 1e-5
--lr_decay_style "cosine"
--lr_warmup_fraction 0.05
--weight_decay 0
--max_epochs 1
--save megatron_output/Qwen3-VL-4B-finetune_align
--save_interval 1000
--vit_gradient_checkpointing false
--max_length 8192
--num_workers 4
--dataset_num_proc 8
swift sft 训练脚本:
PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True'
NPROC_PER_NODE=8
IMAGE_MAX_TOKEN_NUM=1600
IMAGE_MIN_TOKEN_NUM=4
MAX_PIXELS=1638400
MIN_PIXELS=784
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
swift sft
--model ./Qwen3-VL-4B-Instruct/
--dataset '5w.json'
--load_from_cache_file false
--train_type full
--torch_dtype bfloat16
--num_train_epochs 1
--per_device_train_batch_size 1
--per_device_eval_batch_size 1
--attn_impl flash_attn
--freeze_vit true
--freeze_llm false
--freeze_aligner false
--packing false
--gradient_checkpointing true
--vit_gradient_checkpointing false
--gradient_accumulation_steps 1
--eval_strategy "no"
--save_steps 1000
--save_total_limit 5
--logging_steps 1
--max_length 8192
--max_grad_norm 1
--output_dir swift_output/swift_train_4b
--learning_rate 1e-5
--weight_decay 0
--warmup_ratio 0.05
--lr_scheduler_type "cosine"
--deepspeed zero2
--dataset_num_proc 4
--dataloader_num_workers 4
部署脚本:
CUDA_VISIBLE_DEVICES=0,1,2,3
MAX_PIXELS=1638400
MIN_PIXELS=784
VIDEO_MAX_PIXELS=1638400
FPS_MAX_FRAMES=32
TENSOR_PARALLEL_SIZE=4
swift deploy
--model "./checkpoint-6250"
--infer_backend vllm
--host 0.0.0.0
--port 9000
--vllm_gpu_memory_utilization 0.7
--vllm_max_model_len 50000
--vllm_tensor_parallel_size 4
--max_new_tokens 4096
--vllm_limit_mm_per_prompt '{"image": 5, "video": 2}'
--served_model_name "Qwen/Qwen3-VL-4B-Instruct"
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no source files or tests. Start by reproducing the two one-epoch runs from the provided Megatron SFT and Swift SFT commands with the same Qwen3-VL-4B data and settings, then compare preprocessing, optimization, checkpoint, and vLLM evaluation results. Done means identifying the cause of the roughly 10-point MMBench gap or documenting which configuration difference explains it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100