Metadata-Version: 2.4
Name: duort
Version: 0.1.0
Summary: Fast serving engine for System 1 + System 2 robot policies
License-Expression: Apache-2.0
Project-URL: Repository, https://github.com/duort-project/duort
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=2.5
Requires-Dist: safetensors>=0.4
Requires-Dist: tokenizers>=0.19
Provides-Extra: serve
Requires-Dist: websockets>=13.0; extra == "serve"
Requires-Dist: msgpack>=1.0; extra == "serve"
Requires-Dist: numpy>=1.24; extra == "serve"
Provides-Extra: orbax
Requires-Dist: tensorstore>=0.1.60; extra == "orbax"
Requires-Dist: numpy>=1.24; extra == "orbax"
Provides-Extra: all
Requires-Dist: websockets>=13.0; extra == "all"
Requires-Dist: msgpack>=1.0; extra == "all"
Requires-Dist: numpy>=1.24; extra == "all"
Requires-Dist: tensorstore>=0.1.60; extra == "all"
Dynamic: license-file

<h1 align="center">DuoRT</h1>

<h3 align="center">
Fast serving engine for System 1 + System 2 robot policies
</h3>

<p align="center">
  <a href="./LICENSE"><img src="https://img.shields.io/badge/License-Apache_2.0-green.svg" alt="License"></a>
</p>

<p align="center">
| <a href="#getting-started"><b>Getting Started</b></a> | <a href="#supported-models"><b>Models</b></a> | <a href="./docs/architecture.md"><b>Architecture</b></a> | <a href="#benchmarks"><b>Benchmarks</b></a> | <a href="./examples"><b>Examples</b></a> |
</p>

---

**DuoRT** is a fast serving engine for dual-system robot policies, supporting mainstream VLAs (`pi05`, `GR00T`, `SmolVLA`) and custom System 1 + System 2 models.

On [`LIBERO-Dynamic`](https://github.com/renshaojie233/LIBERO-Dynamic) (`1x RTX 5090`), DuoRT **beats latency-retrained `VLASH` without retraining**:

| 1 Robot ([`pi05_libero`](https://github.com/Physical-Intelligence/openpi), Zero Retraining) | Retrained | Success Rate | Mean Latency |
| :--- | :---: | :---: | :---: |
| `LeRobot PyTorch` (Sync / Async) | No | 43.1% / 48.4% | 147 ms |
| `VLASH` | **Yes** | 55.4% | 104 ms |
| `OpenPI JAX Async` | No | 57.8% | 60 ms |
| **DuoRT** | **No** | **60.9%** | **39 ms** |

On the SOTA [`pi05/mixed_ft3000`](https://huggingface.co/rsj2003/libero-dynamic-paper-models/tree/main/pi05/mixed_ft3000) checkpoint, DuoRT matches native `OpenPI JAX` serving on a single robot (as both easily keep up with the benchmark's 20 Hz control rate)—yet once scaled to 8 concurrent robots on one RTX 5090, `OpenPI JAX` falls behind and collapses while DuoRT holds firm:

| [`pi05/mixed_ft3000`](https://huggingface.co/rsj2003/libero-dynamic-paper-models/tree/main/pi05/mixed_ft3000) serving method | Success Rate | Mean Latency |
| :--- | :---: | :---: |
| `OpenPI JAX Async` | 16.1% | 280 ms |
| **DuoRT** | **52.3% (3.25x)** | **27 ms** |

DuoRT is fast with:
- [Lock-free paged KV and latent cache](./docs/architecture.md#1-lock-free-paged-state-cache) across Slow and Fast streams
- Paged Split-K cross-attention and 3D relative-time RoPE
- C++ deadline batching and latest-frame sensor coalescing
- [Piecewise CUDA Graph slicing (`<= 2 ms`)](./docs/architecture.md#2-sub-2ms-micro-slicing--deadline-batching), `torch.compile`, and `FP8` quantization
- [Real-Time Chunking (RTC)](./docs/architecture.md#3-real-time-chunking-rtc--horizon-ring) with frozen-prefix splicing and overrun blending

DuoRT is easy to use with:
- Native Hugging Face and OpenPI JAX/Orbax checkpoint loading
- Drop-in OpenPI-compatible WebSocket server (`duort serve`) and GPU benchmark CLI (`duort bench`)
- Standard PyTorch `nn.Module` interfaces (`SlowBackbone` and `FastHead`) for custom policies
- [Colocated, disaggregated Slow/Fast, and pipeline-parallel](./docs/architecture.md#4-slowfast-disaggregation--edge-cloud-split-serving) multi-GPU and edge-cloud placement

For system design and architecture details, see [docs/architecture.md](./docs/architecture.md).

## Getting Started

Install on Linux (`Python >= 3.10`, `PyTorch >= 2.5`, `CUDA >= 12.0`, NVIDIA `SM80+`):

```bash
git clone https://github.com/duort-project/duort.git && cd duort
pip install -e ".[all]" --no-build-isolation   # or: docker build -t duort .
```

Launch an OpenPI-compatible multi-stream policy server or run a standalone GPU benchmark:

```bash
duort serve --model lerobot/smolvla_base --embodiment-tag so100 --streams 8 --port 8000
duort bench --model lerobot/smolvla_base --streams 1,4,8
```

Or embed `Engine` directly in a Python real-time control loop:

```python
import time
import torch
from duort import Engine

engine = Engine("lerobot/smolvla_base")
engine.set_prompt("pick up the cup")

cams = torch.randint(0, 256, engine.slow_obs_shape, dtype=torch.uint8)  # simulated RGB cameras
engine.push_slow(cams)
engine.wait_ready()

for step in range(500):               # 1 s real-time loop at 500 Hz (2 ms/step)
    if step % 250 == 0:               # 2 Hz camera frame -> System 2 (Slow)
        engine.push_slow(cams)
    if step % 25 == 0:                # 20 Hz chunk refresh -> System 1 (Fast)
        engine.push_fast()
    actions, *_ = engine.sample_actions(cpu=True)
    time.sleep(0.002)
print(actions.shape)                  # torch.Size([1, 6])
```

- Custom `SlowBackbone` + `FastHead` policy: [examples/custom_model.py](./examples/custom_model.py)
- Modular `(Slow × Fast)` pairing & `@engine.stage`: [examples/quickstart.py](./examples/quickstart.py)
- Multi-GPU disaggregation (`slow_devices=[0], fast_devices=[1, 2, 3]`) & edge-cloud serving: [examples/multi_gpu_serving.py](./examples/multi_gpu_serving.py)

## Supported Models

Measured on a single **`1x RTX 4090` (`24 GB`)** under `2 Hz` camera updates, `20 Hz` chunk requests (`FP8` Fast heads + micro-sliced `BF16` Slow VLM), and `500 Hz` continuous action polling against a multi-stream `BF16` PyTorch `SDPA` baseline:

| Model (`System 2` + `System 1`) | `1-Robot` Chunk `P50`<br>(DuoRT vs. PyTorch) | Zero-Underrun Robots / GPU<br>(`P99`: DuoRT vs. PyTorch) | Peak VRAM |
| :--- | :---: | :---: | :---: |
| **`lerobot/pi05_base`** (+ fine-tuned)<br>PaliGemma-2B + Gemma Expert (10-step Flow) | **22.5 ms** vs. 147.0 ms (**6.5x**) | **2** (**44.3 ms** vs. 181.6 ms) | **5.55 GB** |
| **`nvidia/GR00T-N1.7-3B`** (+ fine-tuned)<br>Qwen3-VL-2B + AlternateVL-DiT (32L, 4-step) | **12.8 ms** vs. 31.6 ms (**2.5x**) | **8** (**33.9 ms** vs. 75.8 ms) | **4.84 GB** |
| **`nvidia/GR00T-N1.5-3B`**<br>Eagle2-VLM + Cross-Attn DiT (16L, 4-step) | **8.8 ms** vs. 24.8 ms (**2.8x**) | **20** (**31.5 ms** vs. 100.9 ms) | **3.89 GB** |
| **`lerobot/smolvla_base`** (+ fine-tuned)<br>SmolVLM2 + SmolLM2 Expert (10-step Flow) | **8.7 ms** vs. 98.6 ms (**11.3x**) | **12** (**28.7 ms** vs. 177.9 ms) | **0.98 GB** |

To serve a custom System 1 + System 2 policy, subclass `SlowBackbone` and `FastHead` connected by a `TemporalChannel` (`mode="hidden"` or `mode="kv"`), register a Hugging Face loader via `@ModelRegistry.register`, or wire custom stages with `@engine.stage`—see [examples/custom_model.py](./examples/custom_model.py).

## Benchmarks

Beyond single-GPU workstation serving, DuoRT disaggregates Slow VLMs and Fast action heads (`1S : 1F`, `1S : 3F`) and pipelines large Slow backbones across GPUs—cutting 3B+ VLA cluster VRAM by **45–59%** while scaling fleet capacity with zero control underruns:

| Model | Multi-GPU Placement | Concurrent Robots | Tail Latency (`P99`: DuoRT vs. PyTorch) |
| :--- | :--- | :---: | :---: |
| **`pi05` (3.3B)** | `4x H100 SXM` (`Colocated`) | 4 | **26.8 ms** vs. 2.94 s (**109.7x lower**) |
| **`GR00T-N1.5` (3B)** | `4x H100 SXM` (`1S : 3F`) | 48 | **13.3 ms** vs. 447.9 ms (**33.6x lower**) |
| **`SmolVLA` (450M)** | `2x RTX PRO 6000` (`1S : 1F`) | 16 | **24.4 ms** vs. 294.5 ms (**12.1x lower**) |

Full [`LIBERO-Dynamic`](https://github.com/renshaojie233/LIBERO-Dynamic) and `LIBERO` results, `RTX 4090` / `RTX 5090` per-model tables, Slow/Fast disaggregation VRAM matrices, and reproduction commands → [benchmarks/README.md](./benchmarks/README.md).

## License

Apache-2.0 — see [LICENSE](./LICENSE).
