In machine learning, especially in deep learning, batch size refers to the number of training examples used in one iteration of model training. The training data is divided into multiple batches, and the model processes each batch sequentially during training.
For LLM (Language Model) training, the batch size is the number of sequences processed together in one forward pass. The choice of batch size can impact the speed and stability of the training process. Larger batch sizes may lead to more stable gradients and faster training, but they also require more memory.
In the case of predicting a sequence with 100 tokens, if you set the batch size to 1, the model will process each token one by one, and the forward pass will run 100 times. If you set the batch size to 10, the model will process 10 tokens at a time, and the forward pass will run 10 times. The gradient is computed for each batch and used to update the model's weights.
The gradient accumulation is a technique used to handle large batch sizes that do not fit into the available memory. Instead of processing the large batch at once, the model processes smaller batches and accumulates gradients over multiple forward passes. After a certain number of forward passes, the accumulated gradients are used to update the model's weights.
In summary, the batch size is the number of sequences processed together in one forward pass during LLM training. The choice of batch size depends on the available memory and desired training stability and speed. Gradient accumulation can be used to handle larger batch sizes when memory constraints are present.