Fireship · @fireship

JAX in 100 Seconds

Uploaded June 3, 2024 · Length 3:24

JAX in 100 Seconds

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.

  1. 0:00

    Jax it's just another accelerated linear

  2. 0:03

    algebra library but capable of mega fast

  3. 0:05

    numerical Computing on futuristic new

  4. 0:08

    hardware to understand Jax let's start

  5. 0:10

    with the x or accelerated linear algebra

  6. 0:12

    in Python there's already a great linear

  7. 0:14

    algebra Library called numpy and Jax is

  8. 0:17

    nearly identical to numpy it allows you

  9. 0:19

    to create multi-dimensional arrays then

  10. 0:21

    do scientific Computing with them like

  11. 0:23

    add them together or get the dot product

  12. 0:25

    however Jax enforces some constraints

  13. 0:27

    that numpy does not have like immutable

  14. 0:29

    arrays and pure functions which allows

  15. 0:31

    it to automatically compile to low-level

  16. 0:34

    code that can run on accelerated

  17. 0:35

    Hardware like gpus and tpus the a stands

  18. 0:38

    for autograd Jax was developed by Google

  19. 0:41

    along with team members from the

  20. 0:42

    original autograd Library you see

  21. 0:44

    virtually every facet of machine

  22. 0:45

    learning requires some calculus you'll

  23. 0:47

    need to compute gradients for

  24. 0:49

    optimization algorithms and back

  25. 0:51

    propagation and neural networks and

  26. 0:52

    autograd allows you to automatically

  27. 0:54

    differentiate python functions or in

  28. 0:56

    simple terms it calculate the rate of

  29. 0:58

    change of a function based on its inputs

  30. 1:01

    then finally the J stands for just in

  31. 1:03

    time compilation when you write a

  32. 1:04

    function in Jax it's transformed into a

  33. 1:07

    primitive set of operations these

  34. 1:08

    so-called Jack spers are lazily compiled

  35. 1:11

    and can be evaluated like a mini

  36. 1:13

    functional programming language to get

  37. 1:14

    started install Jacks either for your

  38. 1:16

    CPU GPU or TPU and now we can start

  39. 1:19

    doing high performance array Computing

  40. 1:21

    let's first create a couple of

  41. 1:22

    two-dimensional arrays now in numpy if I

  42. 1:24

    wanted to change the values in an array

  43. 1:26

    I could mutate the data structure

  44. 1:27

    directly but in Jax that's an error

  45. 1:29

    because arrays are immutable instead we

  46. 1:31

    use the at function to select an index

  47. 1:33

    then set to change the value and return

  48. 1:35

    a new array from there we can do some

  49. 1:37

    linear algebra like element wise

  50. 1:39

    addition element wise multiplication or

  51. 1:41

    get the dot product of the two arrays

  52. 1:43

    what's really cool about Jack though is

  53. 1:45

    automatic differentiation imagine you're

  54. 1:47

    building a high yield nuclear warhead in

  55. 1:49

    your mom's basement you'll likely write

  56. 1:50

    a python function that looks like this

  57. 1:52

    that calculates the height of the

  58. 1:53

    mushroom cloud based on the amount of

  59. 1:55

    time after detonation this will give us

  60. 1:57

    the height at any point in time but we

  61. 1:59

    also want to know the instantaneous rate