同步与断图开销:torch.nonzero(~halted) 返回的 active_idx 形状在每步动态变化,一方面迫使 CUDA 流等待 GPU 向主机回传长度数值触发 StreamSynchronize 阻塞,另一方面会彻底破坏基于静态显存地址的 CUDA Graph 捕获执行(改由 CPU 逐算子重新下发发射开销,延迟反而恶化);
带宽遮盖与额外访存:即便忍受动态开销,只要批里还剩下至少 1 个活跃词元($1 \le \alpha B < B_{\text{crit}}$),共享核心的全套权重仍必须从 HBM 完整读取 100%。减少的只是原本富余、被访存完全掩盖掉的计算周期,反而凭空增加了 Gather 与 Scatter 造成的激活读写流量 $4\alpha B d b_a$(搬运字节宽为 $b_a$ 的激活张量)以及主机同步延时;
David Raposo et al. (2024). Mixture-of-Depths: Dynamically Allocating Compute in Transformer-based Language Models. arXiv:2404.02258
Peng Jin et al. (2024). MoE++: Accelerating Mixture-of-Experts Methods with Zero-Computation Experts. arXiv:2410.07348
Meituan LongCat Team, Bayan, Bei Li et al. (2025). LongCat-Flash Technical Report. arXiv:2509.01322
Papers on adaptive depth and dynamic early exit routinely describe skipping half the layers on easy tokens as halving compute. Measured strictly in abstract FLOPs, that ratio is exact. Yet when an engineer wires token-level early exit into an actual GPU serving engine and runs a profiler, wall-clock latency frequently stays flat—and under moderate concurrency, often gets slightly worse.
This gap is not a framework bug or Python dispatch flaw. It follows directly from the Roofline balance between GPU tensor-core compute throughput and HBM memory bandwidth. Quantifying that hardware ridge point separates dynamic compute designs that yield genuine serving speedups from those that only discard already-hidden arithmetic cycles.
1. Below $B_{\text{crit}} \approx 295$, Skipping Arithmetic Saves Zero Latency#
Consider a concrete decoding slice using Horace He's GPU Roofline first-principles framework and Google DeepMind's Scaling Book: suppose an inference batch currently serves $B = 32$ sequences, and an ideal halting classifier identifies $75\%$ of tokens as converged, leaving only $\alpha B = 8$ difficult tokens to proceed into the next Transformer block. Arithmetic FLOPs drop by three-quarters; how much faster does that layer run?
To answer precisely, compute the arithmetic intensity (AI) of a dense linear projection $[B, d_{\text{in}}] \times [d_{\text{in}}, d_{\text{out}}]$. During low-batch decode ($B \ll d_{\text{in}}, d_{\text{out}}$), activation transfers are negligible relative to matrix weights, so FLOPs total $2 B d_{\text{in}} d_{\text{out}}$ while streaming weights from HBM transfers $b_w d_{\text{in}} d_{\text{out}}$ bytes ($b_w = 2$ for BF16). Equating compute execution time with HBM transfer time locates the Roofline ridge batch size $B_{\text{crit}}$:
It is important to separate the datasheet theoretical ridge (295 tokens) from the achieved H100 empirical ridge (~240–270 tokens): real cuBLAS/CUTLASS BF16 GEMMs sustain roughly 700–850 TFLOP/s over 2.8–3.0 TB/s sustained HBM bandwidth, placing the practical knee slightly below 295. Precision regimes also split sharply:
FP8 (W8A8): FP8 doubles Tensor Core peak ($\sim 1979\text{ TFLOP/s}$) while halving $b_w$ from $2$ to $1$, yielding $B_{\text{crit}} = \frac{1979}{3.35} \cdot \frac{1}{2} \approx 295$ at the exact same spot;
W4A16 (4-bit weights + BF16 activations): quantizing weights to $b_w = 0.5\text{ B}$ while executing on BF16 Tensor Cores ($989\text{ TFLOP/s}$) cuts the ridge 4× lower to $B_{\text{crit}} = \frac{989}{3.35} \cdot \frac{0.5}{2} \approx \mathbf{74\text{ tokens}}$—explaining why fused Marlin W4A16 kernels saturate HBM weight bandwidth and hit the compute roof much earlier;
W4A4 NVFP4 (NVIDIA B200): once native 4-bit Tensor Cores arrive alongside higher HBM3e bandwidth ($\sim 9{,}000\text{ TFLOP/s}$ FP4 peak, $8.0\text{ TB/s}$, $b_w = 0.5\text{ B}$), the ridge climbs back up to $\frac{9000}{8.0} \cdot \frac{0.5}{2} \approx \mathbf{281\text{ tokens}}$.
Calculation
Worked Verification (70B FFN Projection, $[B, 8192]\times[8192, 28672]$ in BF16): One projection matrix weighs $8192 \times 28672 \times 2\text{ B} \approx \mathbf{469.8\text{ MB}}$, taking $\approx \mathbf{140.2\,\mu\text{s}}$ purely to stream from H100 HBM ($3.35\text{ TB/s}$). Corresponding Tensor Core compute takes $2\cdot 32\cdot 8192\cdot 28672 / 989\text{ TFLOP/s} \approx \mathbf{15.2\,\mu\text{s}}$ at $B = 32$ and shrinks to $\mathbf{3.8\,\mu\text{s}}$ at $B = 8$—entirely buried inside the $140\,\mu\text{s}$ HBM weight fetch.
Batch B 64Keep ratio α 0.50HBM Memory-Bound (1.00×)
Figure 1: Sweep batch B and active keep ratio α: whenever both B and αB sit left of B_crit, wall-clock time stays locked on HBM weight reads (1.00×).
In sparse MoE layers with $E$ routed experts and Top-$k$ active per token, each expert receives only $B_{\text{expert}} = B \cdot \frac{k}{E}$ tokens on average. Because an expert's full matrix streams from HBM whenever at least one token hits it, pushing per-expert occupancy past $B_{\text{crit}}$ scales the global batch ridge by $E/k$:
For $E = 256,\; k = 8$ ($B_{\text{crit}} \approx 295$), the global threshold shifts all the way to $B_{\text{global, crit}} \approx 295 \times \frac{256}{8} = \mathbf{9{,}440\text{ tokens}}$. This directly governs when FFN Null Experts save HBM weight reads: routing one token to a null slot skips an HBM weight fetch only if zero other tokens in the current EP rank's microbatch route to that real expert; if any other token still hits it, 100% of that expert's weights still stream from HBM and null routing saves only FLOPs and dispatch payload.
The runnable Roofline sweep below compares H100 arithmetic intensity and step latency for BF16 vs. W4A16 across $B \in [1, 1024]$ (with an optional torch.cuda.Event GPU timing check):
That ridge explains why shrinking $B = 32$ down to $8$ saves essentially zero wall-clock time, and matches controlled checkpoint probing. In low-batch GPU early-exit probing on dense 27B–32B checkpoints (without custom fused skip kernels), dropping final layers collapses generation immediately, whereas skipping 7–8 middle layers retains roughly $90\%$ output agreement yet yields zero wall-clock speedup on GPUs. Even when Logit-Lens probes are paired with a hard-sample buffer pool to batch uncertain tokens separately, Tensor Cores still sit idle waiting for weights across the HBM bus unless active pool occupancy surpasses $B_{\text{crit}}$.
Examining that 6-token compaction trace reveals three concrete failure modes:
Host synchronization and graph breaks: torch.nonzero(~halted) produces a runtime-variable tensor shape, forcing a blocking GPU-to-CPU synchronization to read the active count and breaking CUDA Graph static capture—replacing ultra-low-overhead graph replay with per-kernel CPU launch latency.
Bandwidth dominance and extra activation I/O: Even if dynamic launch penalties were ignored, as long as even one token in the batch remains active ($1 \le \alpha B < B_{\text{crit}}$), 100% of the layer's weight bytes still have to stream from HBM. Every skipped FLOP comes out of idle headroom already masked by memory latency, while Gather/Scatter compaction adds $4\alpha B d b_a$ bytes of activation I/O (moving activations of byte width $b_a$, not weights) plus synchronization delay.
Early-exit KV recomputation trap and latent overthinking: Consider a two-piece phrase such as ["compute", "matrix"]. If "compute" exits after pass 1, its pass-3 KV Cache slot stays empty or stale when "matrix" reaches pass 3—forcing either degraded distant attention or hidden KV recomputation that erodes savings. Conversely, forcing converged states through excessive loops triggers latent overthinking, where target logit margins peak early and decline in deeper iterations.
For token-level compaction to pay off in wall-clock runtime, clamping both pre- and post-compaction occupancy at the $B_{\text{crit}}$ bandwidth floor, reclaimed Tensor Core time must strictly exceed compaction activation I/O and host-sync costs:
$$\begin{aligned}
&\frac{2\big(\max(B, B_{\text{crit}}) - \max(\alpha B, B_{\text{crit}})\big) P_{\text{block}}}{F_{\text{peak}}} \\
&\qquad > \frac{4\alpha B d b_a}{\mathrm{BW}_{\text{HBM}}} + T_{\text{sync}}
\end{aligned}$$
Only at high batch occupancy cleanly past the ridge point—such as shrinking an active batch from $B = 1024$ to $\alpha B = 512$, or $2048$ to $1024$ during saturated batched Prefill—does layer latency sit on the compute roof where reducing tokens moves wall-clock runtime proportionally. If $B = 1024$ drops by $75\%$ to $256$, compute savings clip at the $B_{\text{crit}} \approx 295$ floor rather than scaling down to $256$.
2. Five Scheduling Workarounds and Where Each Hits Friction#
To reconcile dynamic compute allocation with static GPU shapes and bandwidth bounds, systems researchers have converged on five main scheduling strategies:
Scheduling Design
Shape & Density Mechanism
Primary Constraint
1. Fixed Steps / Bucketing
Removes per-token variance; fixed $K \in \{2,3,4\}$ or request queues
Zero dynamic sync; 100% CUDA Graph & full KV; no intra-seq skip
2. MoD (Mixture-of-Depths)
Enforces static router cap $C = \lfloor c S \rfloor$ via Top-$C$
Static Top-$C$ routing in prefill: During pretraining or Prefill, all $S$ tokens exist concurrently so Top-$C$ routing selects a clean static fraction $c S$. Consider a 6-token sequence with capacity ratio $c = 0.5$ ($C = 3$) and router scores [0.12, 0.25, 0.05, 0.91, 0.84, 0.30]: the three highest-scoring tokens (0.91, 0.84, 0.30) enter the Transformer block while 0.12, 0.25, 0.05 skip via the residual connection.
Autoregressive decode & auxiliary classifier drift: During autoregressive Decode, only one token arrives per sequence, eliminating cross-sequence Top-$C$ ranking. Even when an auxiliary binary classifier is trained alongside Top-$C$ for single-token causal decoding, threshold gating breaks static quotas and diverges from fixed-capacity training behavior.
Prematurely dropping tokens & KV holes: Fixed quotas prematurely drop tokens on hard math prompts where more than $c S$ tokens genuinely require compute, and skipping a full layer punches an unpopulated hole in the KV Cache at position $t$. Consequently, autoregressive models like Gemma 2, 3, and 3n skip MoD, whereas non-causal architectures (ViT, DiT, and discrete diffusion LLMs) adopt it without causal KV holes.
⤢ Zoom
Figure 2: Mixture-of-Depths static Top-K capacity routing around Attention and MLP blocks alongside per-layer routing heatmaps compared with Vanilla Transformer and Early-Exit (arXiv:2404.02258). (Source: Raposo et al., 2024, Fig. 1)
The two sides of the figure contrast the routing mechanics directly: on the left, token $x_i$ (w=0.41) bypasses Self-Attention and MLP along the residual wire while $x_{i+1}$ (w=0.65) traverses both sublayers and scales back into the residual sum; on the right, the layer-by-sequence heatmaps (purple = Use block, orange = Route around block) show Early-Exit forming monotonic orange columns from the exit layer upward, whereas MoD forms a checkerboard pattern where skipped tokens re-enter computation in deeper layers.
Batching Request A's pass 1 alongside Request B's pass 4 into a single matrix multiply [2, d] @ W_shared works only because both passes reuse the identical matrix $W_{\text{shared}}$; in a standard untied Transformer where $W_1 \neq W_4$, merging different layers into one GEMM is impossible. The schedule below illustrates two active slots across four beats when User A exits after pass 2:
Beat
Slot 0
Slot 1
Effective GEMM Utilization
Beat 1
User A · Loop 1
Idle
$1/2$ (waiting for refill)
Beat 2
User A · Loop 2 (exit)
User B · Loop 1
$2/2$ (cross-pass batching)
Beat 3
User C · Loop 1
User B · Loop 2
$2/2$ (immediate slot refill)
Beat 4
User C · Loop 2
User B · Loop 3
$2/2$ (sustained static width)
Two systems costs bound CDB in production runtimes. First, standard PagedAttention assumes all requests in a batch execute the same physical layer $\ell$ via 1D (seq_id, logical_block) lookups, whereas packing mixed loop steps requires 2D (req_id, loop_step) page mappings and fractures static CUDA Graph templates. Second, many looped checkpoints share $W_{\text{shared}}$ while keeping per-step untied RMSNorm scales $\gamma^{(t)}$ and residual gates $\alpha^{(t)}$ across loop steps $t$—mixing pass $t=1$ and pass $t=4$ inside one [a_new; b_mid] batch breaks homogeneous fused RMSNorm + Linear kernels, forcing either unfused passes or per-row step_id-indexed norm gathers.
2.3 Confining Dynamic Compute to FFN Null Experts (MoE++ to LongCat-Flash)#
To obtain per-token compute elasticity without touching causal Attention or puncturing KV caches, MoE++ (Jin et al., 2024) leaves Attention intact and augments the MoE FFN router pool with three zero-computation slot types (Zero, Copy, and Const). As shown below, whereas vanilla Top-2 routing in panel (a) dispatches exclusively to real FFN experts (FFN_1..FFN_N), panel (b) lets MoE++ send one slot to a real expert (FFN_3) and the second to Copy (identity pass-through), alongside Zero and Const slots that avoid FFN matrix multiplies altogether.
⤢ Zoom
Figure 3: MoE++ augmenting vanilla Top-2 FFN experts with Zero, Copy, and Const zero-computation experts so tokens can skip dense FFN GEMMs (arXiv:2410.07348). (Source: Jin et al., 2024, Fig. 1)
Scaling this principle to a $560\text{B}$-parameter sparse backbone, LongCat-Flash (Meituan LongCat Team, 2025) pairs zero-computation experts with ScMoE compute-communication overlap. Easy tokens route to null slots while complex tokens draw additional real experts, letting per-token active parameters adapt smoothly between $18.6\text{B}$ and $31.3\text{B}$ (averaging $\sim 27\text{B}$) and yielding ~20% end-to-end throughput improvement. Yet frontier families such as DeepSeek, Qwen, and Kimi still stick to fine-grained fixed Top-$K$ routing for three practical reasons:
Training fragility and router collapse: asymmetric gradient magnitudes between zero-compute slots and real FFN experts easily destabilize routing without careful Z-loss or bias tuning;
EP All-to-All stragglers and conditional HBM savings: under Expert Parallelism across ranks, uneven real-expert assignments leave lightly loaded GPUs stalled at the All-to-All barrier waiting on the busiest rank—and as shown by the per-expert Roofline bound, a null-routed slot skips an HBM expert weight read only when zero other tokens on that rank hit that real expert;
Zero weight or KV VRAM savings: all expert parameters remain pinned in HBM, and full Attention still writes 100% of the KV Cache.
⤢ Zoom
Figure 4: LongCat-Flash ScMoE architecture combining shortcut FFN–MLA–FFN compute-communication overlap with a Top-k router over N FFN experts and Z zero-computation experts (arXiv:2509.01322). (Source: LongCat Team, 2025, Fig. 2)
In the LongCat-Flash ScMoE block above, Multi-head Latent Attention (MLA) at the bottom feeds both the central Top-k Router (selecting across $1\dots N$ peach FFN Experts and $1\dots Z$ yellow Zero-computation Experts) and a parallel green/yellow dense shortcut branch (FFN -> MLA -> FFN) on the left, overlapping dense shortcut compute with sparse MoE All-to-All communication before summing at Output Hidden.
Figure 5: Batch slot layouts across naive early exit, CDB loop refilling, and LongCat-Flash FFN null experts.
Across production GPU deployments, two crisp quantitative decision rules govern dynamic depth scheduling:
When operational decode batches sit below the Roofline ridge point ($\alpha B < B_{\text{crit}} \approx 295$ theoretical / ~240–270 achieved for BF16/FP8 dense, ~74 for W4A16, or $B_{\text{crit}} \cdot E/k$ for sparse MoE), avoid per-token early-exit compaction; rely on sequence-level pass bucketing, CDB if deeply customized, or FFN null experts that leave Attention untouched.
Reserve token-level compaction strictly for saturated large-batch prefill or extreme-concurrency queues ($\alpha B \gg B_{\text{crit}}$, or $B_{\text{crit}} \cdot E/k$ in MoE) where compute savings clamped at the ridge floor genuinely outweigh gather/scatter activation I/O and host-device synchronization.
The Roofline lesson is strict: dynamic sparsity only accelerates GPU inference when it reduces bytes read from HBM—whether weights or KV—not just arithmetic FLOPs already sitting in the idle shadow.