Fireship · @fireship
JAX in 100 Seconds
Uploaded June 3, 2024 · Length 3:24
Summary
JAX is an accelerated linear algebra library for Python that enables fast numerical computing on hardware like GPUs and TPUs, with features like immutable arrays and automatic differentiation.
- jax library
- linear algebra
- gpu computing
- tpu computing
- autograd
- machine learning
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
Jax it's just another accelerated linear
- 0:03
algebra library but capable of mega fast
- 0:05
numerical Computing on futuristic new
- 0:08
hardware to understand Jax let's start
- 0:10
with the x or accelerated linear algebra
- 0:12
in Python there's already a great linear
- 0:14
algebra Library called numpy and Jax is
- 0:17
nearly identical to numpy it allows you
- 0:19
to create multi-dimensional arrays then
- 0:21
do scientific Computing with them like
- 0:23
add them together or get the dot product
- 0:25
however Jax enforces some constraints
- 0:27
that numpy does not have like immutable
- 0:29
arrays and pure functions which allows
- 0:31
it to automatically compile to low-level
- 0:34
code that can run on accelerated
- 0:35
Hardware like gpus and tpus the a stands
- 0:38
for autograd Jax was developed by Google
- 0:41
along with team members from the
- 0:42
original autograd Library you see
- 0:44
virtually every facet of machine
- 0:45
learning requires some calculus you'll
- 0:47
need to compute gradients for
- 0:49
optimization algorithms and back
- 0:51
propagation and neural networks and
- 0:52
autograd allows you to automatically
- 0:54
differentiate python functions or in
- 0:56
simple terms it calculate the rate of
- 0:58
change of a function based on its inputs
- 1:01
then finally the J stands for just in
- 1:03
time compilation when you write a
- 1:04
function in Jax it's transformed into a
- 1:07
primitive set of operations these
- 1:08
so-called Jack spers are lazily compiled
- 1:11
and can be evaluated like a mini
- 1:13
functional programming language to get
- 1:14
started install Jacks either for your
- 1:16
CPU GPU or TPU and now we can start
- 1:19
doing high performance array Computing
- 1:21
let's first create a couple of
- 1:22
two-dimensional arrays now in numpy if I
- 1:24
wanted to change the values in an array
- 1:26
I could mutate the data structure
- 1:27
directly but in Jax that's an error
- 1:29
because arrays are immutable instead we
- 1:31
use the at function to select an index
- 1:33
then set to change the value and return
- 1:35
a new array from there we can do some
- 1:37
linear algebra like element wise
- 1:39
addition element wise multiplication or
- 1:41
get the dot product of the two arrays
- 1:43
what's really cool about Jack though is
- 1:45
automatic differentiation imagine you're
- 1:47
building a high yield nuclear warhead in
- 1:49
your mom's basement you'll likely write
- 1:50
a python function that looks like this
- 1:52
that calculates the height of the
- 1:53
mushroom cloud based on the amount of
- 1:55
time after detonation this will give us
- 1:57
the height at any point in time but we
- 1:59
also want to know the instantaneous rate


