Skip to main content

Jittable data loading utilities for JAX.

Project description

Cyreal - Another JAX DataLoader

grain for the corporations, cyreal for the people

Pure jax utilities for iterating over finite and infinite datasets without ever touching torch or tensorflow. Dataloaders are fast and support jax.jit, jax.grad, jax.lax.scan, and other function transformations.

Installation

pip install cyreal

The only dependency is jax.

Quick Start

Write fast dataloaders without torch or tensorflow

import jax
import jax.numpy as jnp

from cyreal.transforms import BatchTransform, DevicePutTransform
from cyreal.loader import DataLoader
from cyreal.sources import ArraySource
from cyreal.datasets import MNISTDataset

train_data = MNISTDataset(split="train").as_array_dict()
pipeline = [
  # Load dataset into memory-backed array
  ArraySource(train_data, ordering="shuffle"),
  # Batch it
  BatchTransform(batch_size=128),
  # Move the batch to the GPU
  DevicePutTransform(),
]
loader = DataLoader(pipeline)
state = loader.init_state(jax.random.key(0))
iterate = jax.jit(loader.next)

for epoch in range(2):
    for _ in range(loader.steps_per_epoch):
        batch, state, mask = iterate(state)
        ... # Train your network

Use scan_epoch to jit and avoid boilerplate

model_state = {"params": jnp.array(0)}

def update(model_state, batch, mask):
    model_state = {"params": model_state['params'] + 1}
    return model_state, None

for epoch in range(2):
    state, model_state, _ = loader.scan_epoch(state, model_state, update)

Examples and Documentation

See our documentation for more examples.

We also provide full end to end training examples

Speed Test

You can compare the speed to the grain dataloader using this script. This is how long it takes to iterate though one epoch of MNIST

MacBook M4 Pro

Library Dataset Device Batch Device Method Time (s)
grain CPU CPU Iterator 1.33
cyreal CPU CPU jit(loader.next) 0.04
cyreal CPU CPU scan_epoch 0.09

A40 with Wimpy CPU

Library Dataset Device Batch Device Method Time (s)
grain CPU CPU Iterator 10.34
grain CPU GPU Iterator 11.65
cyreal CPU CPU jit(loader.next) 0.66
cyreal CPU GPU jit(loader.next) 0.68
cyreal GPU GPU jit(loader.next) 0.66
cyreal CPU CPU scan_epoch 3.78
cyreal CPU GPU scan_epoch 4.00
cyreal GPU GPU scan_epoch 4.35

RTX 5090

Library Dataset Device Batch Device Method Time (s)
grain CPU CPU Iterator 3.80
grain CPU GPU Iterator 4.04
cyreal CPU CPU jit(loader.next) 0.50
cyreal CPU GPU jit(loader.next) 0.50
cyreal GPU GPU jit(loader.next) 0.50
cyreal CPU CPU scan_epoch 2.71
cyreal CPU GPU scan_epoch 2.72
cyreal GPU GPU scan_epoch 2.68

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cyreal-0.1.6.tar.gz (36.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cyreal-0.1.6-py3-none-any.whl (42.4 kB view details)

Uploaded Python 3

File details

Details for the file cyreal-0.1.6.tar.gz.

File metadata

  • Download URL: cyreal-0.1.6.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cyreal-0.1.6.tar.gz
Algorithm Hash digest
SHA256 ed2563505ce5305bb16b9715a87fd0cb69aae9d79629684331f8dd33e8863c8a
MD5 54e0e16c8e9550a9fced1d1150ea5aaa
BLAKE2b-256 bdbfe73fd8ebaa2ad23491e7fb93e784e31fe4e1eb424a99908c979bb025e3e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for cyreal-0.1.6.tar.gz:

Publisher: python-publish.yml on smorad/cyreal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cyreal-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: cyreal-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 42.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cyreal-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 589624d75b8c1d8019ed4f62a51427b56186160b5df02cbdc334305c4e0c5176
MD5 7f2ddb5aa0043edfb61acac276936ccc
BLAKE2b-256 480f22d5165c6cb1e564ce3c90b66408b685cf3de8f9300d4d32abebf4f62ff7

See more details on using hashes here.

Provenance

The following attestation bundles were made for cyreal-0.1.6-py3-none-any.whl:

Publisher: python-publish.yml on smorad/cyreal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page