Grain - Feeding JAX Models
Installation | Quickstart | Reference docs | Change logs
Grain is a Python library for reading and processing data for training and evaluating JAX models. It is flexible, fast and deterministic.
Grain allows to define data processing steps in a simple declarative way:
import grain
dataset = (
grain.MapDataset.source([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
.shuffle(seed=42) # Shuffles elements globally.
.map(lambda x: x+1) # Maps each element.
.batch(batch_size=2) # Batches consecutive elements.
)
for batch in dataset:
# Training step.
Grain is designed to work with JAX models but it does not require JAX to run and can be used with other frameworks as well.
Installation
Grain is available on PyPI and can be
installed with pip install grain.
Supported platforms
Grain does not directly use GPU or TPU in its transformations, the processing within Grain will be done on the CPU by default.
| Linux | Mac | Windows | |
|---|---|---|---|
| x86_64 | yes | no | yes |
| aarch64 | yes | yes | n/a |
Quickstart
Citing Grain
To cite this repository:
@software{grain2023github,
author = {Marvin Ritter and Ihor Indyk and Aayush Singh and Andrew Audibert and Anoosha Seelam and Camelia Hanes and Eric Lau and Jacek Olesiak and Jiyang Kang and Xihui Wu},
title = {{Grain} - Feeding JAX Models},
url = {http://github.com/google/grain},
version = {0.2.12},
year = {2023},
}
The version number is intended to be that from pyproject.toml, and the year corresponds to the project's open-source release.
Existing users
Grain is used by MaxText, Gemma, kauldron, maxdiffusion and multiple internal Google projects.
Release files for grain 0.2.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| grain-0.2.18-cp314-cp314-win_amd64.whl | CPython 3.14 | CPython 3.14 | Windows x86-64 | Details |
| grain-0.2.18-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl | CPython 3.14 | CPython 3.14 | Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 | Details |
| grain-0.2.18-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl | CPython 3.14 | CPython 3.14 | Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 | Details |
| grain-0.2.18-cp314-cp314-macosx_11_0_arm64.whl | CPython 3.14 | CPython 3.14 | macOS 11.0+ ARM64 | Details |
| grain-0.2.18-cp313-cp313-win_amd64.whl | CPython 3.13 | CPython 3.13 | Windows x86-64 | Details |
| grain-0.2.18-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| grain-0.2.18-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.24+ ARM64, Linux glibc 2.28+ ARM64 | Details |
| grain-0.2.18-cp313-cp313-macosx_11_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 11.0+ ARM64 | Details |
| grain-0.2.18-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details |
| grain-0.2.18-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 | Details |
| grain-0.2.18-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 | Details |
| grain-0.2.18-cp312-cp312-macosx_11_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64 | Details |
| grain-0.2.18-cp311-cp311-win_amd64.whl | CPython 3.11 | CPython 3.11 | Windows x86-64 | Details |
| grain-0.2.18-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| grain-0.2.18-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.24+ ARM64, Linux glibc 2.28+ ARM64 | Details |
| grain-0.2.18-cp311-cp311-macosx_11_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 11.0+ ARM64 | Details |
Total release size: 9.3 MB
Release files / grain-0.2.18-cp314-cp314-win_amd64.whl
| Download URL | grain-0.2.18-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 547.8 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
fe83461d55e81c9c9cdba3d9d9ed0185db7b41cddb8e28223aa495ca3516877c
|
|
BLAKE2b-256 checksum How to use checksums |
a2c8d3f559b3691559054d57779ce9e9dbb832c7631b622e94c8c092ce26ca18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | grain-0.2.18-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 610.2 kB |
| Tags | CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
fc7204490aff21620fbdbd69e088991a4ae1ebc31586456191c11f9f61a8c0e6
|
|
BLAKE2b-256 checksum How to use checksums |
b760b257f1173a6c71c67a1de81798427a7e73ceb71cd6573ccccf7f528018f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
| Download URL | grain-0.2.18-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 610.9 kB |
| Tags | CPython 3.14 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
09bef4e8290d06e79cfddc71e777d0b5f60316e5a43af61f8a3d0e6a2d9feccc
|
|
BLAKE2b-256 checksum How to use checksums |
0f3107c861e8b0a782d2b17b3e8a7b9191420d30d4a9ce86a9882502d4d883eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | grain-0.2.18-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 554.4 kB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5986e756a0803012a74af4d34a506ed2877f6a86b8d1164227e8a67e09af1688
|
|
BLAKE2b-256 checksum How to use checksums |
3cde14532d47c14bcfaeb79878621ea4f28863df60ec1ce29f43a9781a1a2167
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp313-cp313-win_amd64.whl
| Download URL | grain-0.2.18-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 539.9 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
8d74e3f33403146fb9da0b101d7d18148e3979f5adc8d625237524cc144c0d24
|
|
BLAKE2b-256 checksum How to use checksums |
d4edd491cd9e6406d4eca43443939c6b303f8cd66386f861988813ed92038e01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | grain-0.2.18-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 610.2 kB |
| Tags | CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
61290a4af38fbddac41d6da1d19129df498dece53c3de4cc02e7ec557a0b0024
|
|
BLAKE2b-256 checksum How to use checksums |
9bf30d3269dd6796c187f808708b381f6d85a62e5022f45f00c938a7f3a605f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
| Download URL | grain-0.2.18-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 610.9 kB |
| Tags | CPython 3.13 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
229683c7714c3275cc4fee6cbc7356d47769eeaa286fbdc6af7a9542dcb468e5
|
|
BLAKE2b-256 checksum How to use checksums |
60d5590925b5fdf33218dde9f72322b88b65f4043c6a6a06cd00520465ac6915
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | grain-0.2.18-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 554.3 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
bec1c551574d3a1885ea0d1481586b4c2490a1332120bf626b459e2f9a6f1d06
|
|
BLAKE2b-256 checksum How to use checksums |
a23d6ad2033ae65145bcef635741c0d351bfe18a6a241b803766490a432551ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp312-cp312-win_amd64.whl
| Download URL | grain-0.2.18-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 539.8 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
c8a29696d98b2e84d8531df211006b2187475af7cebc45408023da6aa3ac1494
|
|
BLAKE2b-256 checksum How to use checksums |
ee4b7ec021e2385094ab31f6e6dad3e6f5bb2251dff5c3543934c347ba7ada3e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | grain-0.2.18-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 610.2 kB |
| Tags | CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
1ecd87427b4050b695f9b9b5a41d8058208586d3f90a2e56f14a64f920aa47f8
|
|
BLAKE2b-256 checksum How to use checksums |
5686237d99cc246f87536ca3f3764fe94e2e364dababfe382ad227f3153079de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
| Download URL | grain-0.2.18-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 610.9 kB |
| Tags | CPython 3.12 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
1eb8f8424d3844944d1c37248b0430a5598b21f7ec5141119e0a70069edbd943
|
|
BLAKE2b-256 checksum How to use checksums |
c56013bf95936145419a4673f33262d239477e1dc7da30d1a576945e2cba84af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | grain-0.2.18-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 554.3 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1bcff4c0ec71cee0b8c26076e3b60d83897cd7586b8f182291969743fd79a7b9
|
|
BLAKE2b-256 checksum How to use checksums |
1f2059fb32fd6aadc40e0dbde586a62903646ad778413c78280ea8d1e18e73de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp311-cp311-win_amd64.whl
| Download URL | grain-0.2.18-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 539.6 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
c16f4001983bee52a5a08e43569f46343815697d12da344ba6509af898fbca79
|
|
BLAKE2b-256 checksum How to use checksums |
26713be5abc17985d678b08e9d2258248c70e9dfe41cdf374584227033c294b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | grain-0.2.18-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 611.6 kB |
| Tags | CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
08a80a029f8b9c84af9424540d91cf8e4e91fe092e0fb7e0bb460dcf0042f659
|
|
BLAKE2b-256 checksum How to use checksums |
453b1d52db9abf0b28344a209a6f351a68b4bdf62e4fef0f6a11ea91a0e4520d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
| Download URL | grain-0.2.18-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 612.6 kB |
| Tags | CPython 3.11 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
cf9b9cfc59180b549c74307fd2ef5bc6f545ab78538b7661a5cfad71177d8418
|
|
BLAKE2b-256 checksum How to use checksums |
d6a8c6a447fbf8d381bee37bf0b6e93fb86fe4dd30b8154ee912797308f24cba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / grain-0.2.18-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | grain-0.2.18-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 556.4 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
dda2c25d2590e8aae180d58a92525945b31f71e59637a8fe37c2d1e4e502beb5
|
|
BLAKE2b-256 checksum How to use checksums |
55928cf5d07cac2a24c0670f9a7e64f1cac1288c183221f516be3bcae7d0d1e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|