Xiaol.x
Shifting token routing and buffer reuse entirely onto GPU multiprocessors eliminates host-synchronization stalls, raising distributed training throughput by up to 1.41 times on tuned Blackwell clusters.
AI-assisted summary of Mixture of Kittens Explained: How Cursor’s GPU Megakernel Accelerates MoE Training — original source. Check the original for full context.
Source published:
Key ideas
- Cursor developed Mixture of Kittens (MoK), a GPU-resident megakernel for NVIDIA Blackwell systems that unifies inter-GPU communication, scheduling, and expert FFN computation into a single persistent launch to eliminate MoE pipeline bubbles. (0:00)
- Using pull-based dispatch, push-based combine via PyTorch symmetric memory, and an on-chip macrobatch ring buffer, MoK dynamically routes tokens across GPUs without dropping tokens or synchronizing with the host CPU. (7:21)
- On an NVIDIA GB300 NVL72 rack running Qwen 3.5 (EP64), MoK delivered up to a 2.37× speedup in forward MXFP8 over Megatron baselines, alongside a 1.41× end-to-end speedup on Cursor's internal 512-GPU training cluster. (19:24)
- MoK is tailored specifically for high-bandwidth Blackwell NVLink domains and is not universally faster, exhibiting a 1.5% slowdown compared to DeepEP on DeepSeek V4 Pro BF16 backward microbenchmarks. (19:24)
Detailed notes
## Background Published on YouTube by Xiaol.x on August 13, 2026, this technical breakdown examines Cursor's Mixture of Kittens (MoK), a GPU-resident megakernel built to accelerate distributed Mixture-of-Experts training. The video explores how MoK tackles communication, scheduling, and host synchronization stalls on NVIDIA Blackwell architectures by unifying token routing, grouped GEMM execution, and combine phases into a persistent device-side runtime.
## TL;DR While Mixture-of-Experts models reduce theoretical arithmetic, distributed token routing and host-side CPU orchestration routinely turn sparse computation into a severe systems bottleneck. Cursor resolves this with Mixture of Kittens, an architecture-specific megakernel on NVIDIA Blackwell systems that partitions GPU Streaming Multiprocessors into dedicated asynchronous communication workers and persistent grouped-GEMM compute clusters. Utilizing symmetric memory for pull-based dispatch and push-based combine, alongside a macrobatch ring buffer, MoK handles dynamic token loads on-device without dropping tokens or stalling for host synchronization. Microbenchmarks demonstrate up to a 2.37× forward speedup on Qwen 3.5 and a 1.41× end-to-end training boost on Cursor's 512-GPU stack, although results are workload-dependent and can yield minor regressions on models with mismatched communication-to-compute profiles.
## Atmosphere & style The presentation carries a rigorous, systems-first engineering tone that dissects hardware traces and execution pipelines with meticulous precision. It feels like an advanced systems architecture seminar, replacing superficial optimization claims with an unvarnished examination of why modern tensor cores sit idle waiting on host control planes. The delivery is pragmatic and analytical, celebrating the ingenuity of autonomous device-resident scheduling while maintaining intellectual honesty about tuning complexities, proprietary baseline limitations, and hardware-specific boundaries.
## Bulletin - [00:00](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=0s) Cursor developed Mixture of Kittens (MoK), a GPU-resident megakernel for NVIDIA Blackwell systems that unifies inter-GPU communication, scheduling, and expert FFN computation into a single persistent launch to eliminate MoE pipeline bubbles. - [07:21](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=441s) Using pull-based dispatch, push-based combine via PyTorch symmetric memory, and an on-chip macrobatch ring buffer, MoK dynamically routes tokens across GPUs without dropping tokens or synchronizing with the host CPU. - [19:24](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=1164s) On an NVIDIA GB300 NVL72 rack running Qwen 3.5 (EP64), MoK delivered up to a 2.37× speedup in forward MXFP8 over Megatron baselines, alongside a 1.41× end-to-end speedup on Cursor's internal 512-GPU training cluster. - [19:24](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=1164s) MoK is tailored specifically for high-bandwidth Blackwell NVLink domains and is not universally faster, exhibiting a 1.5% slowdown compared to DeepEP on DeepSeek V4 Pro BF16 backward microbenchmarks.
## Key takeaways - [00:00](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=0s) Despite activating only a fraction of parameters, distributed MoE layers routinely consume over half of total training runtime because token transport across GPUs creates a dense systems bottleneck. - [00:00](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=0s) On ultra-fast accelerators like NVIDIA GB300, GPU streams outpace host CPU execution, causing compute engines to sit idle waiting for host-side dispatch orchestration. - [01:50](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=110s) Standard pipelining approaches suffer from high launch overhead and barrier latency, while dynamic routing forces undesirable compromises between convergence-harming token dropping and serialization-inducing host synchronization. - [05:14](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=314s) MoK eliminates host-side scheduling bottlenecks by launching a persistent megakernel (`dispatch_mlp_swiglu_combine`) that manages dispatch, grouped GEMMs, SwiGLU, and combine inside a single GPU runtime context. - [05:14](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=314s) Rather than relying on CUDA streams or green contexts, MoK enforces deterministic SM partitioning directly in software, dedicating specific SMs to communication while reserving the rest for tensor core compute clusters. - [07:21](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=441s) Following a router all-gather, an on-device scheduler tallies expert assignments, aligns token buffers to 256-row grouped GEMM tile boundaries, and builds local itinerary arrays directly in GPU memory. - [07:21](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=441s) PyTorch symmetric memory enables a pull-based dispatch and push-based combine architecture where communication SMs use TMA to directly read and write peer buffers without cross-rank signaling. - [10:34](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=634s) Fine-grained device counters (`x_routed_ready` and `y_routed_ready`) coordinate communication and compute SMs, allowing next-minibatch token pulls to overlap completely with current-minibatch GEMM arithmetic. - [10:34](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=634s) Compute clusters dynamically pull work tiles using Blackwell Cluster Launch Control (CLC), balancing workload distribution across grouped GEMM projections and elementwise SwiGLU activations. - [12:20](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=740s) MoK implements a pre-allocated macrobatch ring buffer on the GPU to handle dynamic token count variations without stalling for runtime host memory reallocations. - [12:20](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=740s) The host CPU is kept out of steady-state execution: the megakernel reads a one-element `num_tokens` device tensor, computes its own loop boundaries, and self-terminates excess thread block clusters. - [15:40](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=940s) MoK exposes five primary tuning knobs—forward/backward comm SM counts, minibatch size, macrobatch size, and schedule capacity—allowing engineers to systematically shift bottleneck placement across hardware limits. - [15:40](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=940s) Deterministic memory schedules guarantee bitwise reproducible accumulation orders across training runs, supporting both pure BF16 and fused MXFP8 precision formats. - [19:24](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=1164s) In EP64 benchmarks on a GB300 NVL72 rack, MoK achieved up to 531.1 TFLOPs/s on Qwen 3.5 MXFP8 forward passes (a 2.37× speedup over Megatron baselines) and 1.92× in BF16 forward. - [19:24](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=1164s) Speedups are workload-dependent: MoK trailed DeepEP by 1.5% on DeepSeek V4 Pro BF16 backward passes, demonstrating that efficiency gains depend strictly on the ratio of arithmetic intensity to communication volume. - [19:24](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=1164s) Cursor reported an end-to-end training throughput increase from 760.9 to 1,070.2 tokens/sec/GPU (1.41×) across 512 GB300 GPUs, though specific production model code and cluster setups remain proprietary. - [23:14](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=1394s) The project conceptualizes the megakernel not as an oversized math operator, but as an on-device factory that coordinates memory transport, scheduling, and compute without CPU intervention.
## Detailed walkthrough ### [00:00](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=0s) The Sparse-Compute Paradox
A Mixture-of-Experts (MoE) architecture sounds deceptively inexpensive on paper because it activates only a tiny subset of its experts for any given token. In Cursor's real-world production training stacks, however, reality contradicted theory: the expert layer routinely ate up more than half of the total end-to-end training runtime. This discrepancy highlights a fundamental systems dilemma: "sparse arithmetic creates a dense systems problem." While the floating-point operations drop dramatically compared to a dense model, the tokens now have to be routed dynamically across physical GPUs, packed into alignments that hardware tensor cores can ingest efficiently, and eventually shipped back to their home ranks.
The conventional distributed MoE pipeline appears rational at first glance. A router module identifies each token's top-$k$ experts. A dispatch phase issues copies of those tokens to the ranks hosting the chosen experts. Once received, each expert executes its feed-forward network—consisting of a gate projection, an up projection, a SwiGLU activation, and a down projection. Finally, a combine step routes the calculated activations back to each token's originating rank. The breakdown occurs because inter-GPU communication takes roughly as long as the expert computation itself. When these stages are treated as independent, sequential software steps, massive hardware-idling gaps appear.
Pipelining the workload helps, but chopping operations into fine chunks introduces severe launch overhead, barrier latency, and host-side orchestration bottlenecks. On state-of-the-art platforms like NVIDIA GB300 systems, the GPU execution stream runs so fast that it overtakes the host Grace CPU, sitting completely idle while waiting on host instructions. Tackling this bottleneck requires moving beyond isolated kernel optimizations like writing a faster matrix multiplication. The entire routed token journey must remain resident on the GPU and overlap at fine granularity. Cursor’s Mixture of Kittens (MoK) addresses this with a device-resident megakernel—a single persistent GPU program coordinating communication, routing, and expert computation from within the device itself.
[01:50](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=110s) The Broken Overlap Staircase and Dynamic Routing
When an MoE layer is distributed across an accelerator cluster, expert parallelism introduces a second machine to coordinate: the interconnect network. To see where the execution trace fractures, consider a simplified toy batch consisting of four tokens and four routed experts distributed across two GPUs. If the gating router sends Token A to Expert 3 and Token B to Expert 1, and those expert parameters are hosted on separate ranks, an all-to-all dispatch transfer is required to move the token activations. Once the feed-forward math completes, an all-to-all combine transfer returns the resulting vectors to their origin rank before a final router-weighted sum is computed.
```mermaid flowchart TD accTitle: Sequential MoE Execution Pipeline vs Overlap accDescr: Diagram contrasting naive sequential MoE phase stalls with the chunked pipelining staircase. subgraph Sequential["Naive Sequential Pipeline (Idle Gaps)"] direction LR S1["All-to-All Dispatch\n(Compute Idle)"] --> S2["Expert FFN GEMMs\n(Network Idle)"] S2 --> S3["All-to-All Combine\n(Compute Idle)"] S3 --> S4["Weighted Sum Reduce"] end subgraph Pipelined["Pipelined Overlap Staircase"] direction LR P1["Transfer Chunk 0"] --> P2["Compute Chunk 0\n& Transfer Chunk 1"] P2 --> P3["Combine Chunk 0,\nCompute Chunk 1,\n& Transfer Chunk 2"] end ```
In a standard sequential implementation, each stage halts until the prior stage finishes across all participating devices. The hardware trace displays glaring inefficiencies: compute units sit completely dark while the network runs dispatch, and the network sits dark while tensor cores churn through expert feed-forward networks. The textbook systems response is pipelining: slice the batch into chunks, compute on chunk zero while chunk one is in transit, and overlap transfers in a staircase pattern. Yet this staircase demands constant coordination handoffs—checking whether a chunk has arrived, launching a matrix multiply, and triggering the combine communication the instant an expert output clears. Implementing this minibatching and ring-buffer macrobatching without kernel fusion introduces numerous separate kernel launches, compounding launch boundary latency.
Dynamic routing further complicates pipelined execution because a destination rank cannot know a priori how many tokens will be routed to it. Standard implementations resort to one of two undesirable compromises: - **Fixed-capacity buffers with token dropping:** Destination buffers are statically allocated, and any routing overflow is simply discarded. Cursor explicitly rejects this strategy because dropping tokens degrades training quality and convergence. - **Host-synchronized buffer allocation:** The GPU gathers dynamic per-rank token counts and synchronizes with the host CPU so it can allocate exact-fit buffers. This synchronization serializes execution. On high-throughput GB300 systems, the GPU stream rapidly catches up to the Grace CPU thread and stalls, proving that "the control plane can starve the data plane."
[05:14](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=314s) Defining the Megakernel and SM Partitioning
Even if the host CPU is removed from the critical scheduling loop, overlapping communication with computation presents a delicate balance. If chunk transfers are partitioned too finely, tensor cores repeatedly hit pipeline synchronization barriers before reaching full arithmetic saturation. If chunk transfers are sized too coarsely, the execution engine experiences long pipeline bubbles at the front of the schedule and during the final combine phase.
```mermaid flowchart TD accTitle: Device-Resident SM Partitioning Architecture accDescr: How Mixture of Kittens partitions GPU streaming multiprocessors into dedicated communication and compute workers. subgraph GPU["Device-Resident Megakernel (dispatch_mlp_swiglu_combine)"] subgraph CommSMs["Communication SMs (Tunable Allocation)"] C1["TMA Async Pull Dispatch"] C2["TMA Async Push Combine"] end subgraph Sync["Fine-Grained Readiness Counters"] RC1["x_routed_ready"] RC2["y_routed_ready"] end subgraph ComputeClusters["Compute SM Clusters (Persistent Grid)"] W1["Gate & Up Grouped GEMMs"] W2["SwiGLU Elementwise"] W3["Down Grouped GEMM"] W4["Blackwell CLC Work Stealing"] end C1 -->|"increments"| RC1 RC1 -->|"unblocks"| W1 W1 --> W2 --> W3 W3 -->|"increments"| RC2 RC2 -->|"unblocks"| C2 end ```
To coordinate these tasks, Mixture of Kittens abandons traditional execution boundaries and assigns dedicated roles to hardware Streaming Multiprocessors (SMs), mediating data readiness through localized atomic counters. Cursor attempted using separate CUDA streams isolated via green contexts to enforce this division, but found them unreliable for deterministic, hardware-level SM partitioning. Instead, MoK relies on strict software-level ownership inside a single persistent kernel launch. In the public PyTorch bindings, this fused forward operation is exposed as `dispatch_mlp_swiglu_combine`.
- A megakernel is not a single, monolithic matrix multiplication; it is a long-running, persistent GPU program that houses dispatch, expert feed-forward calculations, and combine communication inside one runtime context. - Instructions from dispatch, grouped GEMMs, SwiGLU activations, and combine routines are interleaved at the SM task level rather than separated by distinct kernel launch barriers. - The megakernel is only necessary when three distinct pressures collide: token activations must cross physical GPU boundaries, fine-grained pipelining creates prohibitive handoff overhead, and dynamic token routing makes host-side synchronization too costly. - Latency-critical scheduling is moved onto the GPU silicon, while operations outside the primary communication-compute overlap loop—such as the final weighted sum epilogue—remain decoupled as separate functional steps.
[07:21](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=441s) Constructing the Device-Side Schedule and Symmetric Memory
MoK implements a persistent grid pattern on NVIDIA Blackwell architectures. Rather than retiring when an operation concludes, resident thread block clusters query Blackwell Cluster Launch Control (CLC) to fetch the next unfinished task block, staying active until the device-side task grid is fully drained. Before entering the megakernel, all GPU ranks participate in an all-gather exchange of the router's top-$k$ expert assignments. Once these gating choices are globally visible, an on-device scheduler runs three preparatory stages:
1. **Per-Expert Token Accounting:** Each rank tallies the precise number of routed token copies headed toward each local expert from every peer rank in the cluster. 2. **Grouped GEMM Tile Alignment:** The scheduler calculates any necessary padding to round every expert’s assigned token segment up to an exact multiple of 256 rows, satisfying hardware tile requirements for high-efficiency grouped GEMMs. 3. **Data-Plane Itinerary Generation:** It constructs two parallel scheduling arrays: `peer_rank` and `peer_token_index`. A given index $R$ in these tables explicitly dictates which peer rank and source index routed row $R$ must be pulled from during dispatch, and where its final result must be pushed back during combine. Structural padding entries are assigned a sentinel rank value of `-1`.
```mermaid flowchart LR accTitle: Symmetric Memory Direct Pull Dispatch and Push Combine accDescr: Token activations moving via TMA directly between symmetric memory buffers without intermediate local copies. subgraph RemoteRank["Peer GPU Rank"] R_In["Input Buffer\n(Token Activations)"] R_Out["Combine Slot\n(Final Accumulation)"] end subgraph LocalRank["Local GPU Rank"] CommSM["Communication SM\n(TMA Engine)"] LocalBuf["Contiguous Expert Rows\n(256-Row Aligned)"] ComputeSM["Compute SMs\n(Grouped GEMMs / SwiGLU)"] end R_In -->|"Direct Pull (TMA Load)"| CommSM CommSM --> LocalBuf LocalBuf --> ComputeSM ComputeSM -->|"Local Intermediate"| LocalBuf LocalBuf --> CommSM CommSM -->|"Direct Push (TMA Store)"| R_Out ```
This device-side itinerary functions seamlessly because all expert-parallel ranks allocate identically sized symmetric memory buffers via PyTorch’s symmetric memory rendezvous mechanisms. This exchange provides every GPU with direct peer memory pointers into both the input and combine buffers across the entire cluster.
By taking advantage of symmetric memory, MoK adopts a **pull-based dispatch** and **push-based combine** architecture: - **Pull Dispatch:** A local communication SM uses remote pointers to pull token vectors directly from the source rank's memory into a contiguous, 256-row-aligned local expert buffer, completely bypassing any intermediate local reordering steps. - **Push Combine:** When calculation concludes, the communication SM writes the completed activation row straight into the remote origin rank’s target combine buffer slot. - **Elimination of Cross-Rank Signaling:** Because the local GPU initiates both the pull and the push, it maintains immediate local visibility over data readiness. It does not need to wait for or process a flood of incoming completion messages from remote ranks; it simply updates an internal register or shared-memory counter to notify local compute clusters that a segment is ready.
[10:34](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=634s) Communication vs. Compute SMs in the Minibatch Pipeline
Inside the launched megakernel, the GPU’s physical Streaming Multiprocessors are split into two explicit operational groups. The first group consists of a user-tunable number of dedicated Communication SMs. These multiprocessors execute network-bound dispatch and combine tasks using Blackwell's Tensor Memory Accelerator (TMA) for asynchronous loads and stores. The remaining multiprocessors form Compute Clusters dedicated entirely to high-throughput tensor core arithmetic: the gate and up grouped GEMMs, the elementwise SwiGLU activation, and the down grouped GEMM.
```mermaid flowchart TD accTitle: Minibatch 0 Step-by-Step Execution Trace accDescr: Chronological walkthrough of Minibatch 0 from token pull to combine push. T1["1. Comm SM reads schedule:\nToken 17 (Copy 1) on Peer Rank 2"] --> T2["2. TMA Pull into local routed row 0"] T2 --> T3["3. Comm SM increments x_routed_ready for Minibatch 0"] T3 --> T4["4. Compute Cluster unblocks:\nExecutes Gate & Up Grouped GEMMs"] T4 --> T5["5. SwiGLU elementwise multiply:\n(swish(gate) * up)"] T5 --> T6["6. Compute Cluster executes Down Grouped GEMM"] T6 --> T7["7. Compute Cluster increments y_routed_ready for Minibatch 0"] T7 --> T8["8. Comm SM unblocks:\nTMA Push result to Peer Rank 2 combine slot"] T8 --> T9["9. Epilogue: Weighted sum across top-k copies"] ```
Work distribution among the compute clusters is handled dynamically via Blackwell Cluster Launch Control, enabling clusters to steal whichever task tile is next in line across the device-resident task grid. Sizing the communication SM pool requires precise balancing: allocating too few communication SMs causes the interconnect to starve, leaving tensor cores waiting for input, while dedicating too many drains the hardware capacity needed for intensive matrix operations.
The lifecycle of an individual execution unit illustrates how this coordination operates without host intervention: - **Schedule Lookup & TMA Pull:** On Rank 0, a communication SM inspecting Minibatch 0 reads its device schedule and identifies that top-$k$ copy 1 of Token 17 resides on Peer Rank 2 and targets a local expert. The SM pulls that vector across NVLink directly into local routed row 0. - **Signaling Compute Readiness:** Once the minibatch transfer completes, the communication SM increments the device counter `x_routed_ready` for Minibatch 0. - **FFN Computation:** A persistent compute cluster waiting on `x_routed_ready` wakes up and launches the expert's gate and up projections. The SwiGLU activation multiplies the activated gate branch with the up branch, and the down projection maps the representations back down to the model's hidden width. - **Signaling Combine Readiness:** As soon as all required output tiles for Minibatch 0 are written into local buffers, the compute worker increments `y_routed_ready`. - **TMA Push Combine:** The waiting communication SM detects the updated counter and pushes the finished activation vector across NVLink directly into Peer Rank 2's combine buffer slot for Token 17. - **Decoupled Epilogue:** Finally, an independent epilogue applies the gating router weights and accumulates the finished top-$k$ copies.
Because readiness tracking is managed through fine-grained, device-local counters, the megakernel achieves full hardware overlap: while compute clusters process Minibatch 0, the communication SMs are already pulling activations for Minibatch 1.
[12:20](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=740s) Minibatch Pipelining and Macrobatch Ring-Buffer Reuse
The core pipeline operates on a producer-consumer model: communication SMs produce ready minibatches, while compute SMs consume them to perform expert work and yield finished minibatches. As soon as minibatch 0 finishes its down-projection, the combine phase can begin immediately without being gated on minibatch 1's expert computation. Setting the minibatch size requires balancing two distinct failure modes: making minibatches too tiny causes frequent signaling overhead and underfills tensor core waves, whereas making them too huge delays both the first compute wave and the ultimate combine step. The project recommends sizing minibatches to provide roughly enough work for two full compute waves.
Because expert routing is dynamic, the host CPU cannot know in advance the exact number of arriving tokens. To eliminate dynamic runtime host allocations, Mixture of Kittens (MoK) pre-allocates a fixed routed token buffer called the macrobatch. When the routed rows exceed this buffer's physical capacity, the storage is reused as a ring buffer. The forward path processes macrobatches in reverse order: at a ring boundary, the communication group combines macrobatch $M$ while simultaneously dispatching macrobatch $M-1$ into the released memory region. Release and acquire counters in GPU memory prevent data overwrites until the grouped GEMM and combine reads are fully completed. By draining and immediately refilling each slot, fixed memory capacity is preserved without requiring host round-trips or dropping tokens.
```mermaid flowchart LR accTitle: Macrobatch Ring Buffer Lifecycle accDescr: Pipeline showing cyclic buffer reuse between communication dispatch, compute, combine, and slot release without host synchronization.
subgraph RingSlot["Macrobatch Ring Slot"] D["Dispatch (Pull Tokens)"] C["Compute (Grouped GEMM)"] CB["Combine (Push Tokens)"] end
Sync["Counters (Release/Acquire)"]
D --> C C --> CB CB -->|"Drain slot"| Sync Sync -->|"Refill slot (M-1)"| D ```
- Steady-state execution completely bypasses the host: the CPU never queries token counts to allocate memory. - The router writes total token counts (`num_tokens`) as a one-element CUDA tensor directly on the device. - The megakernel reads this single-element tensor on-chip, calculates macrobatch and minibatch counts, and self-exits excess thread block clusters. - The host CPU enqueues only high-level steps (scheduler, megakernel barrier, weighted epilogue) and never synchronizes across dispatch, compute, and combine stages. - Minibatch pipelining replaces the sequential latency sum ($\text{Comm} + \text{MLP}$) with an overlapped maximum: $\text{Fill} + (M - 1) \times \max(\text{Comm Service}, \text{MLP Service}) + \text{Drain}$.
---
[15:40](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=940s) Tuning Controls and the Five Knobs of Bottleneck Placement
MoK converts the entire distributed MoE pipeline—scheduling, dispatch, grouped expert FFNs, combine, and router-weight application—into a single schedule-driven megakernel. This architectural shift exposes five critical tuning knobs that allow engineers to shift bottleneck placement rather than just adjusting cosmetic configurations:
```mermaid flowchart TD accTitle: Megakernel Resource Partitioning Controls accDescr: Diagram illustrating how MoK splits streaming multiprocessors and manages buffers via five tunable parameters.
subgraph SM_Allocation["SM Allocation"] CSM["Comm SM Count (Forward & Backward)"] KSM["Compute SMs (Tensor Core GEMMs)"] end
subgraph Data_Chunking["Granularity & Buffer Sizing"] MB["Minibatch Size (Handoff Grain)"] MCB["Macrobatch Size (Ring Window)"] SC["Schedule Capacity (Imbalance Headroom)"] end
CSM <-->|"SM trade-off"| KSM MB -->|"Determines wave fullness"| KSM MCB -->|"Bounds symmetric memory"| CSM ```
- **Forward Communication SM Count**: Allocates dedicated SMs to drain network traffic; adding SMs accelerates transfers but robs compute capacity from tensor cores. - **Backward Communication SM Count**: Independently tuned because backward passes involve reverse communication, replay decisions, three activation gradient GEMMs, three weight gradient GEMMs, and router weight gradient calculations. - **Minibatch Size**: Controls handoff granularity; small sizes allow earlier compute overlap but incur barrier overhead, while large sizes ensure full tensor core waves at the expense of pipeline latency. - **Macrobatch Size**: Configures the reusable memory window for the ring buffer, preventing out-of-memory errors on skewed distributions. - **Schedule Capacity**: Reserves buffer headroom to absorb dynamic token routing imbalances across ranks without dropping tokens.
The CUDA scheduler deterministically fixes which source rank and token index fills each padded expert slot, matching an exact reference visitation order. In addition, floating-point accumulation order is deterministic across runs, preserving bitwise reproducibility for ablations and on-policy RL training. Precision modes support pure BF16 or MXFP8 (where expert weights are pre-quantized with microscopic block scales, activation quantization is fused directly into the pipeline, and shared experts remain in BF16 for numerical stability).
---
[19:24](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=1164s) Benchmark Findings: GB300 NVL72 and Internal Cluster Evidence
Evaluated on a single Nvidia GB300 NVL72 rack at expert parallel degree 64 (EP64) with 48 tokens per GPU prior to routing, MoK was benchmarked against the fastest public baselines (NCCL + PyTorch, DeepEP + PyTorch, DeepEP + Transformer Engine, and Hybrid EP + Megatron):
| Model Shape | Precision & Direction | MoK Performance | Best Baseline | Speedup Factor | |:--- |:--- |:--- |:--- |:--- | | **Qwen 3.5 (397B / A17B)** | MXFP8 Forward | 531.1 TFLOPs/s (1.068 ms) | 224.4 TFLOPs/s (Hybrid EP + Megatron) | **2.37×** | | **Qwen 3.5 (397B / A17B)** | MXFP8 Backward | — | Hybrid EP + Megatron | **1.78×** | | **Qwen 3.5 (397B / A17B)** | BF16 Forward | — | DeepEP + PyTorch | **1.92×** | | **Qwen 3.5 (397B / A17B)** | BF16 Backward | — | DeepEP + PyTorch | **1.58×** | | **DeepSeek V4 Pro** | BF16 Backward | — | DeepEP + PyTorch | **0.985× (1.5% loss)** |
The data confirms that MoK is a specialized workload optimization rather than an unqualified win across every possible architecture. On the DeepSeek V4 Pro BF16 backward benchmark, MoK runs roughly 1.5% slower than the DeepEP baseline, illustrating that performance gains hinge directly on compute-to-communication balance and expert sizing.
Beyond standalone layer microbenchmarks, Cursor tested an end-to-end production setup across 512 GB300 GPUs spanning multiple NVL72 racks. Swapping out their prior DeepEP-based custom MXFP8 pipeline for MoK elevated training throughput from 760.9 tokens/sec/GPU to 1,070.2 tokens/sec/GPU—a 1.41× end-to-end acceleration. However, because production model code, run configurations, and cluster logs remain proprietary, external practitioners cannot independently replicate this 1.41× end-to-end metric from the public repository alone.
- The public codebase requires Python 3.12+, PyTorch 2.10+, and CUDA 13+ compiled for Nvidia Blackwell SM100 or SM103 architectures (e.g., GB200, GB300 NVL72). - The functional implementation relies fundamentally on PyTorch symmetric memory across the expert parallel domain.
---
[23:14](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=1394s) The Resident Factory: Eliminating Three Architectural Bubbles
The architectural thesis behind Mixture of Kittens is best understood as a "resident factory, not an oversized operator." Rather than repeatedly launching discrete kernels and synchronizing through the host CPU, a single GPU-resident megakernel orchestrates worker groups: one team of SMs pulls and pushes network tokens while another team runs GEMMs on tensor cores, passing minibatches back and forth via hardware counters.
MoK systematically tackles three primary sources of pipeline bubbles:
1. **Scheduling & Cross-GPU Overhead**: Pull-based dispatch and push-based combine ensure destination ranks independently fetch needed inputs and push outputs, eliminating cross-GPU completion signals and host barriers. 2. **Compute Wave Starvation**: Granular, tunable minibatches prevent tensor core underutilization while avoiding idle delay waiting for large transfers. 3. **Dynamic Host Allocations**: The macrobatch ring buffer dynamically recycles symmetric memory on-chip, processing fluctuating token loads without dropping tokens or stalling for host reallocations.
MoK demonstrates that "the megakernel achievement is not 'fusion makes everything faster.'" Instead, its strength lies in co-designing the scheduling, transport, GEMM compute, and memory buffers into a unified device-resident system. By making SM ownership explicit and streaming dynamic tokens through ring buffers within high-bandwidth NVLink domains, MoK shows how to remove boundary overheads when standard distributed pipelines stall.
## Notable quotes > [00:00](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=0s) sparse arithmetic creates a dense systems problem. — Xiaol.x
> [01:50](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=110s) the control plane can starve the data plane. — Xiaol.x
> [05:14](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=314s) dispatch_mlp_swiglu_combine — Xiaol.x
> [07:21](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=441s) peer_rank — Xiaol.x
> [07:21](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=441s) peer_token_index — Xiaol.x
> [10:34](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=634s) x_routed_ready — Xiaol.x
> [10:34](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=634s) y_routed_ready — Xiaol.x
> [23:14](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=1394s) resident factory, not an oversized operator. — Xiaol.x
> [23:14](https://www.youtube.com/watch?v=hlzBiTt6h7M&t=1394s) the megakernel achievement is not 'fusion makes everything faster.' — Xiaol.x
## Mentioned Cursor, Mixture of Kittens, NVIDIA, NVIDIA GB300, NVIDIA GB200, NVL72, Blackwell, SM100, SM103, Grace CPU, Tensor Memory Accelerator (TMA), Cluster Launch Control (CLC), CUDA, PyTorch, NCCL, DeepEP, Transformer Engine, Hybrid EP, Megatron, Qwen 3.5, DeepSeek V4 Pro
## Video description Mixture-of-Experts models activate only a small fraction of their experts, but routing tokens across GPUs can still consume a large share of training time. Cursor’s Mixture of Kittens addresses this with a GPU-resident megakernel that coordinates communication, expert computation, scheduling, and result combination.
This English explainer walks through:
- Why ordinary MoE pipelines stall at CPU, launch, and synchronization boundaries - How device-side routing schedules are constructed - Pull-based dispatch and push-based combine - Communication-SM and compute-SM partitioning - Minibatch overlap and macrobatch ring-buffer reuse - Public GB300/NVL72 benchmark results and their limitations - Why the approach targets specific Blackwell workloads rather than being a universal GPU optimization
Chapters
00:00 The Sparse-Compute Paradox 01:50 Why Ordinary MoE Pipelines Stall 07:21 Inside the MoK Megakernel 15:40 Evidence, Tuning, and Boundaries 23:14 A Device-Resident Factory
Sources
Repository: https://github.com/cursor/mixture-of-kittens Technical article: https://cursor.com/blog/mixture-of-kittens
The reported speedups are workload-dependent. The 1.41× end-to-end comparison comes from Cursor’s private 512-GPU production stack, while the released implementation targets Blackwell SM100/SM103 systems and requires workload-specific tuning.
#MixtureOfExperts #Megakernel #GPUComputing #CUDA #DeepLearning #AIInfrastructure
[Source](https://www.youtube.com/watch?v=hlzBiTt6h7M)