How open-agent-infra/rsinfer works
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: loop.py Request scheduler · batch/unit.py GPU worker · pytorch/unit.py PyTorch executor · runtime.py Unit runtime
Components 25
Serving Frontend
- HTTP API
engine/frontend/http/api.py - Tokenizer
engine/frontend/tokenizer/unit.py - Detokenizer
engine/frontend/detok/unit.py - Frontend transport
engine/frontend/transport.py
Scheduling Runtime
- Request scheduler
engine/core/sched/loop.py - Request tracking
engine/sched/reqs/unit.py - Scheduling policies
engine/policies - GPU worker
engine/worker/batch/unit.py - Worker communication
engine/worker/comm/unit.py
Model Execution
- PyTorch executor
engine/executors/pytorch/unit.py - Model units
engine/models - Model layers
engine/layers - Kernel backends
engine/kernels - Device platform
engine/platforms/base.py
Live Change Control
- Control client
engine/core/control/client.py - Dependency planner
engine/core/deps/planner.py - Change coordinator
engine/core/change/coordinator.py - Process supervisor
engine/core/supervisor/supervisor.py - Unit runtime
engine/unit/runtime/runtime.py
Persistent State
- State declarations
engine/core/contracts/state.py - Paged KV state
engine/state/kv_paged/unit.py - Host cache service
engine/state/host_cache/cache_service.py - Weights state
engine/core/state/weights/unit.py
Other components
- API client
- Operator or agent
Connections 27
- API client → HTTP API: sends requests
README.md - HTTP API → Tokenizer: tokenizes input
- HTTP API → Frontend transport: submits requests
engine/frontend/http/api.py - Frontend transport → Request scheduler: routes requests
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
engine/executors/pytorch/unit.py - PyTorch executor → Model units: executes model
- Model units → Model layers: composes layers
engine/models/ds1017/unit.py - Model layers → Kernel backends: invokes kernels
engine/layers/ds1017/unit.py - PyTorch executor → Device platform: selects device
engine/executors/pytorch/unit.py - Frontend transport → Detokenizer: streams tokens
- Detokenizer → HTTP API: returns text
- Operator or agent → Control client: requests changes
engine/core/control/client.py - Control client → Change coordinator: submits change
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
engine/core/contracts/state.py - State declarations → Paged KV state: guides allocation
- GPU worker → Host cache service: issues cache work
engine/state/host_cache/cache_service.py - PyTorch executor → Weights state: uses resident weights