A growing number of models are getting smarter without getting bigger. Dory, Inkling 2 Mini and GLM 5.4 do this through looped transformer architectures, running a shared set of layers multiple times for each token. Reusing the same weights adds computation without adding parameters, giving the models more computational depth for better reasoning.
The additional computation has a cost. In GLM 5.4, the loop adds over a third more FLOPs per token, a cost that compounds across the long prompts common in agents. More computation at each position therefore means a longer wait for the first response and more GPU time per request.
Dory and Inkling 2 are quite small models, so a very attractive way of running them (especially the prefill phase) is unsharded on a single GPU. GLM 5.4, however, has 750B parameters and must be sharded to make the weights fit. Although the model weights for GLM 5.4 are not out yet, Zhipu describes the model architecture in depth in their blog post. We built GLM 5.4 from that description with random weights of the right shapes and explored various methods of efficiently running this architecture.
An increasingly popular way to split a large model is pipeline parallelism. Each GPU holds a block of layers, and the prompt flows through them in chunks. It delivers high throughput and lowers latency on long prompts that aren’t already cached [1], and it’s how DeepSeek V4 [2] and Kimi K3 and K3.1 [3, 4] are served for long-context prefill.
But pipeline parallelism only works well when every GPU takes the same time per chunk. A looped architecture breaks that balance: GPUs holding looped layers do twice the work, leaving other stages waiting. Moving the second pass to another GPU could spread the work, but would also require transferring the first pass’s KV cache, a large, growing communication cost. With a conventional partition of GLM 5.4, some GPUs sit idle about half the time. The challenge is to preserve the reasoning gains while eliminating that avoidable idle time.
We compare two layouts that remove most of that idle time:

- Ping-pong spreads the looped layers across two GPUs, each holding half of them, and sends every chunk through both twice, alternating between two prompts so neither GPU waits. With ping-pong, GLM 5.4 reaches 96% of its throughput ceiling on 8K prompts, and two 128K prompts finish in 8.5 s instead of 11.8 s.
- Hetero puts the whole loop on a single wider stage, where two GPUs share each chunk. A model fitted to our measured traces puts hetero 12–19% faster on a single long prompt, because each chunk crosses fewer stages. For a two-pass loop like GLM 5.4’s, hetero is the better layout; as loops get deeper, the advantage moves to ping-pong.
Inside GLM 5.4’s loop and shared KV cache
GLM 5.4 keeps the GLM 5.3 trunk: 78 MoE layers with DeepSeek-style sparse attention, where a lightweight indexer picks the top-k past positions each query attends to. The change is that layers 27–54 run twice per token, on shared weights. A damp gate closes each pass, scaling how much of that pass’s update goes into the residual stream.

The second pass skips the indexer and doesn’t build a full KV cache of its own. In one softmax, it attends to two banks:
- Pass 1’s latents, at pass 1’s top-k. Layer 27 on pass 2 reads the KV that layer 27 wrote on pass 1, at the positions pass 1’s indexer already chose.
- Its own last 128 positions. A small sliding window of pass-2 KV.
The extra loop therefore adds a small KV window rather than another full-context cache. But that saving creates a placement constraint: layer j on pass 2 needs access to the KV cache written by layer j on pass 1. This is important; the dependency determines how we distribute the model across GPUs.
On a single-GPU stage, prefill takes 1.32× as long as GLM 5.3, close to the 1.36× increase predicted by counting layer visits.
Naive pipeline parallelism and its bubbles
Pipeline parallelism is straightforward when a model’s layers run in sequence. Divide them into S stages of equal computational cost, assign each stage to a GPU, and stream prompt chunks through the pipeline. Each stage passes only the residual stream to the next. With balanced stages and enough chunks in flight, every GPU can stay busy once the pipeline fills (no bubbles).
For a pipeline to have no bubbles, every stage must do the same FLOPs per GPU. The slowest stage sets the pace, and every other stage waits for it. Equal layer counts only satisfy this rule when every layer costs the same, which a loop breaks.
A loop breaks the straight line. The first approach is to unroll the loop: prelude → core pass 1 → core pass 2 → coda, with one piece per GPU (Figure 3, row A). This balances compute well: the stages perform 26, 28, 28 and 28 layer visits, including a small speculator on the last stage, discussed below.
The problem is cache placement. Layer 27 on pass 2 needs the KV cache that layer 27 wrote on pass 1. That cache lives on S1, but pass 2 runs on S2. S1 would therefore have to transfer the full KV context for all 28 core layers to S2. Instead of passing only the residual stream for new tokens, this boundary would carry a cache covering the entire context. That transfer is much larger and grows with every chunk of a long prompt. The layout also stores the core weights twice.
The other obvious fix is to keep the whole loop on one GPU (row B). The weights are stored once and the KV cache never moves. But that stage now performs 56 layer visits per chunk while its neighbors perform 26 and 28. With roughly twice the FLOPs per GPU, it becomes the bottleneck, creating pipeline bubbles as neighboring stages wait between chunks.
Figure 4 shows the resulting bubbles in a simulation of two prompts with four chunks each. Time is measured in layer units: the time one layer takes to process one chunk. With the loop on a single stage, S0 and S2 sit idle more than half the time even after the pipeline fills.
Dividing the model by layer count, about 20 layers per GPU, reduces the imbalance but does not eliminate it. Stages containing loop layers still perform 32–34 visits per chunk, compared with 20–24 at the ends. S0 consequently remains idle about 40% of the time, and S3 about 30%. In summary, the layers are more evenly distributed, but the work is not.
In steady state, the PP3 layout keeps S0 46% busy and the even split keeps it 59% busy.
Ping-pong: balancing two passes across two stages
Ping-pong is an approach that gives the loop stages half of the layers. At load, each loop stage does half the amount of GPU work twice, bringing its total compute in line with the surrounding stages.
Concretely, the 28 core layers are split into two stages of 14. A chunk runs S0 → S1 → S2, wraps back to S1, runs S1 → S2 a second time, then goes on to S3. Each loop stage plays its 14 layers twice per chunk, ping and pong, for 28 visits. That’s within 2 of S0’s 26.
The coda has only 24 layers, but the final stage typically also runs the speculator, bringing its total work into balance with the other stages.
Each loop stage runs its layers twice but stores their weights only once. Giving it half as many layers balances compute, but leaves it with roughly half the weight memory. The spare HBM holds the top-k buffers shared between passes and the second pass’s sliding-window KV cache.
This layout has three consequences:
- Every layer lives on exactly one GPU. One copy of the weights.
- The KV dependency is solved because layers run different passes in the same stage. Layer 27’s pass 2 runs on the GPU that holds layer 27’s pass-1 KV, so the cache never crosses a link.
- Only the residual stream crosses stage boundaries, plus the pass index for the gate and, on pass 1, the IndexShare top-k for layers that reuse a group’s indexer.
S1 and S2 hold half as many layers as S0 and S3, but process each chunk twice. Their total compute per chunk is therefore comparable to that of their neighbors, despite the uneven distribution of weights.
Balance the work per GPU, not the number of layers. FLOPs guide the partition, but execution time per chunk determines whether stages stay busy. The traces below check that balance in practice.
Under this balanced timing model, the second pass does not increase the total stage-processing time per chunk. Let T be the time a run-once stage spends on a chunk, with p prelude stages, m loop stages and c coda stages. Each loop visit takes T/2:
A chunk therefore takes the same compute time as in a plain S-stage pipeline. The additional cost is communication: five stage-to-stage transfers per chunk (ping-pong, row 3) instead of three (row 2); it’s a small drawback, though, as these communications are small. Fewer, larger loop stages limit that overhead.
Interleaving requests to fill the pipeline bubbles
Ping-pong balances the work across GPUs, but keeping them busy also requires the right execution order. With a single request, the fixed execution order leaves a gap (Figure 7, top). S1 finishes chunk R0C0’s first pass and sends it to S2. That chunk cannot return for its second pass until S2 finishes, and the next chunk is queued behind it. S1 therefore sits idle for a full slot, one in every three.
The fix is a scheduling change. We interleaved chunks from two requests, so while one chunk moved through S2, S1 could begin work on the other.
Suppose we have two requests, each with chunks 0–3. Instead of processing R0C0, R0C1, R0C2…, we schedule R0C0, R1C0, R0C1, R1C1, and so on. While R0C0 is on S2, S1 runs R1C0’s pass 1. By the time that finishes, R0C0 has wrapped back. Each loop stage alternates between chunks on pass 1 and chunks on pass 2.
The interleaving only needs to be as deep as the number of times we loop. In practice, each prefill step carries two micro-batches, A and B, with one chunk from each request. Each loop stage runs A1 → B1 → A2 → B2: A’s first pass, B’s first pass, then their second passes. For this two-stage, two-pass layout, two micro-batches fill the scheduling gap.
In the illustrated schedule, A returns to S1 just as S1 finishes B’s first pass. The remaining idle time comes from filling and draining the pipeline, which shrinks as the stream of chunks gets longer.
Two requests are not a fundamental requirement. Strictly, chunk C1 only depends on chunk C0 on the same stage, since that stage holds C0’s KV. Because the chunked-prefill scheduler does not depend on how individual pipeline stages operate, we changed the execution order within a step rather than replacing the scheduler.
The traces show the improvement. With 32K-token chunks, a single 256K-token prompt leaves S1 and S2 only 59% and 65% busy. Interleaving two 128K-token prompts, with one chunk from each per step, raises utilization to 91% and 87%. Both requests finish in 8.5 seconds, compared with 11.8 seconds when run back to back.
Measured throughput on 8K prompts
With 8K-token prompts, concurrency 4 and stage boundaries at [26, 40, 54], S0–S2 reach 98–99% utilization, while S3 reaches 85%. These runs exclude the speculator, leaving headroom on S3 for its additional work.
At this context length, first- and second-pass visits take nearly the same time, 21.5–21.7 ms, keeping the loop stages closely balanced with S0. Longer prompts shift that balance slightly.
GLM 5.4 performs 1.36× as much work per token as GLM 5.3, implying a compute-only throughput ceiling of about 0.74× under comparable conditions. Most of the remaining shortfall comes from the loop stages performing 28 layer visits per chunk versus S0’s 26. Interleaving delivered the largest improvement by filling the scheduling gaps; the remaining imbalance is comparatively small.
Hetero: one two-GPU loop stage
Heterogeneous (“hetero”) pipeline parallelism keeps the KV local by making the loop stage wider rather than shorter. The model uses three pipeline stages (PP3), with the entire loop on a two-GPU middle stage using query parallelism (QP2).
The balancing principle is the same: the middle stage does twice the FLOPs of its neighbors, but over twice the GPUs, so the FLOPs per GPU match.
Each GPU processes half the chunk’s query tokens through all 28 core layers on both passes. We shard over query tokens, not context: both GPUs retain the full KV cache for the loop layers. Each layer therefore only needs to all-gather the new tokens’ KV latents, which takes about 1% of a layer’s execution time.
The MoE runs two-way sharded across the two GPUs as EP2. Its dispatch and combine operations cost about 25% of a layer’s execution time. Mega MoE hides most of that exchange behind computation.
This communication is the cost of widening the stage. It occurs at every loop layer, and some remains exposed even with Mega MoE. The two-GPU stage therefore takes slightly longer than its neighbors despite their similar FLOPs per GPU. It sets the pipeline’s pace, leaving S0 and S3 waiting briefly on each chunk. Essentially, hetero trades ping-pong’s interleaving for small bubbles of its own.
The pipeline is a straight line again: chunks follow request order, with no wrap or interleaving required. Sparse attention keeps the query workload balanced because every query has the same top-k budget.
Hetero finishes this short batch sooner because each chunk follows a shorter path. Its loop stage remains the bottleneck, however, leaving small bubbles on S0 and S3 with every chunk. Ping-pong’s gaps are limited to pipeline fill, drain and the short transfers between stages.
Because the pipeline is shorter, a single chunk gets through sooner, and nothing ever waits for a wrap. That matters most when there’s one long prompt and nothing to interleave it with. To estimate hetero’s performance in this setting, we fitted a model to the long-prompt traces. It matched the measured 128K, 256K and 2×128K runs within 0.6%, and we used it to project the hetero layout’s execution time:
Modeled prefill time, not an end-to-end build. Hetero assumes Mega MoE hides the EP2 exchange.
For GLM 5.4, that makes hetero the better layout. With Mega MoE hiding nearly all of the EP2 exchange, it’s 12–19% faster for one long prompt and 9–14% faster for two. On many short prompts, both layouts reach about 53.9K tokens/s. Hetero is no slower in any of the cases evaluated.
That lead depends on how much of the EP2 exchange Mega MoE can hide behind computation. With half the EP2 exchange exposed, the lead narrows to 9–14% for one prompt and 6–8% for two. With none hidden, it falls to 2–8% for one prompt and disappears for two.
Hetero wins on latency because a chunk crosses three stages instead of making five hops through four. Its weak spot is the communication inside the loop stage, but in this two-GPU layout, that is limited to a two-way KV all-gather and an EP2 exchange that Mega MoE can largely hide behind computation.
Deeper loops favor ping-pong
Hetero’s advantage depends on the loop running only twice. Both layouts can handle a loop that runs L times, but they pay for it in different places.
Hetero balances FLOPs per GPU by making the loop stage wider, so an L-pass loop needs an L-GPU stage running QP-L. That stage has to communicate inside every loop layer. A wider stage adds more communication and leaves less compute per GPU to hide it behind, since each GPU gets only 1/L of the chunk’s queries.
Any exposed communication slows the loop stage and creates bubbles on the surrounding stages. Hetero also replicates the loop’s KV cache across all L GPUs, consuming memory that could otherwise support longer contexts.
Ping-pong makes the loop stages shorter instead. It spreads the core across more GPUs, each holding a smaller set of layers that it runs L times. Stage boundaries still carry the residual stream and limited metadata, while each layer’s KV stays on the GPU that wrote it.
The growing cost is in scheduling and transfers between stages. A chunk wraps L − 1 times, so the loop stages need L micro-batches in flight to stay busy, and each chunk makes a few more hops. With enough concurrent prefill traffic, both close to optimal.
For a two-pass loop like GLM 5.4’s, hetero is the simpler and faster choice. As loops get deeper, the wider loop stage communicates more and hides less of it, and that exposed communication becomes bubbles across the pipeline. Ping-pong’s extra cost stays in scheduling, which is where it becomes the better fit.
Alternative sharding schemes
Pipeline parallelism is one option for serving looped models, not a universal answer. Query/token parallelism, context parallelism and data parallelism offer other ways to distribute the work, and can be combined with pipeline parallelism.
Each of these strategies has its own trade-off curve between throughput and latency, and the curves cross in different places depending on prompt lengths, concurrency, latency targets and how deep the loop is. One can even combine these various parallelism strategies to achieve different characteristics on the Pareto curve. No single layout wins for every workload.
That choice is what we work on at Fireworks. For any model, we can help you find the layout that fits your traffic and latency targets.
References
- Pipeline Parallelism in SGLang: Scaling to Million-Token Contexts and Beyond. LMSYS, January 2026.
- Deploying DeepSeek on GB300 NVL72: Big Wins in Long-Context Inference. LMSYS, February 2026.
- SGLang and Miles Add Day-0 Support for Kimi K3. LMSYS, July 2026.
- Kimi K3.1 Pro: Day-0 Inference and RL Support. SGLang.