# open-agent-infra/rsinfer architecture

> Architecture diagram of the GitHub repository open-agent-infra/rsinfer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/open-agent-infra/rsinfer
- Repository: https://github.com/open-agent-infra/rsinfer

## Overview

RSInfer is an OpenAI-compatible LLM serving engine whose main runtime path accepts HTTP generation requests, tokenizes and schedules them, executes model work on GPU workers, then detokenizes and returns streamed results. A separate control path enables live, dependency-planned changes with coordinated reload and rollback while long-lived model and cache state remains resident. The README also describes model/kernel hot-plugging, distributed serving, and host caching. Source excerpts establish some interfaces and calls; several runtime relationships below are documented by the README or conservatively left unconnected where implementation was not sampled.

Main entry points: [`engine/core/sched/loop.py`](https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/sched/loop.py) (Request scheduler), [`engine/worker/batch/unit.py`](https://github.com/open-agent-infra/rsinfer/blob/master/engine/worker/batch/unit.py) (GPU worker), [`engine/executors/pytorch/unit.py`](https://github.com/open-agent-infra/rsinfer/blob/master/engine/executors/pytorch/unit.py) (PyTorch executor), [`engine/unit/runtime/runtime.py`](https://github.com/open-agent-infra/rsinfer/blob/master/engine/unit/runtime/runtime.py) (Unit runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_serving["Serving Frontend"]
  node_http["HTTP API<br/>[api.py]"]
  node_tokenizer["Tokenizer<br/>[unit.py]"]
  node_detokenizer["Detokenizer<br/>[unit.py]"]
  node_transport["Frontend transport<br/>[transport.py]"]
end

subgraph group_runtime["Scheduling Runtime"]
  node_scheduler["Request scheduler<br/>[loop.py]"]
  node_requeststate["Request tracking<br/>[unit.py]"]
  node_policies["Scheduling policies"]
  node_worker["GPU worker<br/>[unit.py]"]
  node_communication["Worker communication<br/>[unit.py]"]
end

subgraph group_models["Model Execution"]
  node_executor["PyTorch executor<br/>[unit.py]"]
  node_model["Model units"]
  node_layers["Model layers"]
  node_kernels["Kernel backends"]
  node_platform["Device platform<br/>[base.py]"]
end

subgraph group_change["Live Change Control"]
  node_controlclient["Control client<br/>[client.py]"]
  node_planner["Dependency planner<br/>[planner.py]"]
  node_changeprotocol["Change coordinator<br/>[coordinator.py]"]
  node_supervisor["Process supervisor<br/>[supervisor.py]"]
  node_unitruntime["Unit runtime<br/>[runtime.py]"]
end

subgraph group_state["Persistent State"]
  node_statecontracts["State declarations<br/>[state.py]"]
  node_kvstate[("Paged KV state<br/>[unit.py]")]
  node_hostcache[("Host cache service<br/>[cache_service.py]")]
  node_weights[("Weights state<br/>[unit.py]")]
end

node_client(("API client"))
node_controloperator(("Operator or agent"))

node_client -->|"sends requests"| node_http
node_http -.->|"tokenizes input"| node_tokenizer
node_http -->|"submits requests"| node_transport
node_transport -->|"routes requests"| node_scheduler
node_scheduler -->|"tracks requests"| node_requeststate
node_scheduler -.->|"selects policy"| node_policies
node_scheduler -.->|"dispatches steps"| node_worker
node_worker -.->|"uses channels"| node_communication
node_worker -->|"runs execution"| node_executor
node_executor -.->|"executes model"| node_model
node_model -->|"composes layers"| node_layers
node_layers -->|"invokes kernels"| node_kernels
node_executor -->|"selects device"| node_platform
node_transport -.->|"streams tokens"| node_detokenizer
node_detokenizer -.->|"returns text"| node_http
node_controloperator -->|"requests changes"| node_controlclient
node_controlclient -->|"submits change"| node_changeprotocol
node_changeprotocol -.->|"derives action plan"| node_planner
node_changeprotocol -.->|"coordinates participants"| node_supervisor
node_supervisor -.->|"reloads units"| node_unitruntime
node_unitruntime -.->|"hot reloads"| node_model
node_unitruntime -.->|"hot reloads"| node_policies
node_unitruntime -.->|"hot reloads"| node_kernels
node_model -->|"declares storage"| node_statecontracts
node_statecontracts -.->|"guides allocation"| node_kvstate
node_worker -->|"issues cache work"| node_hostcache
node_executor -.->|"uses resident weights"| node_weights

click node_http "https://github.com/open-agent-infra/rsinfer/blob/master/engine/frontend/http/api.py"
click node_tokenizer "https://github.com/open-agent-infra/rsinfer/blob/master/engine/frontend/tokenizer/unit.py"
click node_detokenizer "https://github.com/open-agent-infra/rsinfer/blob/master/engine/frontend/detok/unit.py"
click node_transport "https://github.com/open-agent-infra/rsinfer/blob/master/engine/frontend/transport.py"
click node_scheduler "https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/sched/loop.py"
click node_requeststate "https://github.com/open-agent-infra/rsinfer/blob/master/engine/sched/reqs/unit.py"
click node_policies "https://github.com/open-agent-infra/rsinfer/tree/master/engine/policies"
click node_worker "https://github.com/open-agent-infra/rsinfer/blob/master/engine/worker/batch/unit.py"
click node_communication "https://github.com/open-agent-infra/rsinfer/blob/master/engine/worker/comm/unit.py"
click node_executor "https://github.com/open-agent-infra/rsinfer/blob/master/engine/executors/pytorch/unit.py"
click node_model "https://github.com/open-agent-infra/rsinfer/tree/master/engine/models"
click node_layers "https://github.com/open-agent-infra/rsinfer/tree/master/engine/layers"
click node_kernels "https://github.com/open-agent-infra/rsinfer/tree/master/engine/kernels"
click node_platform "https://github.com/open-agent-infra/rsinfer/blob/master/engine/platforms/base.py"
click node_controlclient "https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/control/client.py"
click node_planner "https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/deps/planner.py"
click node_changeprotocol "https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/change/coordinator.py"
click node_supervisor "https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/supervisor/supervisor.py"
click node_unitruntime "https://github.com/open-agent-infra/rsinfer/blob/master/engine/unit/runtime/runtime.py"
click node_statecontracts "https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/contracts/state.py"
click node_kvstate "https://github.com/open-agent-infra/rsinfer/blob/master/engine/state/kv_paged/unit.py"
click node_hostcache "https://github.com/open-agent-infra/rsinfer/blob/master/engine/state/host_cache/cache_service.py"
click node_weights "https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/state/weights/unit.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_http,node_tokenizer,node_detokenizer,node_transport,node_client toneBlue
class node_scheduler,node_requeststate,node_policies,node_worker,node_communication toneAmber
class node_executor,node_model,node_layers,node_kernels,node_platform toneMint
class node_controlclient,node_planner,node_changeprotocol,node_supervisor,node_unitruntime toneRose
class node_statecontracts,node_kvstate,node_hostcache,node_weights,node_controloperator toneIndigo
```

## Components

### Serving Frontend

- [HTTP API](https://github.com/open-agent-infra/rsinfer/blob/master/engine/frontend/http/api.py): `engine/frontend/http/api.py`
- [Tokenizer](https://github.com/open-agent-infra/rsinfer/blob/master/engine/frontend/tokenizer/unit.py): `engine/frontend/tokenizer/unit.py`
- [Detokenizer](https://github.com/open-agent-infra/rsinfer/blob/master/engine/frontend/detok/unit.py): `engine/frontend/detok/unit.py`
- [Frontend transport](https://github.com/open-agent-infra/rsinfer/blob/master/engine/frontend/transport.py): `engine/frontend/transport.py`

### Scheduling Runtime

- [Request scheduler](https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/sched/loop.py): `engine/core/sched/loop.py`
- [Request tracking](https://github.com/open-agent-infra/rsinfer/blob/master/engine/sched/reqs/unit.py): `engine/sched/reqs/unit.py`
- [Scheduling policies](https://github.com/open-agent-infra/rsinfer/tree/master/engine/policies): `engine/policies`
- [GPU worker](https://github.com/open-agent-infra/rsinfer/blob/master/engine/worker/batch/unit.py): `engine/worker/batch/unit.py`
- [Worker communication](https://github.com/open-agent-infra/rsinfer/blob/master/engine/worker/comm/unit.py): `engine/worker/comm/unit.py`

### Model Execution

- [PyTorch executor](https://github.com/open-agent-infra/rsinfer/blob/master/engine/executors/pytorch/unit.py): `engine/executors/pytorch/unit.py`
- [Model units](https://github.com/open-agent-infra/rsinfer/tree/master/engine/models): `engine/models`
- [Model layers](https://github.com/open-agent-infra/rsinfer/tree/master/engine/layers): `engine/layers`
- [Kernel backends](https://github.com/open-agent-infra/rsinfer/tree/master/engine/kernels): `engine/kernels`
- [Device platform](https://github.com/open-agent-infra/rsinfer/blob/master/engine/platforms/base.py): `engine/platforms/base.py`

### Live Change Control

- [Control client](https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/control/client.py): `engine/core/control/client.py`
- [Dependency planner](https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/deps/planner.py): `engine/core/deps/planner.py`
- [Change coordinator](https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/change/coordinator.py): `engine/core/change/coordinator.py`
- [Process supervisor](https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/supervisor/supervisor.py): `engine/core/supervisor/supervisor.py`
- [Unit runtime](https://github.com/open-agent-infra/rsinfer/blob/master/engine/unit/runtime/runtime.py): `engine/unit/runtime/runtime.py`

### Persistent State

- [State declarations](https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/contracts/state.py): `engine/core/contracts/state.py`
- [Paged KV state](https://github.com/open-agent-infra/rsinfer/blob/master/engine/state/kv_paged/unit.py): `engine/state/kv_paged/unit.py`
- [Host cache service](https://github.com/open-agent-infra/rsinfer/blob/master/engine/state/host_cache/cache_service.py): `engine/state/host_cache/cache_service.py`
- [Weights state](https://github.com/open-agent-infra/rsinfer/blob/master/engine/core/state/weights/unit.py): `engine/core/state/weights/unit.py`

### Other components

- **API client**
- **Operator or agent**

## Connections

- API client → HTTP API: sends requests (evidence: `README.md`)
- HTTP API → Tokenizer: tokenizes input
- HTTP API → Frontend transport: submits requests (evidence: `engine/frontend/http/api.py`)
- Frontend transport → Request scheduler: routes requests (evidence: `engine/frontend/transport.py`)
- Request scheduler → Request tracking: tracks requests
- Request scheduler → Scheduling policies: selects policy
- Request scheduler → GPU worker: dispatches steps
- GPU worker → Worker communication: uses channels
- GPU worker → PyTorch executor: runs execution (evidence: `engine/executors/pytorch/unit.py`)
- PyTorch executor → Model units: executes model
- Model units → Model layers: composes layers (evidence: `engine/models/ds1017/unit.py`)
- Model layers → Kernel backends: invokes kernels (evidence: `engine/layers/ds1017/unit.py`)
- PyTorch executor → Device platform: selects device (evidence: `engine/executors/pytorch/unit.py`)
- Frontend transport → Detokenizer: streams tokens
- Detokenizer → HTTP API: returns text
- Operator or agent → Control client: requests changes (evidence: `engine/core/control/client.py`)
- Control client → Change coordinator: submits change (evidence: `engine/core/control/client.py`)
- Change coordinator → Dependency planner: derives action plan
- Change coordinator → Process supervisor: coordinates participants
- Process supervisor → Unit runtime: reloads units
- Unit runtime → Model units: hot reloads
- Unit runtime → Scheduling policies: hot reloads
- Unit runtime → Kernel backends: hot reloads
- Model units → State declarations: declares storage (evidence: `engine/core/contracts/state.py`)
- State declarations → Paged KV state: guides allocation
- GPU worker → Host cache service: issues cache work (evidence: `engine/state/host_cache/cache_service.py`)
- PyTorch executor → Weights state: uses resident weights
