High-Performance LLM Inference in Pure Python with PyTorch Custom Ops
Yineng Zhang, Senior Director at Together AI
Agenda
1 | Why a pure-Python architecture can match C++ inference engines | |
2 | The key design principles behind multi-process runtime scheduling | |
3 | How to hide scheduling overhead behind GPU execution | |
4 | Why CUDA Graph changed Python inference | |
5 | The role of PyTorch custom ops in high-performance serving | |
6 | Practical lessons learned from scaling a Python LLM engine | |
7 | Case Study: TokenSpeed — A Next-Generation LLM Inference Engine | |
What does modern LLM inference systems look like
Modern inference engines are distributed runtime systems, not traditional Python applications.
Why a pure-Python architecture can match C++ inference engines
Multi-process runtime architecture
CPU-side work such as tokenization and detokenization can be isolated into asynchronous processes, preventing them from blocking GPU scheduling and inference execution. Combined with efficient request routing and continuous batching, the runtime can maintain high GPU utilization despite Python’s GIL.
CPU-GPU overlap execution
The scheduler primarily prepares metadata, batching decisions, and execution plans, while the actual heavy computation runs asynchronously on GPUs. With careful CPU-GPU overlap and minimal synchronization, scheduling overhead can become nearly invisible in the end-to-end pipeline.
Native custom kernels
Performance-critical kernels are ultimately implemented in CUDA, Triton, CUTLASS, vendor libraries, or other native backends. Python acts as the glue layer coordinating these kernels rather than executing the heavy computation itself, allowing a Python architecture to achieve performance close to C++ inference engines.
CUDA Graph���CUDA Graph captures an iteration as a reusable GPU execution graph, replacing many small host-side kernel launches with a single graph replay.
This significantly reduces Python dispatch, CPU launch overhead on the critical path.
The key design �principles behind multi-�process runtime scheduling
Figure from the LightLLM design (2023)
How to hide scheduling overhead behind GPU execution
Figure from vLLM v1 design (2024-2025)
CUDA Graph
Why CUDA Graph changed Python inference
The role of Pytorch custom ops in �high-performance �serving
Pytorch tensor interface�Tensor lifecycle, memory ownership, �stream/device semantics
Pytorch custom ops�Expose CUDA/Triton/vendor kernels as Pytorch �tensor operators
High-performance kernels�CUDA/Triton/vendor kernels
Vendor GPU hardware�NVIDIA/AMD/etc.
LLM inference engine
Practical lessons learned from scaling a Python LLM engine
What worked well
What became difficult �
Python is very well suited for the execution plane, but the complexity of the control plane eventually requires stronger constraints.
Case study: �TokenSpeed — A Next-Generation LLM Inference Engine
TokenSpeed is a high-performance LLM inference engine.
What is TokenSpeed?
The architecture of TokenSpeed
Execution
Python runtime
Frontend
Tokenspeed-smg
Kernel
TokenSpeed-kernel
Scheduler
TokenSpeed scheduler
Final takeaway
Modern LLM inference engines are no longer just Python applications.
They are heterogeneous systems:
The future is not Python vs C++/Rust.
It is choosing the right abstraction boundary for each layer.
LinkedIn: https://www.linkedin.com/in/zhyncs
GitHub: https://github.com/zhyncs�Slides: https://pycon.lightseek.org
Youtube: https://www.youtube.com/watch?v=XdDiixKHk38
LightSeek Foundation: https://lightseek.org
TokenSpeed: https://github.com/lightseekorg/tokenspeed
Thank you!