Trading off compute for memory with activation checkpointing
A whole-graph activation checkpointing planner for torch.compile takes an absolute GB memory budget and greedily drops min-cut saves with the cheapest recompute cost per byte of peak memory freed. Before training, a planning pass on fake tensors captures every graph, its min-cut save set and the execution order. Peak memory is simulated from tensor liveness across stacked forward and backward graphs, and recompute time is estimated from FLOP formulas. On single-graph models it beat PyTorch's memory-budget knapsack and op-level SAC policies for most budgets, avoided recompute-induced peak spikes, and still lacks support for dynamic shapes, data-dependent ops and RNG ops.
Related posts
- What the interns have wrought, special jumbo 2026 edition
Jane Street Tech Blog easyNoviceJane Street's 2026 interns shipped projects across ML research, software engineering, Linux engineering, IT, trading desk operations and strategy. Highlights include an activation checkpointing scheme that beats PyTorch's by greedily recomputing the nodes with the cheapest recompute cost per byte freed in the torch.compile dynamo graph, and a dense topic index for tip recovery in the Aria messaging framework that cut CPU use by 30%. Other projects include an OCaml-native FUSE server for the Depot object store reaching 1.3 GiB/s, and a kernel log reporter that falls back to pstore when disk and network fail. Research work covered diffusion models of market data and reducing memorization in LLMs, and an OxCaml SPMD DSL targets CPU SIMD instructions.
- Visualize and understand GPU memory in PyTorch
Hugging Face mediumAdeptPyTorch's memory snapshot recorder (torch.cuda.memory._record_memory_history plus the memory_viz web tool) makes it possible to see exactly where GPU memory goes during training: persistent parameters, activations that grow in the forward pass and shrink in backward, gradients, optimizer state and transient optimizer intermediates. Profiling a Qwen2.5-1.5B training loop shows the peak can come from either the forward pass or the optimizer step depending on batch size. The resulting estimate is total memory = parameters + optimizer state (2×N×P for AdamW) + the larger of activations or gradients plus optimizer intermediates. Activations per token can be measured with forward hooks or approximated by a linear fit against parameter count (A ≈ 4.69e-4×N + 1.85e6).
- Make your ZeroGPU Spaces go brrr with ahead-of-time compilation
Hugging Face mediumAdeptPyTorch ahead-of-time compilation (torch.export plus AOTInductor) suits ZeroGPU Spaces, where each GPU task runs in a short-lived forked process and torch.compile's just-in-time caching costs tens of seconds to minutes per task. The workflow captures example inputs with spaces.aoti_capture, exports and compiles the transformer inside a @spaces.GPU function, then patches it into the pipeline with spaces.aoti_apply, giving 1.3–1.8× speedups on Flux, Wan and LTX (1.7× on FLUX.1-dev). Further gains come from FP8 dynamic quantization via torchao (about 1.2× more on H200), dynamic shapes via torch.export.Dim, per-resolution multi-compile with shared weights, and prebuilt FlashAttention-3 kernels from the kernels library.
- GPU Memory Snapshots: Supercharging sub-second startup
Modal mediumAdept
Modal's GPU memory snapshots extend its gVisor-based checkpoint/restore to capture GPU state, using NVIDIA's new CUDA checkpoint API (driver branches 570/575) to lock CUDA processes, copy device memory, kernels, streams, contexts and memory mappings to host memory, then snapshot CPU and GPU state together. Restoring skips expensive warm-up such as torch.compile, CUDA graph capture and moving weights from CPU to GPU, which removes the earlier split between pre- and post-restore setup methods. Reported cold starts drop by up to 10x, for example Parakeet from about 20s to 2s, vLLM with Qwen2.5-0.5B from 45s to 5s, and a compiled ViT from 8.5s to 2.25s. The feature is in alpha and is enabled with an experimental flag.
- Profiling in PyTorch (Part 1): A Beginner's Guide to torch.profiler
Hugging Face mediumAdepttorch.profiler produces two artifacts: a statistical table showing where time goes and a Chrome/Perfetto trace showing when CPU and GPU events happen. A small 64x64 bf16 matmul+add is overhead-bound, with GPU time under 1% of CPU time, while 4096x4096 matrices shift the work to compute-bound GEMM kernels. The trace walkthrough explains a cold-start dead window of about 228 µs before aten::matmul dispatch, a CPU-GPU lane offset, gaps caused by profiler Activity Buffer Requests, and the dispatch chain from Python down to CUDA kernels. The practical advice is to warm up, use profiler schedules, and read Self versus total times carefully before turning to torch.compile.