Nicolas Perrin 52d94ab954 refactor(moe): pass the MoE output destination and top-k slot deferral as arguments (#4037)
## Summary

Kimi-K3 and the latent MoE gave the routed experts their output
destination and the top-k slot deferral by setting `_situ_output_buffer`
and `_situ_defer_topk_reduce` on the `MoELayer` before calling it.
Eleven MoE apply kernels read them back with `getattr`, and the latent
MoE saved and restored the buffer around its call. They are now
arguments.

- `moe_apply` and `MoELayer.forward` take `out`, a caller-owned
destination for the finalized rows, and `defer_topk_reduce`. A plan
advertises them as `supports_out` and `supports_defer_topk_reduce`;
`moe_apply` refuses either on a plan without the capability, as it does
`deferred_out`.
- The kernels that read the attributes (FlashInfer TRT-LLM MXFP4 and
NVFP4 SiTU, FlashInfer Cake MXFP4 SiTU, and the gfx950 and gfx1250 Gluon
MXFP4 applies) take them as parameters and declare the traits. They
still write into `out` only when its shape and layout fit.
- K3's native forward passes both to its experts calls when the selected
plan supports them, so a plan that ignored the attributes receives
neither, as before. The main forward no longer resets the buffer, and
the latent MoE passes its routed target directly.

## Tests

Tests that set the attributes pass `out=` and `defer_topk_reduce=`
instead; the stubs that stand in for `MoELayer` accept them.

On GB200: the NVIDIA SiTU kernel tests and the kernel API selection
suite (441 passed), and the MoE layer, latent MoE and Kimi-K3 runtime
suites pass. `test_kimi3_moe_execution_policy_preserves_nvidia_trtllm`
and `test_model_prepares_routed_workspace_at_serving_limit` fail on main
as well. The gfx950 and gfx1250 tests change the same way and run in AMD
CI.

Served greedy on GB200, main vs this branch, tokens and logprobs
compared bit for bit: Qwen3.5-35B-A3B-FP8, TP1, short prompts, a
2.8k-token prompt with its prefix hits and a follow-up turn are
identical. Four concurrent requests vary from run to run on main itself
(5 main runs, every rerun differs from the first, two at the step where
the shortest request leaves the batch); one branch run matched main on
them exactly.

---------

Signed-off-by: Nicolas Perrin <nperrin.ai@gmail.com>
2026-12-02 10:30:27 -05:00
2026-07-12 13:37:43 -07:00
2026-05-06 13:27:02 +00:00
2026-05-06 13:27:02 +00:00
2026-05-06 13:27:02 +00:00
2026-10-14 06:11:03 -07:00

TokenSpeed: Tokens at the speed of light

Publish nightly

TokenSpeed is a speed-of-light LLM inference engine designed for agentic workloads, with TensorRT-LLM-level performance and vLLM-level usability. The goal is to be the most performant inference engine for production agentic workloads.

Core components:

  • Scheduler: C++ control plane and Python execution plane. Request lifecycle, KV cache ownership, and overlap timing are encoded as a finite-state machine, with safe KV resource reuse enforced by the type system at compile time.
  • Kernels: pluggable, layered kernel system with a portable public API and a centralized registry including one of the fastest MLA (Multi-head Latent Attention) implementations on Blackwell for agentic workloads.
  • Entrypoint: SMG and Dynamo drive the engine from Rust over its msgpack wire, with no Python on the request path.

Differentiation

TokenSpeed takes a fundamentally different architectural approach from existing LLM inference engines. The PyTorch Foundation highlighted these architectural differentiators when welcoming TokenSpeed to the PyTorch Ecosystem Landscape:

TokenSpeed is an open source LLM inference engine and the first to separate the control plane from the execution plane. The control plane is implemented in C++ as a finite-state machine, using the type system to enforce safe resource management, including request lifecycles and KV cache state, at compile time rather than runtime. The execution plane is implemented in Python, enabling fast iteration and lowering the cognitive load for researchers and engineers. This architecture combines strong correctness guarantees in the core scheduling system with the development velocity of a high-level execution layer.

TokenSpeed also treats kernels as a first-class, modular subsystem, separating them from the core engine through a portable public API, centralized registry and selection model, and an extensible plugin mechanism for heterogeneous accelerators.

More importantly, TokenSpeed is the Switzerland of open-source LLM inference engines: neutral because it's backed by the non-profit LightSeek Foundation rather than a commercial company, with serious hardware and engineering support from vendors such as NVIDIA and AMD.

News

  • [2026/11] Advancing Muse Spark Open Agentic Inference on AMD Instinct MI355X GPUs with TokenSpeed [AMD blog]
  • [2026/11] 331 output tokens/s per GPU on AgentX: Serving Kimi K3 on GB300 with TokenSpeed (Kimi K3 Optimization on GB300 — Part II) [blog]
  • [2026/10] TokenSpeed MLA 2 for NVIDIA Vera Rubin. [blog]
  • [2026/10] Advancing Kimi K3 inference on AMD Instinct MI355X GPUs with TokenSpeed. [AMD blog]
  • [2026/09] Kimi K3 Optimization on GB300 — Part I. [blog]
  • [2026/08] TokenSpeed joins the PyTorch Ecosystem.
  • [2026/06] Deep dive into the design and optimization of TokenSpeed-Kernel. [PyTorch blog]
  • [2026/05] TokenSpeed hits 580 TPS on Qwen3.5-397B-A17B for agentic workloads. [PyTorch blog]
  • [2026/05] TokenSpeed is a brand new inference engine purpose-built for speed-of-light agentic workloads. [NVIDIA AI X]
  • [2026/05] TokenSpeed announced — a speed-of-light LLM inference engine for agentic workloads. [blog]
More news
  • [2026/11] TokenSpeed sets the state of the art for Kimi K3.1 Pro on AMD Instinct MI355X [blog]
  • [2026/11] TML Inkling 2 Small at Day 0: Serve TML Inkling with TokenSpeed [blog]
  • [2026/11] Kimi K3.1 Pro at Day 0: Sparse attention on the Kimi K3 stack with TokenSpeed. [blog]
  • [2026/10] EAGLE-4 training and serving with TorchSpec and TokenSpeed. [blog]
  • [2026/10] Reflection's Beam at day 0: 501B MoE serving in NVFP4 on NVIDIA GB200 with TokenSpeed. [blog]
  • [2026/10] 685 tokens/s per user: serving Qwen3.8-Flash-Next on NVIDIA GB300 with TokenSpeed. [blog]
  • [2026/08] Qwen3.8 Flash Next at Day 0 and GLM 5.3 Flash at Day 0.
  • [2026/08] Qwen3.8 at Day 0: 2.4T-Scale Inference with TokenSpeed. [blog]
  • [2026/07] Kimi K3 at Day 0: Frontier Model Enablement on Leading Platforms with TokenSpeed. [blog]
  • [2026/07] TML Inkling at Day 0: FP4 Inference on NVIDIA and AMD with TokenSpeed. [blog]

Blogs and talks

For technical blogs, conference talks, and engineering articles from the LightSeek Foundation, visit the LightSeek Blog.

Sponsors and partners

LightSeek's work is advanced by the support of sponsors and partners across the AI ecosystem.

Installation

Install the latest nightly with pip or uv:

pip

pip install --upgrade tokenspeed --extra-index-url https://lightseek.org/whl/nightly

uv

uv pip install --upgrade tokenspeed --index https://lightseek.org/whl/nightly

Documentation

Start here:

For Ascend memory release and graph recovery, see the ACL Graph Memory Saver guide.

Citation

@misc{tokenspeed2026,
  author       = {{TokenSpeed Team}},
  title        = {{TokenSpeed}: A Speed-of-Light {LLM} Inference Engine},
  year         = {2026},
  howpublished = {\url{https://github.com/lightseekorg/tokenspeed}}
}
Languages
Python 83.8%
Rust 8.1%
C++ 7.6%
Shell 0.3%
Cuda 0.1%