Fixed batch_size_per_device and batch_size misuse in LazyLLM #377
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
This PR addresses the issue of the incorrect usage of
batch_size_per_device
andbatch_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 tobatch_size_per_device
in Llamafactory, which is similar to amicro_batch_size
.Code in Transformers:

Log in Llamafactory and Code in Transformers:

Solve
To resolve this, in LazyLLM, I have fixed
gradient_accumulation_steps
to 1. Given abatch_size
, the correct calculation forbatch_size_per_device
should bebatch_size_per_device // n_gpus
. This ensures that the batch size is properly distributed across the available GPUs.Verify
2 GPUs OOM:

4 GPUs OK:
