Okay, let's break down the batch size parameters used in the PPO training setup for NeMo-Aligner, based on the provided files.
Here's an explanation of global_batch_size, micro_batch_size, rollout_samples_size, and rollout_micro_batch_size, and how they relate to each other within the context of PPO training:
1. global_batch_size
- Definition: This parameter represents the total number of samples processed across all GPUs in the data parallel group during one optimization step. It is also referred to as
gbs.
- Scope: It's a global concept and is not dependent on the micro-batching strategy.
- Usage:
- In
train_gpt_ppo_actor.py, the global_batch_size is used to create a dummy dataloader to infer the number of training steps.
- In
megatron_gpt_ppo_actor.py, global_batch_size is used to configure batch sizes and calculate the number of microbatches.
- Relationship to other parameters:
global_batch_size is distributed across data parallel ranks by dividing it by the data parallel world size. This is done when creating the dummy training dataloader and calculating the number of microbatches in the actor model forward pass.
2. micro_batch_size
- Definition: This is the number of samples processed in one forward and backward pass on a single GPU. It is also referred to as
mbs. It is used for optimizing the actor model
- Scope: Local to a single GPU.
- Usage:
- In
megatron_gpt_ppo_actor.py, micro_batch_size is used to calculate the number of microbatches for the actor model forward pass.
- In
megatron_gpt_ppo_actor.py, micro_batch_size is also used to calculate the number of microbatches for the log probability calculation.
- Relationship to other parameters:
- The
global_batch_size is divided by the data parallel world size and further divided into micro_batch_size. Each micro-batch is processed independently before gradients are accumulated.
3. rollout_samples_size
- Definition: This parameter represents the total number of samples generated during the rollout phase across all GPUs in the data parallel group. It's the total number of environment interactions (prompts) that the policy explores before doing the PPO update. Also referred to as
num_rollout_samples or gbs in the dataloader creation
- Scope: It's a global concept and is not dependent on the micro-batching strategy during rollout.
- Usage:
- In
train_gpt_ppo_actor.py, it's used when creating the training dataloader via the build_dataloader function. This determines the number of prompts to generate rollouts from per PPO step.
- In
ppo.py, this parameter is not directly referenced, but the number of samples from the dataloader is extracted and is used for PPO training
- Relationship to other parameters:
- The
rollout_samples_size is divided across the data parallel group in the dataloader.
- The number of microbatches for generation is indirectly related to
rollout_samples_size via the rollout_micro_batch_size.
4. rollout_micro_batch_size
- Definition: This is the number of samples generated in one forward pass on a single GPU for the rollout phase. It is also referred to as
mbs during dataloader creation. This parameter is only used when creating the training data for PPO.
- Scope: Local to a single GPU during the rollout phase.
- Usage:
- In
train_gpt_ppo_actor.py, it is used when creating the train and validation dataloaders via the build_dataloader function to generate the responses for the prompts.
- In
ppo.py, it's used to compute the number of microbatches for the data loader.
- In
megatron_gpt_ppo_actor.py, it's used to compute the number of microbatches for the log probability calculation.
- Relationship to other parameters:
rollout_micro_batch_size is used in conjunction with rollout_samples_size to control the memory usage of the rollout phase.
- The number of microbatches for generation is calculated using
rollout_samples_size and rollout_micro_batch_size, and the data parallel size.
In Summary
global_batch_size: Overall training batch size for the actor model (across all GPUs).
micro_batch_size: The actual batch size used in the forward/backward pass on a single GPU for the actor model. The global_batch_size is split across micro batches to help with memory.
rollout_samples_size: Overall number of samples generated for PPO training (across all GPUs).
rollout_micro_batch_size: The actual batch size used to generate samples on a single GPU during the rollout phase. The rollout_samples_size is split across micro batches to help with memory.
The relationship between these parameters is crucial for efficient training. The global_batch_size and rollout_samples_size determine the amount of data processed, while the micro-batch sizes control memory usage on individual GPUs. The dataloader distributes the global_batch_size and rollout_samples_size across the data parallel group.