2200: Deep Learning Frameworks¶
One stack, three viewpoints — how frameworks execute your model (dynamic graphs), how compilers optimize it (XLA), and how the hardware actually computes it (CUDA kernels).
Contents¶
- Module Overview
- Learning Objectives
- Module Contents
- Learning Path
- Prerequisites
- Assessment
- Related Modules
- Time Commitment
- Resources
- Tips for Success
- Common Pitfalls
- Summary
- References
- Next Steps
Module Overview¶
Frameworks are the layer you touch every day as an ML engineer — and the layer you debug when training slows down, memory runs out, or a kernel underperforms. This module takes PyTorch's dynamic graphs, TensorFlow's XLA compiler, and CUDA's execution model apart so the machinery is no longer a black box.
Why This Matters:
- Every training and inference system you will build runs on top of these frameworks
- Debugging performance means reading what the framework, the compiler, and the GPU each did to your model
- Custom autograd functions and custom kernels are how research code escapes framework limits
- Understanding static vs dynamic graphs and AOT vs JIT compilation explains why frameworks behave so differently
Learning Objectives¶
After completing this module, you will be able to:
- Graph Models: Explain dynamic vs static computational graphs and pick the right mental model for a debugging session
- Autograd Internals: Inspect
.grad_fngraphs and write customtorch.autograd.Functionsubclasses - Compiler Thinking: Enable and profile XLA, understand operation fusion and HLO, and reason about what compilers can and cannot do
- GPU Literacy: Describe the CUDA execution model, the memory hierarchy, and tensor cores well enough to profile and tune kernels
- Performance Diagnosis: Move from a slow model to a hypothesis about dispatch, fusion, or memory — with evidence
Module Contents¶
Each lesson is written around runnable code — work through the examples, don't just read them.
Lesson 2201 — How Frameworks Execute: PyTorch's Dynamic Graphs¶
2201: PyTorch Computational Graphs and Dynamic Execution
- Dynamic vs static graphs — and what each trades away
- Computational graph construction and
grad_fninternals - Dynamic control flow and custom autograd functions
- Graph optimization, debugging, and memory management
Lesson 2202 — How Compilers Optimize: TensorFlow and XLA¶
2202: TensorFlow XLA and Compiler Optimizations
- What XLA is and how to enable it (JIT and AOT)
- Operation fusion and HLO (High-Level Operations) instructions
- Memory optimization and GPU compilation with tensor cores
- Performance profiling, best practices, and troubleshooting
Lesson 2203 — How the Hardware Computes: CUDA Kernels¶
2203: CUDA Kernel Programming and GPU Architecture
- GPU architecture overview and the CUDA execution model
- Writing CUDA kernels and the memory hierarchy
- PyTorch CUDA integration and tensor core programming
- Optimization techniques and CUDA debugging
Learning Path¶
- Verify readiness with 2200: Deep Learning Frameworks - Prerequisites
- 2201: PyTorch Computational Graphs and Dynamic Execution — dynamic graphs, autograd internals, custom functions
- 2202: TensorFlow XLA and Compiler Optimizations — fusion, HLO, profiling with XLA
- 2203: CUDA Kernel Programming and GPU Architecture — execution model, memory hierarchy, kernels
- Check understanding with the 2200: Frameworks - Quiz, then apply it with the 2200: Frameworks - Practice exercises
Prerequisites¶
Required:
- Comfortable Python — classes, decorators, and context managers (the framework's control surface)
- Autograd basics from 2102:
requires_grad,.backward(),.grad, and why graphs matter - Tensor fundamentals: shapes, broadcasting, and device placement
Helpful:
- A CUDA GPU for the GPU sections of 2202/2203 — every code example runs on CPU where noted, and GPU blocks are clearly marked and optional; no CUDA toolchain is required (PyTorch ships its own kernels)
- C++ or another systems-language exposure, for 2203's kernel listings
Review: 2200: Deep Learning Frameworks - Prerequisites for detailed requirements with runnable self-check examples.
Assessment¶
Knowledge Check¶
- 2200: Frameworks - Quiz — 20 questions across the three lessons, 80% (16/20) to pass
Practice Exercises¶
- Format: Hands-on coding exercises
- Duration: 4-6 hours
- Topics:
- Build custom autograd functions and inspect graph internals
- Enable XLA and measure fusion effects
- Profile a small model and attribute time to dispatch, memory, or kernels
- Location: 2200: Frameworks - Practice
Related Modules¶
- 2100: Calculus for Deep Learning — the backward-pass math these frameworks automate
- 2300: Framework Engineering — turn framework knowledge into engineered training systems
- 2400: LLM Pretraining — run the stack at pretraining scale
- 3100: Attention Architectures — graph and kernel behavior inside attention workloads
- 4100: Low-Bit Quantization — compiler and kernel implications of quantized compute
Time Commitment¶
| Activity | Time |
|---|---|
| Lesson 2201 (PyTorch graphs) | 4 hours |
| Lesson 2202 (XLA compilers) | 4 hours |
| Lesson 2203 (CUDA kernels) | 4 hours |
| Quiz | 1 hour |
| Practice | 4-6 hours |
| Total | 17-19 hours |
Resources¶
Essential Reading:
- PyTorch Tutorials — official tutorials; the autograd and nn.Module walkthroughs map onto Lesson 2201
- TensorFlow Tutorials — official tutorials; XLA integration context for Lesson 2202
- CUDA Programming Guide (NVIDIA) — the reference behind Lesson 2203
Optional:
- XLA: Accelerated Linear Algebra (OpenXLA) — the compiler's own overview, architecture, and backends
- PyTorch Internals (Edward Z. Yang) — tensor structure, dispatch, autograd, and the codebase layout
Tips for Success¶
- Inspect, don't trust: print
.grad_fnchains until graph construction feels concrete - Compare the three layers: run the same model through autograd, XLA, and a hand-written kernel mental model
- Profile before optimizing: every performance claim in these lessons starts with a measurement
- Keep GPU code optional: the CPU paths teach the same concepts; use a GPU when you have one
- Read the framework source: the PyTorch internals essay makes the codebase navigable
Common Pitfalls¶
- Memorizing framework APIs instead of the execution model: APIs change; dispatch, graphs, and kernels persist
- Assuming fusion is free: compilers change numerics slightly (float32 rounding), and not every fusion is profitable
- Mixing devices silently: a CPU tensor next to a CUDA tensor is the most common runtime error in this module
- Optimizing without a baseline: measure first — 2202's profiling sections exist for a reason
Summary¶
- This module explains the machinery under every training run from three angles: how frameworks execute (dynamic graphs), how compilers optimize (XLA), and how GPUs compute (CUDA kernels) — closed by a quiz and hands-on practice.
- Everything core is runnable on CPU with PyTorch; GPU and XLA sections are marked and optional.
- Plan for 17-19 hours (12 hours lessons + 1 hour quiz + 4-6 hours practice).
- Position in Phase 2: 2100 taught the math these frameworks automate, 2200 the machinery itself, and 2300 turns that machinery into engineered training systems.
References¶
Related Documents¶
- 2201: PyTorch Computational Graphs and Dynamic Execution — dynamic graphs, autograd internals
- 2202: TensorFlow XLA and Compiler Optimizations — fusion, HLO, profiling
- 2203: CUDA Kernel Programming and GPU Architecture — execution model, memory hierarchy
- 2200: Deep Learning Frameworks - Prerequisites — readiness check with runnable self-test examples
- EXP_2201: PyTorch Computational Graphs — hands-on graph exercises
- EXP_2202: TensorFlow XLA Optimization — hands-on XLA exercises
- EXP_2203: CUDA Kernels — hands-on CUDA exercises
- 2300: Framework Engineering — the next module that builds on this one
External References¶
- PyTorch Tutorials — official PyTorch tutorials
- TensorFlow Tutorials — official TensorFlow tutorials
- CUDA Programming Guide — NVIDIA
- XLA: Accelerated Linear Algebra — OpenXLA project
- PyTorch Internals — Edward Z. Yang
Next Steps¶
- Not reviewed yet? Start with 2200: Deep Learning Frameworks - Prerequisites and run its self-check examples.
- Work the lessons in order: 2201: PyTorch Computational Graphs and Dynamic Execution → 2202: TensorFlow XLA and Compiler Optimizations → 2203: CUDA Kernel Programming and GPU Architecture — each layer builds on the previous one.
- Close the loop: take the quiz, then the practice exercises.
- Continue to the next module: 2300: Framework Engineering
Related: 2201: PyTorch Computational Graphs and Dynamic Execution · 2202: TensorFlow XLA and Compiler Optimizations · 2203: CUDA Kernel Programming and GPU Architecture
Experiment: No EXP_22xx overview exists — start from EXP_2201: PyTorch Computational Graphs (the hands-on companion to Lesson 2201).