Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the displayed loss in the sft trainer for gradient accumulation > 1 #102

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

hiyouga
Copy link
Contributor

@hiyouga hiyouga commented Jan 13, 2025

What does this PR do?

This PR mainly fixes the display loss value in the fsdp_sft_trainer. We should sum up the scaled values rather than directly use the scaled one. By the way, we also performed an all reduce operation to average the loss values among DP nodes.

Environment

  • Python version: 3.10.12
  • PyTorch version: 2.5.1+cu124 (GPU)
  • Transformers version: 4.47.1
  • GPU type: NVIDIA H100
  • vLLM version: 0.6.6.post1

Reproduction

torchrun --standalone --nnodes=1 --nproc_per_node=4 \
     -m verl.trainer.fsdp_sft_trainer \
    data.train_files=$HOME/data/gsm8k/train.parquet \
    data.val_files=$HOME/data/gsm8k/test.parquet \
    data.prompt_key=prompt \
    data.response_key=answer \
    data.micro_batch_size=8 \
    model.partial_pretrain=meta-llama/Meta-Llama-3-8B-Instruct \
    trainer.project_name=gsm8k-sft \
    trainer.experiment_name=llama3_gsk8k_before_fix \
    trainer.total_epochs=4 \
    trainer.logger=['console','wandb']

The training loss of Llama-3 8B on the GSM8K dataset should be larger than 0.5, while the bugged version has much lower loss values.

image

Who can review?

@PeterSH6

@vermouth1992 vermouth1992 merged commit e230de8 into volcengine:main Jan 14, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants