Continuous Depth-wise Batching
- Continuous depth-wise batching is a dynamic inference paradigm that leverages weight-shared, recursive Transformers to batch processing across both token time and layer depth.
- It employs early-exit mechanisms and FIFO scheduling to maximize accelerator utilization, yielding a 2–3× speedup in autoregressive token generation.
- Empirical results on models like Gemma 2B demonstrate practical throughput gains, validating the efficiency of batching across both sequence and depth dimensions.
Continuous Depth-wise Batching (CDB) is a dynamic inference paradigm that leverages the parameter-tied (recursive) structure of Transformers to pipeline sequence processing not only in the conventional time (token) dimension, but also across model depth (layer iterations). CDB exploits repeated blocks within a recursive Transformer—enabled by weight sharing across layers—to maximize hardware utilization and reduce idle compute slots, achieving substantial improvements in throughput for autoregressive generation, especially when combined with early-exit mechanisms. When deployed in practice, CDB demonstrates a 2–3× increase in token-generation throughput relative to static, layer-distinct Transformers, subject to model configuration and early-exit dynamics (Bae et al., 2024).
1. Formal Definition and Mechanism
Continuous Depth-wise Batching operates in recursive Transformers constructed from a total depth , reorganized as looping blocks of size , with denoting the th layer of a shared block. For token and layer index , the forward pass is:
CDB maintains, during runtime, up to active samples at each block-iteration stage . For each compute step, up to 0 samples in 1 are processed in parallel by the corresponding shared block 2. Freed slots are immediately filled with either survivors from deeper iterations or new requests entering at the initial block stage. This batched scheduling occurs in both time (token) and depth (block iteration) dimensions and maximizes accelerator utilization for each block function (Bae et al., 2024).
2. Scheduling: Pseudocode and Operational Overview
A high-level scheduling procedure for CDB paired with early-exiting utilizes 3 separate FIFO queues, one per block iteration. At each scheduler tick, a batch is formed (up to 4) for each queue, the shared block 5 is applied, and samples either exit (if the early-exit criterion is satisfied) or proceed to the next block. New requests enter at the first block whenever there is available capacity. The general scheduler pseudocode is:
1
Key features include up to 6 simultaneous batches (one per block), flexible early-exiting, and backfilling to maintain throughput. Batching is conducted across samples invoking the same block parameters, which is feasible only in weight-sharing architectures (Bae et al., 2024).
3. Theoretical and Empirical Throughput Gains
CDB’s effectiveness is quantified against two baselines: static synchronous batching and continuous sequence-wise batching (CSB):
- Static batching: All 7 slots process in lock-step with throughput 8.
- CSB: Batching across token sequences at the same block depth, empirically yielding a speedup 9 (e.g., Gemma 2B: 1080 tok/s → 1528 tok/s).
- CDB: Enables 0-fold depth-wise pipeline; for 1 and 2, this yields a theoretical 3 speedup.
With early-exit, if the mean exit depth is 4, the depth-wise pipeline is shortened, and the effective speedup approaches 5. For example, with Gemma 2B and 6, the observed throughput was 7 tok/s, corresponding to a 8 speedup (Bae et al., 2024).
4. Experimental Configurations and Results
Key configuration details include:
- Models evaluated: Gemma 2B (18 layers, 2 blocks of 9), TinyLlama 1.1B (22 layers, 2 blocks of 11), Pythia 1B (16 layers, 2 blocks of 8).
- Batch size: 9.
- Early-exit criterion: Confidence score (e.g., max-token log-probability) checked after each block iteration; oracle simulations provided idealized throughput.
- Hardware profiling: V100/A100 GPU, per-block timing denoted by 0.
- Token-generation throughput (Gemma 2B, SlimPajama/RedPajama/PG19):
- Stat