What is batch size and how does it affect training?

Answer

Batch size is the number of training examples used in one forward/backward pass before updating the model weights. Full-batch gradient descent uses all data — stable but very slow. Stochastic GD (batch size = 1) is noisy but can escape local minima. Mini-batch GD (typical sizes: 32, 64, 128) balances stability and speed, and leverages GPU parallelism efficiently. Larger batches produce smoother gradient estimates but may converge to sharper minima with worse generalization (the "generalization gap" phenomenon).