---
title: "Profiling in PyTorch (Part 2): From nn.Linear to a Fused MLP"
description: "Profiling an nn.Linear on an A100 shows a single cuBLAS/CUTLASS GEMM kernel with the bias folded in as an epilogue via aten::addmm, while aten::t only rewrites strides on the CPU and launches nothing."
url: "https://swe.quest/articles/profiling-in-pytorch-part-2-from-nn-linear-to-a-fused-mlp-9b220b5d3b1f868e"
canonical: "https://huggingface.co/blog/torch-mlp-fusion"
source: "Hugging Face"
published: "2026-06-11"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 19
tags: ["performance","python","machine-learning","compilers"]
---

# Profiling in PyTorch (Part 2): From nn.Linear to a Fused MLP

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2026-06-11, 19 min read, Deep dive. Original: [https://huggingface.co/blog/torch-mlp-fusion](https://huggingface.co/blog/torch-mlp-fusion)

## Summary

Profiling an nn.Linear on an A100 shows a single cuBLAS/CUTLASS GEMM kernel with the bias folded in as an epilogue via aten::addmm, while aten::t only rewrites strides on the CPU and launches nothing. As a result, torch.compile has little to fuse for a lone Linear; it mainly removes CPU dispatch overhead by hard-coding strides, and the kernel's layout suffix (e.g. tn) shows how the transpose is absorbed. Stacking three Linears into a GeGLU MLP yields five kernels per forward pass: three GEMMs, each preceded by an occupancy query, plus separate GELU and multiply pointwise kernels. Reading kernel names and the profiler table shows which ops actually reach the GPU and where fusion could help.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Compilers](https://swe.quest/tags/compilers.md) (Compilers & runtimes)

## Prerequisites

- PyTorch basics
- GPU kernels and CUDA launches ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))
- torch.profiler traces
- matrix multiplication

## Keywords

PyTorch, torch.profiler, torch.compile, cuBLAS, CUTLASS, GeGLU, NVIDIA A100, TorchInductor

## Related posts

- [Profiling in PyTorch (Part 3): Attention is all you profile](https://swe.quest/articles/profiling-in-pytorch-part-3-attention-is-all-you-profile-44c4f73b7586bec2.md): Hugging Face · 2026-07-10 · Medium · 21 min read · Performance engineering, Inference & serving, Python, Hardware, LLMs
  Profiling attention variants in PyTorch on an A100 shows how each implementation appears in profiler traces.
- [Profiling in PyTorch (Part 1): A Beginner's Guide to torch.profiler](https://swe.quest/articles/profiling-in-pytorch-part-1-a-beginner-s-guide-to-torch-profiler-de0c791495fa22c4.md): Hugging Face · 2026-05-29 · Medium · 27 min read · Performance engineering, Machine learning, Python, Debugging
  torch.profiler produces two artifacts: a statistical table showing where time goes and a Chrome/Perfetto trace showing when CPU and GPU events happen.
- [Learn the Hugging Face Kernel Hub in 5 Minutes](https://swe.quest/articles/learn-the-hugging-face-kernel-hub-in-5-minutes-049114b1e85677a7.md): Hugging Face · 2025-06-12 · Medium · 13 min read · Inference & serving, Performance engineering, Python, Hardware
  Hugging Face's Kernel Hub and \`kernels\` library let PyTorch code download pre-compiled, optimized GPU kernels such as FlashAttention, activations, RMSNorm and quantization kernels with a single \`get\_kernel\` call.
- [Profiling TorchNeuron (Part 1): System-level profiling on AWS Trainium.](https://swe.quest/articles/profiling-torchneuron-part-1-system-level-profiling-on-aws-trainium-034696b775aee014.md): Hugging Face · 2026-10-21 · Medium · 9 min read · Performance engineering, Inference & serving, Hardware, Python
  A beginner-friendly walkthrough of system-level profiling for PyTorch on AWS Trainium using TorchNeuron.
- [Custom Kernels for All from Codex and Claude](https://swe.quest/articles/custom-kernels-for-all-from-codex-and-claude-9d652cbc33fa9001.md): Hugging Face · 2026-02-13 · Medium · 9 min read · AI for coding, Performance engineering, Inference & serving, Hardware, Python
  Hugging Face packaged CUDA kernel expertise (GPU architecture guides for H100/A100/T4, diffusers and transformers integration patterns, vectorized kernel templates, benchmark scripts) into an agent skill that lets Claude and Codex generate complete kernel-builder projects with PyTorch bindings.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
