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

Fixed batch_size_per_device and batch_size misuse in LazyLLM #377

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

JingofXin
Copy link
Contributor

Background

This PR addresses the issue of the incorrect usage of batch_size_per_device and batch_size. In the transformers code, the total_train_batch_size is calculated as total_train_batch_size = _train_batch_size * gradient_accumulation_steps * world_size.
Here, _train_batch_size corresponds to batch_size_per_device in Llamafactory, which is similar to a micro_batch_size.

Code in Transformers:
image

Log in Llamafactory and Code in Transformers:
image

Solve

To resolve this, in LazyLLM, I have fixed gradient_accumulation_steps to 1. Given a batch_size, the correct calculation for batch_size_per_device should be batch_size_per_device // n_gpus. This ensures that the batch size is properly distributed across the available GPUs.

Verify

  • 2 GPUs OOM:
    企业微信截图_17332106802115

  • 4 GPUs OK:
    企业微信截图_17332106059677

@wzh1994 wzh1994 merged commit b8bea00 into LazyAGI:main Dec 3, 2024
4 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