A deep dive into PyTorch profiling, tracing the evolution from a single nn.Linear layer to a fused MLP. Covers how nn.Linear uses addmm to fold bias addition into the GEMM epilogue, how torch.compile removes CPU dispatch overhead and fuses pointwise ops (GeLU + mul) into a single Triton kernel, and how hand-written Liger kernels from the Hugging Face Hub achieve the same fusion without compile latency or shape-specialization constraints. Includes detailed analysis of CUTLASS kernel naming conventions, tensor strides/views, occupancy queries, and HBM memory traffic reduction through kernel fusion.

17m read timeFrom huggingface.co
Post cover image
Table of contents
From matmul-add to LinearStacking three Linears: the MLPLet's use hand tuned kernelsConclusion
1.2K Impressions