---
title: Continuous Depth-wise Batching (CDB)
url: https://www.emergentmind.com/topics/continuous-depth-wise-batching-cdb
type: topic
---

# Continuous Depth-wise Batching (CDB)

Searching arXiv for the specified papers and closely related work.
I’ll retrieve the arXiv metadata for the cited papers to ground the article.
Continuous Depth-wise Batching (CDB) is an inference paradigm introduced alongside Relaxed Recursive Transformers to exploit the looped structure of Recursive Transformers and maximize hardware utilization, especially when combined with early-exit mechanisms [2410.20672]. In this setting, a model is organized as repeated applications of a shared block, and inference is scheduled not only across sequences but also across depth. The central idea is that whenever a sample leaves a depth stage—because it has exited early or completed that iteration—its slot in the next depth can be filled immediately by another sample already waiting at that depth or by a new request entering at depth 1. This reframes batching as a depth-aware pipeline and is intended to close utilization gaps left by vanilla batching or early exit.

## 1. Motivation and Operating Principle

Under standard Transformer inference, even with continuous sequence-wise batching, new requests can only enter the pipeline once the entire current batch has finished all layers or decoding timesteps. The stated motivation for CDB is that this leaves the device under-utilized whenever some sequences finish earlier than others, such as under early exiting, but the batch cannot advance [2410.20672].

Recursive Transformers provide the structural precondition for CDB. In the formulation described for Relaxed Recursive Transformers, the same $K$-layer block is applied repeatedly, so depth can be interpreted as loop iteration. This makes it possible to treat each loop iteration as a stage in a pipeline, all using the same weights. CDB generalizes continuous batching from the time or timestep dimension to the depth or loop dimension. A sample that finishes one stage can immediately free capacity that is reused either by another in-flight sample at a compatible depth or by a brand-new request at the first stage.

This suggests that CDB is not merely a batching convenience, but a scheduling policy tied to a particular architectural regularity: repeated execution of a shared block. Early exiting amplifies the benefit because samples do not all consume the same number of loop iterations.

## 2. Integration with Recursive Transformers and Early Exit

The architectural context is a Recursive Transformer in which the model consists of $B$ loop iterations of a shared $K$-layer block. Depth $\ell$ of the full $L = B \cdot K$ layers corresponds to loop index $\lceil \ell / K \rceil$ modulo the shared block structure [2410.20672]. In the relaxed variant, stage-specific LoRA adapters can be attached while preserving the shared backbone.

Early exiting is applied at loop iteration $i$, that is, at depth $i \cdot K$, by evaluating a confidence test on the partial hidden state. If the confidence is at least a threshold, inference terminates immediately and the remaining loops are skipped. CDB takes this model and interprets each of the loop iterations as a pipeline stage $S_1, S_2, \ldots, S_{B}$. A queue $Q_k$ is maintained for samples waiting for stage $S_k$. New requests are admitted into $Q_1$; a sample that does not exit at stage $S_i$ is enqueued into $Q_{i+1}$.

The resulting data flow is stage-centric. Worker threads or an asynchronous scheduler repeatedly pull up to `batch_size` samples from a stage queue whose depth is ready, execute the shared $K$-layer block together with any stage-specific LoRA adapters, and then either emit a final token or enqueue the sample into the next depth queue. Because the weights are shared across stages, stage-local work is homogeneous enough to support repeated kernel launches over the same block. A plausible implication is that the shared-block design reduces some of the coordination complexity that would arise if every depth used a distinct parameterization.

## 3. Formalization and Throughput Analysis

The theoretical analysis introduces the following notation. Let $B$ denote the maximum batch size. Let $K$ be the number of layers in the shared block, and let $B_{\text{loop}}$ be the number of loop iterations, so that $L = K \cdot B_{\text{loop}}$. Let $T_k$ be the time to process the $k$-th layer of the shared block on a full batch of $B$ samples, or scaled accordingly if fewer samples are present. For simplicity, the analysis assumes $T_1 = T_2 = \cdots = T_K = T_{\text{layer}}$, so the time per loop iteration is
$$
T_{\text{block}} = \sum_{k=1}^{K} T_k \approx K \cdot T_{\text{layer}}.
$$

Let $f_i$ be the fraction of tokens or sequence positions that survive through at least $i$ loop iterations, meaning they have not exited before stage $i$. By definition, $f_1 = 1$ and $f_{B_{\text{loop}}+1} = 0$. The average compute per token under early exit is then
$$
C_{\text{avg}} = \sum_{i=1}^{B_{\text{loop}}} f_i \cdot T_{\text{block}}.
$$

Vanilla throughput, with continuous sequence-wise batching but no depth-wise reuse, is given as
$$
\text{Throughput}_v = \frac{B}{L \cdot T_{\text{layer}}} = \frac{B}{B_{\text{loop}} \cdot T_{\text{block}}}.
$$

For CDB, at steady state, each stage $S_i$ is kept busy with $B$ samples on average until those samples exit. The wall-clock time to complete one round of outputs for $B$ samples is therefore $C_{\text{avg}}$, yielding
$$
\text{Throughput}_{\text{CDB}} = \frac{B}{C_{\text{avg}}} = \frac{B}{\sum_{i=1}^{B_{\text{loop}}} f_i \cdot T_{\text{block}}}.
$$

The relative speedup is
$$
\text{Speedup} = \frac{\text{Throughput}_{\text{CDB}}}{\text{Throughput}_v}
= \frac{B_{\text{loop}}}{\sum_{i=1}^{B_{\text{loop}}} f_i}.
$$

The paper provides an illustrative case with $B_{\text{loop}} = 3$: if $40\%$ of tokens exit after the first loop, so $f_2 = 0.6$, $30\%$ exit after the second, so $f_3 = 0.3$, and the rest go full depth with $f_4 = 0.1$, then $\sum f_i = 1 + 0.6 + 0.3 = 1.9$, giving a speedup of $3/1.9 \approx 1.58\times$ [2410.20672]. The same analysis states that, with deeper early-exit distributions measured in the paper, $\sum f_i$ can be as low as approximately $0.7 \cdot B_{\text{loop}}$, yielding $2$–$3\times$ gains.

## 4. Scheduling Procedure and Systems Realization

The high-level algorithm initializes queues $Q[1..B_{\text{loop}}]$ as empty, admits new requests into depth 1 while $Q[1].\text{size} < B$ and requests are available, and then iterates over stages looking for a nonempty queue [2410.20672]. For the first nonempty stage, it dequeues up to $B$ samples, runs `SharedBlockForward(batch, stage=i)`, and then applies the confidence test. Samples whose confidence reaches the threshold emit their final token; samples that do not exit and are not yet at the last loop iteration are enqueued into the next stage.

Two aspects are central to the intended behavior. First, stage 1 is always filled up to $B$ when possible, so the device does not idle waiting for new inputs at the start of a loop. Second, whenever a sample exits early, its slot is effectively freed at all deeper stages and is immediately reused by another sample in the appropriate queue or by a fresh request in $Q_1$.

The implementation discussion emphasizes host-side scheduling and asynchronous execution. A small scheduler tracks $Q[1..B_{\text{loop}}]$ and launches a CUDA kernel for whichever stage has available data and a free compute stream. Because all depths use the same shared weights, mixed-depth inputs can, if memory allows, be concatenated so that a single fused kernel processes them in one pass. For autoregressive decoding, each sample carries its own key-value cache per layer; when a sample moves from stage $i$ to stage $i+1$, its cache moves with it, and exited samples’ caches can be freed immediately. The maximum simultaneous number of samples in flight across all depths is $B_{\text{loop}} \cdot B$, though only $B$ are present at any one depth. Multi-GPU or multi-stream setups can pipeline stages in parallel if desired.

## 5. Empirical Results and Performance Claims

The reported experiments simulate CDB paired with oracle early-exiting on several models, including Gemma 2B, TinyLlama 1.1B, and Pythia 1B [2410.20672]. The headline findings concern throughput rather than model quality, because the paper explicitly states that no accuracy degradation is incurred by CDB itself: the model’s predictions and exit criteria remain identical. The stated trade-off arises only when higher-rank LoRA is used in relaxed recursive variants, which slightly increases model size.

| Configuration | Throughput claim | Notes |
|---|---:|---|
| Vanilla Pythia 1B | $\sim 1.00\times$ baseline; 1,080 tokens/sec | No CDB |
| Pythia 1B + CSB | $1.41\times$; $\approx 1{,}528$ tok/s | Continuous sequence-wise batching |
| 2-block recursive Pythia ($\approx 0.99$B params) + CDB + early exit | $2.66\times$; $\approx 2{,}877$ tok/s | Recursive conversion with CDB |
| Relaxed recursive variants, LoRA rank $= 64/128/256/512$ | $2.0$–$1.6\times$ | Throughput traded for improved accuracy |

Across SlimPajama, RedPajama, and PG19, the average CDB gains are reported as $2$–$3\times$ over vanilla, outperforming continuous sequence-wise batching alone. For Gemma 2B, the paper states that near $4\times$ end-to-end speedup is theoretically attainable when comparing recursive and vanilla settings. Latency to first token is also described as improving because stages are never starved waiting for full-batch data.

These results should be read with two distinctions in mind. First, the measurements are tied to recursive or relaxed recursive models rather than to unmodified dense Transformers. Second, the paper describes the CDB results as simulated with oracle early-exiting, so the gains are coupled to the assumed exit behavior.

## 6. Relation to Earlier Depth-Based Batching and Conceptual Boundaries

CDB is distinct from the depth-based on-the-fly batching heuristic developed for dynamic computation graphs in "On-the-fly Operation Batching in Dynamic Computation Graphs" [1705.07860]. In that earlier setting, the computation is modeled as a directed acyclic graph $G = (V, E)$, node depth is defined as the length of the longest path from any leaf node to a node, and execution proceeds depth by depth, signature by signature, batching together ready nodes at equal depth that share the same signature. Grouping is performed over graph nodes, and correctness follows from the fact that if $u \to v$ then $\text{depth}(u) < \text{depth}(v)$.

CDB operates on a different object and under different assumptions. Its stages are loop iterations of a shared Transformer block rather than arbitrary nodes in a dynamic computation graph. Its queues track samples waiting at successive depths, and the mechanism is specifically designed to exploit recursive weight sharing together with early exit. A common confusion arises from the shared phrase “depth-wise batching,” but the two methods address different scheduling problems. The 2017 method batches same-signature operations at the same graph depth; CDB pipelines request flow across model depths in a Recursive Transformer.

The contrast is also informative at the level of opportunity and constraint. The 2017 paper notes that strict depth-based batching can miss cross-depth opportunities and that agenda-based scheduling can recover some of them [1705.07860]. CDB, by comparison, is explicitly designed to capitalize on movement between depths, because a sample that leaves one stage immediately creates reusable capacity elsewhere in the pipeline. This suggests that the reuse of a single shared block is not incidental but constitutive of the method’s efficiency model.

## 7. Limitations, Trade-offs, and Scope

The paper presents CDB as a promising new inference paradigm enabled by the Recursive Transformer when paired with early exiting [2410.20672]. That phrasing is itself a boundary condition: CDB is not introduced as a universally applicable batching strategy for arbitrary Transformer deployments, but as one that depends on the recursive weight-sharing structure and benefits particularly from heterogeneous exit depths.

The reported performance gains are theoretical or simulated under oracle early-exiting, and the throughput analysis assumes a simplified per-layer timing model with $T_1 = \cdots = T_K = T_{\text{layer}}$. This suggests that realized speedups may depend on how closely an implementation matches the assumed steady-state pipeline behavior, on memory available for mixed-depth or multi-stream execution, and on the actual survival fractions $f_i$. The paper nevertheless states that the model’s predictions and exit criteria remain identical under CDB itself, so the mechanism is presented as a systems-level scheduling change rather than an approximation to model computation.

Within that scope, CDB is characterized by three defining properties: it extends batching from the sequence dimension to the depth dimension, it uses stage queues over repeated shared blocks, and it derives its throughput advantage from keeping those depth stages busy while early-exiting samples release capacity.

Source: https://www.emergentmind.com/topics/continuous-depth-wise-batching-cdb