liveBook · Manning

Batch size

As explained in Transformers in Action

Batch size is the number of training examples processed in one forward and backward pass before a parameter update.

Batch size is the number of training examples used to calculate a gradient before the model updates its parameters. As a training hyperparameter, it influences convergence stability and speed alongside the learning rate and number of epochs. section 8.1.1

Batch size matters because it shapes each optimization step:

  • Larger or smaller batches change how many data points contribute to each gradient calculation, affecting convergence stability and speed. section 8.1.1
  • Training configuration balances batch size with available memory; gradient accumulation can help fit fine-tuning within limited VRAM. section 7.5
  • Batch size works with learning rate, epochs, and regularization choices rather than determining training quality in isolation. section 8.1.1

Translation fine-tuning configuration

A Gemma 3 270M English–Spanish fine-tuning workflow passes a batch-size variable into SFTConfig as per_device_train_batch_size=bs and combines it with gradient_accumulation_steps=gas. The configuration is designed to accommodate limited VRAM while training on formatted OPUS-100 examples. section 7.5

How Transformers in Action covers it

How deep it goes
Explains gradient contribution, convergence effects, and VRAM-aware configuration, but does not provide a batch-size selection procedure.
Examples
Uses OPUS-100 English–Spanish translation fine-tuning and an SFTConfig setting named per_device_train_batch_size.
What it assumes
Assumes familiarity with training examples and parameter updates while positioning batch size among gradient-descent hyperparameters.
What you can do after
Operate/configure fine-tuning through TRL SFTConfig while accounting for gradient accumulation and limited VRAM.
How it connects
Connects batch size with gradient descent, learning rate, epochs, gradient accumulation, fine-tuning, and overfitting.

Also explained in

Compare how 12 books explain batch size →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Transformers in Action. The section links point to the parts of the book it draws on.