braintools.trainer.create_distributed_batches#
- braintools.trainer.create_distributed_batches(data, batch_size, devices=None, shuffle=False, seed=None)[source]#
Create batches suitable for distributed training with pmap.
- Parameters:
- Yields:
Any – Batches with shape (num_devices, batch_size, …).
Notes
Only full blocks of
num_devices * batch_sizesamples are yielded; any trailing samples that cannot fill a complete block are dropped (this keeps the leading device axis a fixed size forpmap). Size the data orbatch_sizeaccordingly if you cannot afford to drop the remainder.Examples
>>> for batch in create_distributed_batches(X, batch_size=32): ... # batch.shape == (num_devices, 32, ...) ... outputs = pmap_train_step(batch)