modelscope / modelscope/ms-swift
使用chunked cross entropy对显存没有优化
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 1.7k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 136
Description
训练脚本如下
NPROC_PER_NODE=8
CELOSS_PARALLEL_SIZE=2048
swift sft
--model Qwen/Qwen2.5-3B-Instruct
--dataset 'AI-ModelScope/LongAlpaca-12k'
--load_from_cache_file true
--train_type lora
--torch_dtype bfloat16
--per_device_train_batch_size 4
--target_modules all-linear
--gradient_accumulation_steps 8
--save_total_limit 2
--save_only_model true
--save_steps 50
--max_length 65536
--warmup_ratio 0.05
--attn_impl flash_attn
--sequence_parallel_size 8
--logging_steps 1
--use_logits_to_keep false
--padding_free true
情况说明:
根据下行的资料显示,开启chunked cross entropy会对损失函数计算的显存占用有优化
https://github.com/meta-pytorch/torchtune/pull/1390
在当前版本中可以设定CELOSS_PARALLEL_SIZE、sequence_parallel_size等参数(参考上文的脚本)以启用CCE损失函数
swift/trainers/utils.py row:73
实际测试发现峰值显存”几乎“没有变化,峰值显存取自训练输出的logging.jsonl
测试显卡:华为、昆仑芯
测试模型:Qwen2.5的1.5B、3B和7B模型
测试参数变量:CELOSS_PARALLEL_SIZE改为过16、512、1024、2048(修改该参数会影响时间)
有人知道原因或做过类似的测试吗
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
Start by reading swift/trainers/utils.py around row 73, then run the supplied training command while varying CELOSS_PARALLEL_SIZE and recording peak memory from logging.jsonl. Compare the results across the listed Qwen2.5 model sizes and accelerator types; done means explaining why chunked cross entropy does or does not reduce peak memory, or identifying the relevant implementation issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100