🔒 7 more in the full analysis
Searchable transcript of Build and optimize JAX training loops — Google Cloud Tech (03:25). Search for a phrase, then click its timestamp to jump straight to that moment in the video.
Captions sourced from the original video on YouTube, published by Google Cloud Tech. The video, its captions and all related intellectual property remain the property of their respective owners; AINotes claims no ownership. Provided for research, accessibility and search — see the Transcript Notice and Copyright Policy.
00:00 In the last video, we learn how to tell whenever JAX is compiling, transferring, or really executing. Now, let's send a training job to the GPU. >> A clean JAX training step is a pure function. Parameters, optimizer step, and a batch goes in. New parameters, new optimizer step, and metrics come out. >> Before coding the model, be sure you prepare your data properly.
00:28 In our notebook example, we get shocked, normalized, reshaped, batched to a fixed size, and placed on the GPU. And again, fixed batches keep the compiled step reusable. >> The model we decided to start with is a small MLP. We did not pick it to win vision benchmarks and train a frontier model. The goal here is to see logits, cross-entropy, accuracy, gradients, and updates without getting overwhelmed by architectural details.
01:00 >> First, we do one update by end. So, the compiled version is transparent to you in the notebook. The JAX value and grad returns the loss and a gradient tree. The gradient tree has the same structure as the parameter tree. >> Then Optax AdamW gives us the practical optimizer pass. Same idea. Compute gradients, update optimizer state, apply updates.
01:26 JAX jit stages the whole step for the GPU. >> But here is when the code can quietly slow a loop down. Remember to not convert matrix to Python every step. Log occasionally, block intentionally, and keep the loop on the device. >> After training, evaluate on fixed test batches. Inspect predictions and check the confusion matrix. A useful loop tells you what the model is doing and not simply follows the loss curve.
01:56 Now, let's move from our simple MLP to one of the most common workloads of today models, the attention one. The attention is four moves: score Q against K, scale, softmax, and then mix B. Of course, implementation matters. Bear in mind that the naive attention mechanism, like the one as shown in the notebook, can lead inefficient behaviors on GPUs. In the notebook, the naive path materializes the full attention matrix.
02:30 That matrix grows with sequence length squared. So, the sequence length sweep is where we see dramatic changes on the latency curve. The default practical move is Let jax and XLA fuse the operations. On supported NVIDIA GPUs, implementation equal cuDNN can use fused cuDNN attention with BF16 or FP16 inputs. Decoder models need causal attention. Each token can only look backward.
03:05 For inference, MHA, GQA, and MQA all produce the same output shape, but have different KV cache costs. That causal attention is exactly what we plug into the transformer next.