← All questions
Inference & ServingMedium· Kernel Fusion· PyTorch· Profiling

A custom activation function written as a chain of PyTo...

First, verify via the profiler trace that the activation is executing as multiple separate kernels. The primary optimization strategy is to apply torch.compile, which can automatically fuse simple chains into a single Triton kernel. If the operation requires more complex logic, such as custom shared memory layouts or specific masking, you should manually implement a Triton kernel. Always profile after each modification to confirm that the kernel launch count has decreased.

Code playground (Python)