Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/flax/language-modeling/run_clm_flax.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ def data_loader(rng: jax.random.PRNGKey, dataset: Dataset, batch_size: int, shuf
steps_per_epoch = len(dataset) // batch_size

if shuffle:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patil-suraj - I think here we could actually switch to jax.random.permutation as this is called only once per epoch. I'm pretty sure that it wouldn't slow down the training

batch_idx = np.random.permutation(len(dataset))
batch_idx = jax.random.permutation(rng, len(dataset))
else:
batch_idx = np.arange(len(dataset))
batch_idx = jnp.arange(len(dataset))

batch_idx = batch_idx[: steps_per_epoch * batch_size] # Skip incomplete batch.
batch_idx = batch_idx.reshape((steps_per_epoch, batch_size))
Expand Down