Skip to content

Add data loaders tutorial#5454

Open
samanklesaria wants to merge 1 commit into
google:mainfrom
samanklesaria:dataloader_docs
Open

Add data loaders tutorial#5454
samanklesaria wants to merge 1 commit into
google:mainfrom
samanklesaria:dataloader_docs

Conversation

@samanklesaria
Copy link
Copy Markdown
Collaborator

This PR ports the Jax AI stack DataLoader tutorial to the flax docs. I've completely rewritten the tutorial, however, to focus entirely on dataloaders, leaving the model creation and jax transformations to other tutorials. This is part of the workstream outlined in #5433

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

You should be familiar with how to write a training loop from the [MNIST Example](https://flax.readthedocs.io/en/stable/mnist_tutorial.html). For this tutorial, we'll use a dummy training step that takes in 4-D image arrays and 1-D label vectors. Our goal in data loading will be to create these tensors, implementing the `get_batches` generator below.

```python outputId="c51838df-69ad-4d81-e577-5bbe95f8f6e7"
!pip install jaxtyping
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we add this as a docs dependency instead?

```python
def get_pt_batches(ds):
for image, label in train_dataloader:
yield jnp.array(image, dype=jnp.float32), jnp.array(label)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe we could recommend jax.dlpack.from_dlpack here?


```python
data_loader = grain.DataLoader(
data_source=splits['train'],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could be good to recreate splits again in this section to make it a bit more self contained.

Copy link
Copy Markdown
Collaborator

@cgarciae cgarciae left a comment

Choose a reason for hiding this comment

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

Looks good! Left some comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants