JAX
扫码查看

Documentación sobre JAX, un marco informático de alto rendimiento para matrices.

JAX

In the fast-changing areas of machine learning and scientific computing, the two main factors that are highly needed are the speed of the operation and flexibility. The program called JAX, which comes from the Google Research team, is a highly known tool that has been coming up to the top of the list in the pursuit of speed-up in the numerical computing and deep learning areas. JAX has all the basic NumPy features, and on top of that, it introduces a very familiar language with some of the most advanced features such as automatic differentiation, enabling one to run machine learning workloads and code optimized for modern GPUs/TPUs and also with just-in-time compilation. This paper studies JAX in one's search for the most suitable way of using it, comparing the actual capability with the one claimed, and offering a simple tutorial suitable for freshmen in this subject.
What is JAX?
JAX is a powerful numeric computing library that expands NumPy functionality to incorporate various functions that enhance the productivity of modern machine learning and scientific computing. JAX, unlike older libraries, is centered around organizing function transfer, which helps to make the code the researcher and the engineer writes be both short and powerful. The main features of JAX are its support for automatic differentiation, hardware acceleration, and the ease of integration with the existing Python workflows.
Main Attributes of JAX
JAX is different from other number-crunching toolkits due to the following unique characteristics:
NumPy Compatibility: JAX supports most of the array operations that NumPy has to offer. Thus, users don’t have to throw away their old codes when they use Numpy operations and can also enjoy the benefits of GPU/TPU acceleration.
Automatic Differentiation: By providing reverse and forward-mode autodiff as part of the library, JAX lowers the barrier of entry to the laborious computation of gradients for machine learning and optimization applications.
Just-In-Time Compilation (JIT): One of the features of the jit decorator is the ability to compile Python functions directly to an efficient machine code which leads to the gain in performance by a lot.
Hardware Acceleration: Without any change in the code, JAX can work as smoothly on CPUs, GPUs, and TPUs both for simple and very large scale research tasks.
Function Transformations: Highly efficient tools like grad, vmap, and pmap not only can transform (and thus optimize) functions by vectorizing, parallelization, and automatic batching but also can do so in an easy and rapid manner.

Getting Started with JAX: A Basic Tutorial
Our goal in this instance is to provide a short example that will introduce JAX's automatic differentiation and JIT compilation features.
First of all, JAX should be installed via pip:
pip install jax jaxlib
Then, the required modules should be imported:
import jax
import jax.numpy as jnp
from jax import grad, jit
It's a good idea to pick up a function that is easy to understand and explain before you find the gradient of some function:
def f(x):
return 3 * x ** 2 + 2 * x + 1
df_dx = grad(f)
print(df_dx(2.0)) # Output: 14.0
The faster execution can now be granted by JIT compilation:
@jit
def fast_f(x):
return 3 * x ** 2 + 2 * x + 1
print(fast_f(2.0)) # Output: 17.0
This tutorial showcases more than just how good JAX is in finding gradients. Fitting such operations into core, JAX offers vmap and pmap for the work of batch or device parallelization purposes.
Conclusion
JAX is a major advance in the field of array computing, as it combines the ease of use of NumPy with the latest performance optimization. Although learning to deal with functional programming is a small obstacle to overcome, the extent of speed and adaptability of the resulting benefits is quite rewarding. Whether it is training machine learning models, scientific simulations, or mathematical functions optimization, JAX is the tool that will help in lifting the limits of what’s possible in Python.

FacebookXWhatsAppPinterestLinkedIn