This repository contains our paper's implementation of Continuous Depth Batching (CDB), a method for efficient inference with depth-adaptive looped language models. It includes the core inference code, workload and evaluation utilities, and scripts for reproducing the experimental results.
Warning
The backend code will soon be replaced by our much faster implementation at loop-sglang.
The repository provides a continuous batching baseline and continuous depth batching for Ouro (1.4B, 2.6B) and Huginn, including scheduling with and without refill. The engines currently support only greedy decoding. The implementation adapts Hugging Face Transformers' continuous batching and the Ouro and Huginn model releases, with selected designs informed by vLLM and SGLang. See THIRD_PARTY_NOTICES.md for attribution and license details.
-
Install uv.
-
Clone or extract this repository and enter its root directory.
-
Create the machine and cluster configuration:
cp shells/_machine_config.sh.template shells/_machine_config.sh
Edit
shells/_machine_config.shto configure the repository path, cache directories, SLURM settings, GPU type, and FlashAttention backend. -
Install the dependencies:
uv sync --frozen
When using FlashAttention 2, run:
uv sync --frozen --extra fa2
All experiment jobs are submitted through shells/_submit.sh, which reads the machine configuration shells/_machine_config.sh and selects the appropriate SLURM resources.
For example, run the offline throughput sweep for Ouro on the ShareGPT workload with:
MODEL=ouro DATASET=sharegpt ./shells/_submit.sh \
shells/paper/throughput_exit-sweep.sh -- --time=24:00:00The workload must be generated before submitting the throughput sweep.
Arguments before -- are passed to the experiment script, while arguments after -- are passed to sbatch.
Scripts ending in _cpu.sh are submitted to the configured CPU partition, and all other scripts are submitted to the configured GPU partition.
Job logs are written to logs/<script-name>/.
The shell scripts under shells/paper/ reproduce all experiments reported in the paper.
See shells/paper/README.md for details.
The following example loads Huginn with the shared KV cache and early-exit lookahead gate:
from datasets import load_dataset
from looped_cdb.continuous_depth_batching import (
ContinuousDepthBatchingConfig,
ContinuousDepthBatchingEngine,
)
from looped_cdb.eval.model_loading import load_huginn_model, load_huginn_tokenizer
model_id = "tomg-group-umd/huginn-0125"
model = load_huginn_model(model_id)
tokenizer = load_huginn_tokenizer(model_id)
dataset = load_dataset("openai/gsm8k", "main", split="test[:8]")
prompts = [f"Q: {row['question']}\nA:" for row in dataset]
engine = ContinuousDepthBatchingEngine.from_model(
model,
ContinuousDepthBatchingConfig(
max_recurrent_steps=16,
exit_threshold=0.28,
kv_policy="single",
),
)
outputs = engine.generate_batch(
tokenizer(prompts, add_special_tokens=False)["input_ids"],
max_new_tokens=128,
eos_token_id=tokenizer.eos_token_id,
)If you find our code helpful, please cite our paper:
@misc{schwethelm2026cdb,
title={Depth-adaptive Inference of Looped Language Models via Continuous Depth Batching},
author={Kristian Schwethelm and Daniel Rueckert and Georgios Kaissis},
year={2026},
eprint={2608.09444},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2608.09444},
}