← All questions
Inference & ServingMedium· Triton· torch.compile· Kernel Optimization

When would you use Triton instead of torch.compile?

Use torch.compile for standard operations like element-wise math or standard matrix multiplications, as it is highly optimized for these cases. Switch to Triton when you need to implement custom logic that the compiler cannot automatically fuse, such as fused quantization-dequantization, online reductions over tiles, or non-standard memory layouts and attention masking patterns. Triton provides the low-level control necessary to encode specific algorithmic optimizations that general-purpose compilers might miss.

Code playground (Python)