Minimal data loader for Flax
Project description
loaderx
Minimal data loader for Flax
Rationale for Creating mloader
While Flax supports various data loading backends—such as PyTorch, TensorFlow, Grain, and jax_dataloader—these often come with nontrivial dependencies.
- Installing heavy frameworks like PyTorch or TensorFlow solely for data loading is undesirable.
- Grain offers a clean API but suffers from suboptimal performance in practice.
- jax_dataloader leverages GPU memory by default, which may lead to inefficient memory usage in certain scenarios.
Design Goals of mloader
mloader is designed with simplicity and efficiency in mind. It follows a pragmatic approach—favoring low memory overhead and minimal dependencies. The implementation targets common use cases, with a particular focus on single-host training pipelines.
Current Limitations
At present, mloader only supports single-host scenarios and does not yet address multi-host training setups.
How to integrate it with Flax.
Below is a code example.
The mloader is mainly inspired by the design of Grain, so avoid using patterns like for epoch in num_epochs.
def loss_fn(model: CNN, batch):
logits = model(batch['data'])
loss = optax.softmax_cross_entropy_with_integer_labels(logits=logits, labels=batch['label']).mean()
return loss, logits
@nnx.jit
def train_step(model: CNN, optimizer: nnx.Optimizer, metrics: nnx.MultiMetric, batch):
"""Train for a single step."""
grad_fn = nnx.value_and_grad(loss_fn, has_aux=True)
(loss, logits), grads = grad_fn(model, batch)
metrics.update(loss=loss, logits=logits, labels=batch['label']) # In-place updates.
optimizer.update(grads) # In-place updates.
@nnx.jit
def eval_step(model: CNN, metrics: nnx.MultiMetric, batch):
loss, logits = loss_fn(model, batch)
metrics.update(loss=loss, logits=logits, labels=batch['label']) # In-place updates.
@nnx.jit
def pred_step(model: CNN, batch):
logits = model(batch['data'])
return logits.argmax(axis=1)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file loaderx-0.0.2.tar.gz.
File metadata
- Download URL: loaderx-0.0.2.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c75f26127887f67a0c0a8120767dd11a86e3edb7c8c2cde12a5fa7430b25b4b
|
|
| MD5 |
8236105d4ef7f162f21771f4c5c7f4d9
|
|
| BLAKE2b-256 |
944210c2a408f6e62ee92eeeb19b510be482688fccf88bb88bcd43cfc76c92f3
|
File details
Details for the file loaderx-0.0.2-py3-none-any.whl.
File metadata
- Download URL: loaderx-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e39a1d5a423f1758de065b4a700511bf9653657e2bfe0ff8bcb657d741dc718
|
|
| MD5 |
7963ef768261efedcbcb0157de0b8003
|
|
| BLAKE2b-256 |
4fae48c7abbafd398ef20143df7e9c72b57b148acd1a270adeae63c38648352c
|