Profiling in PyTorch (Part 2): From nn.Linear to a Fused MLP
AI-generated summary of reporting by Huggingface Blog. Read the original for the full story.
Why it matters
PyTorch engineers learn that torch.compile adds nothing for a single linear layer because bias is already fused as a GEMM epilogue, changing where optimization effort is worth spending.
Hugging Face published the second part of a tutorial series on reading PyTorch profiler traces, using an NVIDIA A100 GPU. It shows that a basic building block of neural networks, the linear layer, already fuses its math into one GPU operation, so the popular speedup tool torch.compile adds nothing there. The article then stacks three such layers into a network called an MLP and shows how combining operations into one kernel saves memory traffic. It matters to anyone training or serving AI models who wants their code to run faster.
This Hugging Face tutorial teaches engineers to profile PyTorch code on an A100 GPU and find that the reflex of reaching for torch.compile is wasted on single linear layers, since bias addition is already fused into the cuBLAS matmul kernel. Real gains come from fusing operations across multi-layer blocks, as torch.compile does for an MLP, or from hand-tuned kernels. Teams paying for GPU time gain the most; there is no cost, product or timing news here.
Part 2 of Hugging Face's profiling series traces nn.Linear on an A100-SXM4-80GB, showing aten::t is a zero-cost stride-view (no GPU kernel), and that aten::addmm dispatches a cuBLAS GEMM with bias-add as an epilogue, so torch.compile only removes CPU dispatch overhead, not GPU work. Kernel names like cutlass_80_..._tn_align8 encode layout (tn), dtype and tile. A GeGLU MLP (768/3072 dims, batch 64, seq 128) runs five kernels per forward, each GEMM ~38.7 GFLOP, with down_proj ~10% faster due to different N-shape tiling. Scripts 02_linear.py and 03_simple_mlp.py are provided.
Read the original
This summary exists to save you time, not to replace the source.
Key terms
PyTorch torch.compile nn.Linear NVIDIA A100-SXM4-80GB cuBLAS GeGLU Triton
Was this summary useful?
One click, anonymous. It tells us which summaries to re-run.
Related reading
Samsung is testing a feature that changes the angle of photos you’ve already taken
Samsung’s new Recompose lets users change photo angles after shooting, potentially reducing the need for multiple shots and improving post-capture editing workflows for photographers and casual users alike.
Code-driven AI illustrations are more useful than images from dedicated image models
Code-driven AI illustrations let designers edit assets directly in code, saving time on iteration and ensuring consistency, which is a game-changer for teams that need rapid, reusable visual content.
datasette-charts 0.5a0
Datasette Charts 0.5a0 adds calendar heatmaps, box plots and active-over-time charts, enabling richer data visualisation directly in the browser without extra libraries.
A hierarchical note-taking app for building large personal knowledge bases
Trilium lets users build and navigate massive personal knowledge bases without duplicating content, saving time on organization and retrieval.
Desktop apps in Go with native UI or web frontend
Go developers can now ship cross-platform desktop and mobile apps in a single small binary without cgo or heavy runtimes, cutting build complexity and deployment size.