Skip to content

About

Depth-adaptive Inference of Looped Language Models via Continuous Depth Batching

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Repository files navigation

Continuous Depth Batching (CDB) for Looped Language Models

arXiv Project Page License: MIT

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.

Scope

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.

Setup

  1. Install uv.

  2. Clone or extract this repository and enter its root directory.

  3. Create the machine and cluster configuration:

    cp shells/_machine_config.sh.template shells/_machine_config.sh

    Edit shells/_machine_config.sh to configure the repository path, cache directories, SLURM settings, GPU type, and FlashAttention backend.

  4. Install the dependencies:

    uv sync --frozen

    When using FlashAttention 2, run:

    uv sync --frozen --extra fa2

SLURM Job Submission

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:00

The 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>/.

Reproducing the results

The shell scripts under shells/paper/ reproduce all experiments reported in the paper. See shells/paper/README.md for details.

Minimal CDB example

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,
)

Cite

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},
}

About

Depth-adaptive Inference of Looped Language Models via Continuous Depth Batching

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages