Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.5%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: actionseval
- License: apache-2.0
- Language: Python
- Default Branch: main
- Size: 16.6 MB
Statistics
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
Transformable numerical computing at scale
Transformations | Scaling | Install guide | Change logs | Reference docs
What is JAX?
JAX is a Python library for accelerator-oriented array computation and program transformation, designed for high-performance numerical computing and large-scale machine learning.
JAX can automatically differentiate native
Python and NumPy functions. It can differentiate through loops, branches,
recursion, and closures, and it can take derivatives of derivatives of
derivatives. It supports reverse-mode differentiation (a.k.a. backpropagation)
via jax.grad as well as forward-mode differentiation,
and the two can be composed arbitrarily to any order.
JAX uses XLA
to compile and scale your NumPy programs on TPUs, GPUs, and other hardware accelerators.
You can compile your own pure functions with jax.jit.
Compilation and automatic differentiation can be composed arbitrarily.
Dig a little deeper, and you'll see that JAX is really an extensible system for composable function transformations at scale.
This is a research project, not an official Google product. Expect sharp edges. Please help by trying it out, reporting bugs, and letting us know what you think!
```python import jax import jax.numpy as jnp
def predict(params, inputs): for W, b in params: outputs = jnp.dot(inputs, W) + b inputs = jnp.tanh(outputs) # inputs to the next layer return outputs # no activation on last layer
def loss(params, inputs, targets): preds = predict(params, inputs) return jnp.sum((preds - targets)**2)
gradloss = jax.jit(jax.grad(loss)) # compiled gradient evaluation function perexgrads = jax.jit(jax.vmap(gradloss, inaxes=(None, 0, 0))) # fast per-example grads ```
Contents
- Transformations
- Scaling
- Current gotchas
- Installation
- Neural net libraries
- Citing JAX
- Reference documentation
Transformations
At its core, JAX is an extensible system for transforming numerical functions.
Here are three: jax.grad, jax.jit, and jax.vmap.
Automatic differentiation with grad
Use jax.grad
to efficiently compute reverse-mode gradients:
```python import jax import jax.numpy as jnp
def tanh(x): y = jnp.exp(-2.0 * x) return (1.0 - y) / (1.0 + y)
gradtanh = jax.grad(tanh) print(gradtanh(1.0))
prints 0.4199743
```
You can differentiate to any order with grad:
```python print(jax.grad(jax.grad(jax.grad(tanh)))(1.0))
prints 0.62162673
```
You're free to use differentiation with Python control flow:
```python def abs_val(x): if x > 0: return x else: return -x
absvalgrad = jax.grad(absval) print(absvalgrad(1.0)) # prints 1.0 print(absvalgrad(-1.0)) # prints -1.0 (absval is re-evaluated) ```
See the JAX Autodiff Cookbook and the reference docs on automatic differentiation for more.
Compilation with jit
Use XLA to compile your functions end-to-end with
jit,
used either as an @jit decorator or as a higher-order function.
```python import jax import jax.numpy as jnp
def slow_f(x): # Element-wise ops see a large benefit from fusion return x * x + x * 2.0
x = jnp.ones((5000, 5000)) fastf = jax.jit(slowf) %timeit -n10 -r3 fastf(x) %timeit -n10 -r3 slowf(x) ```
Using jax.jit constrains the kind of Python control flow
the function can use; see
the tutorial on Control Flow and Logical Operators with JIT
for more.
Auto-vectorization with vmap
vmap maps
a function along array axes.
But instead of just looping over function applications, it pushes the loop down
onto the function’s primitive operations, e.g. turning matrix-vector multiplies into
matrix-matrix multiplies for better performance.
Using vmap can save you from having to carry around batch dimensions in your
code:
```python import jax import jax.numpy as jnp
def l1_distance(x, y): assert x.ndim == y.ndim == 1 # only works on 1D inputs return jnp.sum(jnp.abs(x - y))
def pairwise_distances(dist1D, xs): return jax.vmap(jax.vmap(dist1D, (0, None)), (None, 0))(xs, xs)
xs = jax.random.normal(jax.random.key(0), (100, 3)) dists = pairwisedistances(l1distance, xs) dists.shape # (100, 100) ```
By composing jax.vmap with jax.grad and jax.jit, we can get efficient
Jacobian matrices, or per-example gradients:
python
per_example_grads = jax.jit(jax.vmap(jax.grad(loss), in_axes=(None, 0, 0)))
Scaling
To scale your computations across thousands of devices, you can use any
composition of these:
* Compiler-based automatic parallelization
where you program as if using a single global machine, and the compiler chooses
how to shard data and partition computation (with some user-provided constraints);
* Explicit sharding and automatic partitioning
where you still have a global view but data shardings are
explicit in JAX types, inspectable using jax.typeof;
* Manual per-device programming
where you have a per-device view of data
and computation, and can communicate with explicit collectives.
| Mode | View? | Explicit sharding? | Explicit Collectives? | |---|---|---|---| | Auto | Global | ❌ | ❌ | | Explicit | Global | ✅ | ❌ | | Manual | Per-device | ✅ | ✅ |
```python from jax.sharding import setmesh, AxisType, PartitionSpec as P mesh = jax.makemesh((8,), ('data',), axistypes=(AxisType.Explicit,)) setmesh(mesh)
parameters are sharded for FSDP:
for W, b in params: print(f'{jax.typeof(W)}') # f32[512@data,512] print(f'{jax.typeof(b)}') # f32[512]
shard data for batch parallelism:
inputs, targets = jax.device_put((inputs, targets), P('data'))
evaluate gradients, automatically parallelized!
gradfun = jax.jit(jax.grad(loss)) param_grads = gradfun(params, (inputs, targets)) ```
See the tutorial and advanced guides for more.
Gotchas and sharp bits
See the Gotchas Notebook.
Installation
Supported platforms
| | Linux x8664 | Linux aarch64 | Mac aarch64 | Windows x8664 | Windows WSL2 x86_64 | |------------|--------------|---------------|--------------|----------------|---------------------| | CPU | yes | yes | yes | yes | yes | | NVIDIA GPU | yes | yes | n/a | no | experimental | | Google TPU | yes | n/a | n/a | n/a | n/a | | AMD GPU | yes | no | n/a | no | no | | Apple GPU | n/a | no | experimental | n/a | n/a | | Intel GPU | experimental | n/a | n/a | no | no |
Instructions
| Platform | Instructions |
|-----------------|-----------------------------------------------------------------------------------------------------------------|
| CPU | pip install -U jax |
| NVIDIA GPU | pip install -U "jax[cuda12]" |
| Google TPU | pip install -U "jax[tpu]" |
| AMD GPU (Linux) | Follow AMD's instructions. |
| Mac GPU | Follow Apple's instructions. |
| Intel GPU | Follow Intel's instructions. |
See the documentation for information on alternative installation strategies. These include compiling from source, installing with Docker, using other versions of CUDA, a community-supported conda build, and answers to some frequently-asked questions.
Citing JAX
To cite this repository:
@software{jax2018github,
author = {James Bradbury and Roy Frostig and Peter Hawkins and Matthew James Johnson and Chris Leary and Dougal Maclaurin and George Necula and Adam Paszke and Jake Vander{P}las and Skye Wanderman-{M}ilne and Qiao Zhang},
title = {{JAX}: composable transformations of {P}ython+{N}um{P}y programs},
url = {http://github.com/jax-ml/jax},
version = {0.3.13},
year = {2018},
}
In the above bibtex entry, names are in alphabetical order, the version number is intended to be that from jax/version.py, and the year corresponds to the project's open-source release.
A nascent version of JAX, supporting only automatic differentiation and compilation to XLA, was described in a paper that appeared at SysML 2018. We're currently working on covering JAX's ideas and capabilities in a more comprehensive and up-to-date paper.
Reference documentation
For details about the JAX API, see the reference documentation.
For getting started as a JAX developer, see the developer documentation.
Owner
- Login: actionseval
- Kind: user
- Repositories: 1
- Profile: https://github.com/actionseval
Citation (CITATION.bib)
@software{jax2018github,
author = {James Bradbury and Roy Frostig and Peter Hawkins and Matthew James Johnson and Chris Leary and Dougal Maclaurin and George Necula and Adam Paszke and Jake Vander{P}las and Skye Wanderman-{M}ilne and Qiao Zhang},
title = {{JAX}: composable transformations of {P}ython+{N}um{P}y programs},
url = {http://github.com/jax-ml/jax},
version = {0.3.13},
year = {2018},
}
GitHub Events
Total
- Push event: 2
- Create event: 2
Last Year
- Push event: 2
- Create event: 2
Dependencies
- actions/checkout v4 composite
- actions/setup-python v5 composite
- actions/checkout v4 composite
- actions/setup-python v5 composite
- actions/checkout v2 composite
- actions/setup-python v2 composite
- actions/checkout 11bd71901bbe5b1630ceea73d27597364c9af683 composite
- actions/setup-python a26af69be951a213d495a4c3e4e4022e16d87065 composite
- protobuf *
- tensorflow *
- xprof >=2.19.0
- numpy *
- numpy >=2.2.6
- numpy *
- numpy >=2.2.6
- portpicker *
- tensorstore *
- zstandard *
- build *
- colorama >=0.4.4
- etils *
- jax-cuda12-pjrt ==0.6.2
- jax-cuda12-plugin ==0.6.2
- jaxlib ==0.6.2
- libtpu *
- ml_dtypes >=0.4.0
- nvidia-cuda-nvrtc-cu12 >=12.1.55
- nvidia-nvshmem-cu12 >=3.2.5
- opt-einsum *
- scipy >=1.15.2
- scipy >=1.13.1
- setuptools *
- wheel *
- absl-py ==2.1.0
- attrs ==23.2.0
- auditwheel ==6.1.0
- build ==1.2.1
- cloudpickle ==3.0.0
- colorama ==0.4.6
- contourpy ==1.2.1
- cycler ==0.12.1
- etils ==1.8.0
- execnet ==2.1.1
- filelock ==3.14.0
- flatbuffers ==24.3.25
- fonttools ==4.51.0
- fsspec ==2024.5.0
- hypothesis ==6.102.4
- importlib-resources ==6.4.0
- iniconfig ==2.0.0
- jax-cuda12-pjrt ==0.6.2
- jax-cuda12-plugin ==0.6.2
- jaxlib ==0.6.2
- kiwisolver ==1.4.5
- libtpu ==0.0.13
- markdown-it-py ==3.0.0
- matplotlib ==3.9.0
- mdurl ==0.1.2
- ml-dtypes ==0.5.1
- mpmath ==1.4.0a1
- numpy ==2.0.0
- nvidia-cublas-cu12 ==12.8.3.14
- nvidia-cuda-cupti-cu12 ==12.8.57
- nvidia-cuda-nvcc-cu12 ==12.8.61
- nvidia-cuda-nvrtc-cu12 ==12.9.86
- nvidia-cuda-runtime-cu12 ==12.8.57
- nvidia-cudnn-cu12 ==9.8.0.87
- nvidia-cufft-cu12 ==11.3.3.41
- nvidia-cusolver-cu12 ==11.7.2.55
- nvidia-cusparse-cu12 ==12.5.7.53
- nvidia-nccl-cu12 ==2.25.1
- nvidia-nvjitlink-cu12 ==12.8.61
- nvidia-nvshmem-cu12 ==3.2.5
- opt-einsum ==3.3.0
- packaging ==24.0
- pillow ==11.0.0
- pluggy ==1.5.0
- portpicker ==1.6.0
- psutil ==5.9.8
- pyelftools ==0.31
- pygments ==2.18.0
- pyparsing ==3.1.2
- pyproject-hooks ==1.1.0
- pytest ==8.2.0
- pytest-xdist ==3.6.1
- python-dateutil ==2.9.0.post0
- rich ==13.7.1
- scipy ==1.13.1
- setuptools ==76.0.0
- six ==1.16.0
- sortedcontainers ==2.4.0
- tensorstore ==0.1.73
- typing-extensions ==4.12.0rc1
- wheel ==0.43.0
- zipp ==3.18.2
- zstandard ==0.22.0
- absl-py ==2.1.0
- attrs ==23.2.0
- auditwheel ==6.1.0
- build ==1.2.1
- cloudpickle ==3.0.0
- colorama ==0.4.6
- contourpy ==1.2.1
- cycler ==0.12.1
- etils ==1.8.0
- execnet ==2.1.1
- filelock ==3.14.0
- flatbuffers ==24.3.25
- fonttools ==4.51.0
- fsspec ==2024.5.0
- hypothesis ==6.102.4
- importlib-resources ==6.4.0
- iniconfig ==2.0.0
- jax-cuda12-pjrt ==0.6.2
- jax-cuda12-plugin ==0.6.2
- jaxlib ==0.6.2
- kiwisolver ==1.4.5
- libtpu ==0.0.13
- markdown-it-py ==3.0.0
- matplotlib ==3.9.0
- mdurl ==0.1.2
- ml-dtypes ==0.5.1
- mpmath ==1.4.0a1
- numpy ==2.0.0
- nvidia-cublas-cu12 ==12.8.3.14
- nvidia-cuda-cupti-cu12 ==12.8.57
- nvidia-cuda-nvcc-cu12 ==12.8.61
- nvidia-cuda-nvrtc-cu12 ==12.9.86
- nvidia-cuda-runtime-cu12 ==12.8.57
- nvidia-cudnn-cu12 ==9.8.0.87
- nvidia-cufft-cu12 ==11.3.3.41
- nvidia-cusolver-cu12 ==11.7.2.55
- nvidia-cusparse-cu12 ==12.5.7.53
- nvidia-nccl-cu12 ==2.25.1
- nvidia-nvjitlink-cu12 ==12.8.61
- nvidia-nvshmem-cu12 ==3.2.5
- opt-einsum ==3.3.0
- packaging ==24.0
- pillow ==11.0.0
- pluggy ==1.5.0
- portpicker ==1.6.0
- psutil ==5.9.8
- pyelftools ==0.31
- pygments ==2.18.0
- pyparsing ==3.1.2
- pyproject-hooks ==1.1.0
- pytest ==8.2.0
- pytest-xdist ==3.6.1
- python-dateutil ==2.9.0.post0
- rich ==13.7.1
- scipy ==1.13.1
- setuptools ==76.0.0
- six ==1.16.0
- sortedcontainers ==2.4.0
- tensorstore ==0.1.73
- typing-extensions ==4.12.0rc1
- wheel ==0.43.0
- zipp ==3.18.2
- zstandard ==0.22.0
- absl-py ==2.1.0
- attrs ==24.2.0
- auditwheel ==6.1.0
- build ==1.2.2.post1
- cloudpickle ==3.0.0
- colorama ==0.4.6
- contourpy ==1.3.0
- cycler ==0.12.1
- etils ==1.9.4
- execnet ==2.1.1
- filelock ==3.16.1
- flatbuffers ==24.3.25
- fonttools ==4.54.1
- fsspec ==2024.9.0
- hypothesis ==6.112.5
- importlib-resources ==6.4.5
- iniconfig ==2.0.0
- jax-cuda12-pjrt ==0.6.2
- jax-cuda12-plugin ==0.6.2
- jaxlib ==0.6.2
- kiwisolver ==1.4.7
- libtpu ==0.0.13
- markdown-it-py ==3.0.0
- matplotlib ==3.9.2
- mdurl ==0.1.2
- ml-dtypes ==0.5.1
- mpmath ==1.3.0
- numpy ==2.1.2
- nvidia-cublas-cu12 ==12.8.3.14
- nvidia-cuda-cupti-cu12 ==12.8.57
- nvidia-cuda-nvcc-cu12 ==12.8.61
- nvidia-cuda-nvrtc-cu12 ==12.9.86
- nvidia-cuda-runtime-cu12 ==12.8.57
- nvidia-cudnn-cu12 ==9.8.0.87
- nvidia-cufft-cu12 ==11.3.3.41
- nvidia-cusolver-cu12 ==11.7.2.55
- nvidia-cusparse-cu12 ==12.5.7.53
- nvidia-nccl-cu12 ==2.25.1
- nvidia-nvjitlink-cu12 ==12.8.61
- nvidia-nvshmem-cu12 ==3.2.5
- opt-einsum ==3.4.0
- packaging ==24.1
- pillow ==10.4.0
- pluggy ==1.5.0
- portpicker ==1.6.0
- psutil ==7.0.0
- pyelftools ==0.31
- pygments ==2.18.0
- pyparsing ==3.1.4
- pyproject-hooks ==1.2.0
- pytest ==8.3.3
- pytest-xdist ==3.6.1
- python-dateutil ==2.9.0.post0
- rich ==13.9.2
- scipy ==1.15.2
- setuptools ==76.0.0
- six ==1.16.0
- sortedcontainers ==2.4.0
- tensorstore ==0.1.73
- typing-extensions ==4.12.2
- wheel ==0.44.0
- zipp ==3.20.2
- zstandard ==0.23.0
- absl-py ==2.1.0
- attrs ==24.3.0
- auditwheel ==6.2.0
- build ==1.2.2.post1
- cloudpickle ==3.1.0
- colorama ==0.4.6
- contourpy ==1.3.1
- cycler ==0.12.1
- etils ==1.11.0
- execnet ==2.1.1
- filelock ==3.16.1
- flatbuffers ==24.12.23
- fonttools ==4.55.3
- fsspec ==2024.12.0
- hypothesis ==6.123.9
- importlib-resources ==6.5.2
- iniconfig ==2.0.0
- jax-cuda12-pjrt ==0.6.2
- jax-cuda12-plugin ==0.6.2
- jaxlib ==0.6.2
- kiwisolver ==1.4.8
- libtpu ==0.0.13
- markdown-it-py ==3.0.0
- matplotlib ==3.10.0
- mdurl ==0.1.2
- ml-dtypes ==0.5.1
- mpmath ==1.3.0
- numpy ==2.2.6
- nvidia-cublas-cu12 ==12.8.3.14
- nvidia-cuda-cupti-cu12 ==12.8.57
- nvidia-cuda-nvcc-cu12 ==12.8.61
- nvidia-cuda-nvrtc-cu12 ==12.9.86
- nvidia-cuda-runtime-cu12 ==12.8.57
- nvidia-cudnn-cu12 ==9.8.0.87
- nvidia-cufft-cu12 ==11.3.3.41
- nvidia-cusolver-cu12 ==11.7.2.55
- nvidia-cusparse-cu12 ==12.5.7.53
- nvidia-nccl-cu12 ==2.25.1
- nvidia-nvjitlink-cu12 ==12.8.61
- nvidia-nvshmem-cu12 ==3.2.5
- opt-einsum ==3.4.0
- packaging ==24.2
- pillow ==11.1.0
- pluggy ==1.5.0
- pyelftools ==0.31
- pygments ==2.19.1
- pyparsing ==3.2.1
- pyproject-hooks ==1.2.0
- pytest ==8.3.4
- pytest-xdist ==3.6.1
- python-dateutil ==2.9.0.post0
- rich ==13.9.4
- scipy ==1.15.2
- setuptools ==70.3.0
- six ==1.17.0
- sortedcontainers ==2.4.0
- typing-extensions ==4.12.2
- wheel ==0.45.1
- zipp ==3.21.0
- absl-py ==2.2.2
- attrs ==25.3.0
- auditwheel ==6.3.0
- build ==1.2.2.post1
- cloudpickle ==3.1.1
- contourpy ==1.3.2
- cycler ==0.12.1
- etils ==1.12.2
- execnet ==2.1.1
- filelock ==3.18.0
- flatbuffers ==25.2.10
- fonttools ==4.57.0
- fsspec ==2025.3.2
- hypothesis ==6.131.9
- importlib-resources ==6.5.2
- iniconfig ==2.1.0
- kiwisolver ==1.4.8
- markdown-it-py ==3.0.0
- matplotlib ==3.10.1
- mdurl ==0.1.2
- ml-dtypes ==0.5.1
- mpmath ==1.4.0a4
- numpy ==2.2.6
- nvidia-cublas-cu12 ==12.8.4.1
- nvidia-cuda-cupti-cu12 ==12.8.90
- nvidia-cuda-nvcc-cu12 ==12.8.93
- nvidia-cuda-runtime-cu12 ==12.8.90
- nvidia-cudnn-cu12 ==9.8.0.87
- nvidia-cufft-cu12 ==11.3.3.83
- nvidia-cusolver-cu12 ==11.7.3.90
- nvidia-cusparse-cu12 ==12.5.8.93
- nvidia-nccl-cu12 ==2.26.2.post1
- nvidia-nvjitlink-cu12 ==12.8.93
- opt-einsum ==3.4.0
- packaging ==25.0
- pillow ==11.2.1
- pluggy ==1.5.0
- portpicker ==1.6.0
- psutil ==7.0.0
- pyelftools ==0.32
- pygments ==2.19.1
- pyparsing ==3.2.3
- pyproject-hooks ==1.2.0
- pytest ==8.3.5
- pytest-xdist ==3.6.1
- python-dateutil ==2.9.0.post0
- rich ==14.0.0
- scipy ==1.15.2
- setuptools ==80.0.0
- six ==1.17.0
- sortedcontainers ==2.4.0
- tensorstore ==0.1.74
- typing-extensions ==4.13.2
- wheel ==0.45.1
- zipp ==3.21.0
- zstandard ==0.23.0
- absl-py ==2.1.0
- attrs ==24.3.0
- build ==1.2.2.post1
- flatbuffers ==24.12.23
- hypothesis ==6.123.9
- ml-dtypes ==0.5.1
- numpy *
- opt-einsum ==3.4.0
- packaging ==25.0
- pyproject-hooks ==1.2.0
- scipy *
- setuptools ==80.0.0
- sortedcontainers ==2.4.0
- wheel ==0.45.1
- absl-py * test
- auditwheel * test
- cloudpickle * test
- filelock * test
- flatbuffers * test
- hypothesis * test
- matplotlib * test
- mpmath >=1.3 test
- pillow >=10.4.0 test
- portpicker * test
- pytest-xdist * test
- rich * test
- absl-py *
- cmake *
- flatbuffers *
- ipython >=8.8.0
- matplotlib *
- myst-nb >=1.0.0
- numpy *
- pooch *
- pydata-sphinx-theme ==0.14.4
- pytest *
- pytest-xdist *
- rich *
- scikit-learn *
- snowballstemmer <3.0.0
- sphinx >=7.3.2,<8.0
- sphinx-book-theme ==1.1.1
- sphinx-copybutton >=0.5.0
- sphinx-design *
- sphinx-remove-toctrees *
- sphinxext-rediraffe *
- jax *
- flax *
- tensorflow_datasets *
- tensorflow_hub *
- ml_dtypes >=0.5.0
- numpy >=1.26
- scipy >=1.12
- jaxlib *
- ml_dtypes >=0.5.0
- numpy >=1.26
- opt_einsum *
- scipy >=1.12