Skip to content

feat: add an engine component config and script - #4905

Closed
mikasenghaas wants to merge 7 commits into
feat/public-internal-configsfrom
feat/engine-component
Closed

mikasenghaas wants to merge 7 commits into
feat/public-internal-configsfrom
feat/engine-component

Conversation

@mikasenghaas

@mikasenghaas mikasenghaas commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Why. uv run inference plays two roles. Users run it as the public entrypoint: a router plus an engine locally, or a multi-node or P/D job with [slurm]. The SLURM launchers also run it as the bare engine on each rank, with router = None. So one config mixes public topology (router, deployment, slurm, dry_run) with the fields that one engine process reads. External launchers have no engine component to target.

Idea. Split InferenceConfig along the process boundary, as #4899 did for the other components. The engine blocks already live in configs/components/engine.py (#4899), and the new class joins them:

# configs/components/engine.py
class EngineConfig(ComponentConfig):
    server, vllm, log, env_vars, weight_broadcast, kv_cache_offload, hisparse, pd_* ...   # + to_namespace()

# configs/entrypoints/inference.py
class InferenceConfig(EngineConfig, EntrypointConfig):
    router, backend_port, deployment, slurm, output_dir, dry_run   # + topology validators, for_pd_role()

A new engine script (prime_rl.components.engine:main) serves one EngineConfig without a router. _launch_rank.sh.j2 (multi-node and P/D ranks of inference, rl and sft) now runs uv run engine @ "$CONFIG_PATH" instead of uv run inference.

  • The SLURM writers keep only the engine fields (keep_engine_fields) in the files the ranks read: inference.json of multi-node inference, rl and sft, and inference-{prefill,decode}.json. Before, these files held the whole inference config with router = None. EngineConfig is strict like every other config, so a mistyped key or flag fails.
  • InferenceConfig keeps all its fields, keys and defaults. Its JSON schema changes only by a new class description. The local inference and rl launches still run uv run inference.
  • apply_multi_node_dp_env (the PRL_DP_* pod env from main) moves to prime_rl.components.engine and runs in setup_engine_process. So engine and inference both resolve the multi-node DP rank and head address.
  • setup_dummy_load and MODEL_NAME_DRAFT_METHODS move to components/engine.py. The P/D role overrides reach them through the new vllm_overrides property.
  • dump_rl_components and dump_pd_components are unchanged, so the k8s operator's input is unchanged. To run engine, the operator must apply keep_engine_fields to their output.

Breaking

  • Import setup_dummy_load and MODEL_NAME_DRAFT_METHODS from prime_rl.configs.components.engine, not from prime_rl.configs.entrypoints.inference.
  • Import apply_multi_node_dp_env from prime_rl.components.engine, not from prime_rl.entrypoints.inference.

Verification

On 0f24151 (now bdc56e3, after rebases that add #4899's CI filter and algorithm path commits and main up to 42e1e43), on macOS without torch. The schema check and the mutation table ran on 3382ffd, before the rebase onto main.

  • Engine ≡ routerless inference on per-rank configs. test_engine_serves_per_rank_configs_like_a_routerless_inference builds a multi-node and a bidirectional P/D InferenceConfig with native KV offload. It writes the per-rank and role JSON with the SLURM writers (write_config(engine_only=True), write_pd_configs). It parses each file with the per-rank flags under EngineConfig, and under InferenceConfig with --router None, which is what the ranks ran before. It asserts the same engine fields and the same vLLM namespace, including kv_transfer_config.
  • Schemas. model_json_schema() of the 9 script configs is identical to the base branch, except the new InferenceConfig description.
  • Unit suite. 779 passed, 50 failed, 111 collection errors in 10 s. Every failure and error is a module my env lacks (torch, vllm, wandb_gql, env tasksets).
  • CLI. engine --server-prot 1 fails with 1 validation error for EngineConfig.
Change removed Result
keep_engine_fields in write_config test_engine_serves_per_rank_configs_like_a_routerless_inference: router: Extra inputs are not permitted
keep_engine_fields in write_pd_configs same test, same error
engine in [project.scripts] test_config_layout: KeyError: 'engine'
engine parses cli(EngineConfig) test_config_layout: `engine` does not parse EngineConfig

Not covered locally: the keep_engine_fields calls in the multi-node rl writer (write_subconfigs) and the sft writer (write_eval_subconfigs). Building those configs needs tasksets that my env lacks. No GPU run.

Merge order

Merge after #4899. This PR is stacked on #4899 (feat/public-internal-configs). Rebase it onto main after each squash merge. Stack, in merge order: #4899 → #4905 → #4909 → #4919.

🤖 Generated with Claude Code


Note

Medium Risk
Touches multi-node/P/D launch paths and per-rank config JSON; mis-filtered fields would break SLURM ranks, but unit tests assert engine parity with routerless inference.

Overview
Splits inference config along the router vs. per-rank engine process boundary: new EngineConfig in prime-rl-configs holds everything one vLLM worker needs (to_namespace, KV transfer, dummy-load, validators), and InferenceConfig subclasses it with launcher-only fields (router, deployment, slurm, …).

Adds uv run engine (prime_rl.components.engine) for a routerless vLLM process, with setup_engine_process (env, multi-node PRL_DP_*, file limits) shared by local uv run inference. SLURM _launch_rank.sh.j2 and writers now invoke engine and persist keep_engine_fields JSON so ranks only see strict EngineConfig keys—not full inference with router: null.

Breaking: import setup_dummy_load from prime_rl.configs.components.engine and apply_multi_node_dp_env from prime_rl.components.engine.

Reviewed by Cursor Bugbot for commit 83dcf5b. Bugbot is set up for automated code reviews on this repo. Configure here.

@mikasenghaas
mikasenghaas force-pushed the feat/engine-component branch from 5bc53dd to 6bb236b Compare December 2, 2026 19:36
@mikasenghaas
mikasenghaas changed the base branch from feat/move-config-blocks to fix/shared-file-monitor December 2, 2026 19:36
@mikasenghaas
mikasenghaas added this pull request to stack #4902 December 2, 2026 19:41
@mikasenghaas
mikasenghaas force-pushed the fix/shared-file-monitor branch from 553c6a5 to 574a254 Compare December 2, 2026 22:05
@mikasenghaas
mikasenghaas force-pushed the feat/engine-component branch 2 times, most recently from 594b0fd to 0f24151 Compare December 2, 2026 22:33
@mikasenghaas
mikasenghaas force-pushed the fix/shared-file-monitor branch from 574a254 to c12e608 Compare December 2, 2026 22:37
@mikasenghaas
mikasenghaas removed this pull request from stack #4902 December 2, 2026 22:44
@mikasenghaas
mikasenghaas changed the base branch from fix/shared-file-monitor to feat/public-internal-configs December 2, 2026 22:44
@mikasenghaas
mikasenghaas added this pull request to stack #4918 December 2, 2026 22:44
@mikasenghaas
mikasenghaas force-pushed the feat/engine-component branch from 0f24151 to 83dcf5b Compare December 2, 2026 22:48
@mikasenghaas

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 83dcf5b. Configure here.

mikasenghaas and others added 4 commits December 2, 2026 16:42
Entrypoint configs (rl, sft, pretrain, eval, inference) are what users
write. Component configs (trainer, orchestrator, router, env worker
pool, online eval) are what one process reads: an entrypoint resolves
them, or an external launcher such as the Kubernetes operator writes
them. Keeping both in one flat configs/ package hid that boundary.

Move the config modules into configs/entrypoints and
configs/components, and the component process mains into
prime_rl.components. Top-level configs/ modules stay as the blocks
both use. EntrypointConfig and ComponentConfig mark each class, and
test_config_layout checks the scripts, markers and import direction.

Rename RouterEntrypointConfig to RouterConfig and the router backend
union to RouterBackendConfig. Fields are unchanged: the JSON schemas
of the moved configs match main. Old import paths such as
prime_rl.configs.rl now fail with ImportError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
configs/inference.py splits into components/engine.py and
components/router.py, which now holds the router backend blocks.
configs/algorithm.py moves to components/algorithm.py, and
configs/diff.py moves to utils/diff.py.

The old import paths fail loudly; there are no shims.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The algorithm block is no component config: the orchestrator, the env
workers, the sample server and the transports all use it. Keep it at
prime_rl.configs.algorithm, its path on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mikasenghaas
mikasenghaas force-pushed the feat/engine-component branch from 93732c8 to 8705e0d Compare December 3, 2026 00:47
@mikasenghaas
mikasenghaas force-pushed the feat/public-internal-configs branch from 92cc32f to 48de560 Compare December 3, 2026 00:47
mikasenghaas and others added 3 commits December 2, 2026 17:13
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
uv run inference was both the public entrypoint (a router plus an
engine, or a SLURM job) and the bare engine that each SLURM rank runs.
EngineConfig now holds the fields that one engine process reads, and
InferenceConfig extends it with the router, deployment and SLURM
fields. The new `engine` script serves one EngineConfig without a
router, and the per-rank SLURM launches use it.

EngineConfig ignores unknown keys, so it reads any inference config,
including the existing per-rank and P/D role JSON. InferenceConfig
still rejects unknown keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SLURM writers now keep only the engine fields in the per-rank and
P/D role files that `engine` reads. EngineConfig then rejects unknown
keys and CLI flags like every other config. dump_rl_components and
dump_pd_components are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mikasenghaas
mikasenghaas force-pushed the feat/engine-component branch from 8705e0d to bdc56e3 Compare December 3, 2026 01:13
@mikasenghaas

Copy link
Copy Markdown
Member Author

Folded into #4899. The config stack is now four PRs, one per motivation: #4899 (public vs internal configs) → #4909 (a complete config per process) → #4919 (package layout) → #4928 (resolve each value in one place).

mikasenghaas added a commit that referenced this pull request Dec 3, 2026
…#4899)

## Summary

**Why.** rl and sft compose several processes, and they nested each
process's whole config. Users could set keys that the launcher always
fills or that no process reads, e.g. `trainer.output_dir` next to the
top-level `output_dir`, or `inference.slurm` next to `[slurm]`. Some of
these values were silently overwritten. A single-node
`orchestrator.env_worker_pool_replicas` hung the run. `uv run inference`
had the same mix: it was both the public entrypoint and the bare engine
that each SLURM rank ran.

**Idea.** Separate what users write from what a process reads, in the
package and in the classes:

```
configs/entrypoints/  RLConfig, SFTConfig, PretrainConfig, EvalConfig, InferenceConfig   (EntrypointConfig)
configs/components/   TrainerConfig, OrchestratorConfig, EngineConfig, RouterConfig, ...   (ComponentConfig)

section (user writes)    component config (process reads)     filled by the entrypoint
TrainerSection           TrainerConfig                         + output_dir, weight_broadcast
OrchestratorSection      OrchestratorConfig                    + output_dir, weight_broadcast, env_worker_pool_replicas
EngineSection            EngineConfig                          + weight_broadcast
```

An entrypoint nests only sections. A component config extends its
section with the launcher-filled fields, so the two cannot drift. A
builder per process (`RLConfig.trainer_config()`,
`orchestrator_config()`, ...) validates the component config from the
section plus the entrypoint's values. Example:
`TrainerConfig.output_dir` comes from `RLConfig.output_dir / run.name`.

- `EngineConfig` is what one engine process reads. A new `engine` script
serves it without a router, and the SLURM ranks run `uv run engine` with
engine-only JSON. `InferenceConfig` stays the public entrypoint.
- Keys that no process reads go: the sft `[eval]` run fields,
`log.interval` and `log.log_data` where no loop reads them, and the rl
shared `[monitors.wandb] offline`. `inference.backend_port` follows
`server.port + 100` unless set.
- `test_config_layout` checks that each script parses the config of its
role, and that components never import entrypoints. The package README
states the config rules.
- Next in the stack: every process gets its own complete JSON (#4909),
the package layout (#4919), and resolving each value in one place
(#4928).

## Breaking

Remove these keys. Each now fails as an unknown key:
- rl: `trainer.output_dir`, `trainer.weight_broadcast`,
`orchestrator.output_dir`, `orchestrator.weight_broadcast` (set
`output_dir`, `run.name` and `[weight_broadcast]`),
`orchestrator.env_worker_pool_replicas`, `inference.weight_broadcast`,
`inference.slurm` (set `[slurm]`), `inference.output_dir`,
`inference.dry_run`, `inference.use_pd_kv_transfer`,
`inference.pd_decode_blocks_ttl_s`, `inference.pd_spill_to_store`,
`[monitors.wandb] offline` (set it on `trainer` and `orchestrator`).
- sft: `inference.weight_broadcast`, `inference.deployment`,
`inference.slurm`, `inference.output_dir`, `inference.dry_run`, the
three `inference.pd_*` keys, and `[eval]` `model`, `weight_broadcast`,
`broadcasts_dir`, `max_steps`, `resume_step`, `output_dir`, `log`,
`monitors`.
- All entrypoints: `log.interval` outside the orchestrator, eval and
online-eval logs; `log.log_data` outside the sft trainer log.

These values now fail with an error that names the fix: an explicit
single-node `inference.vllm.data_parallel_size` that does not fill
`deployment.num_infer_gpus`, and `inference.vllm.max_lora_rank` below
the LoRA rank.

Import paths change, with no aliases:

| Old | New |
|---|---|
| `prime_rl.configs.{rl,sft,pretrain,supervised,eval}` |
`prime_rl.configs.entrypoints.{...}` |
| `prime_rl.configs.{trainer,orchestrator,env_worker_pool,router}` |
`prime_rl.configs.components.{...}` |
| `prime_rl.configs.inference.InferenceConfig` |
`prime_rl.configs.entrypoints.inference` |
| `prime_rl.configs.inference.*` (engine blocks), `setup_dummy_load` |
`prime_rl.configs.components.engine` |
| `prime_rl.configs.diff` | `prime_rl.utils.diff` |
| `prime_rl.entrypoints.{trainer,orchestrator,env_worker_pool,router}` |
`prime_rl.components.{...}` |
| `apply_multi_node_dp_env` (`prime_rl.entrypoints.inference`) |
`prime_rl.components.engine` |
| `RouterEntrypointConfig` / `RouterConfig` (backend union) |
`RouterConfig` / `RouterBackendConfig` |

Python API: `RLConfig.trainer`, `.orchestrator` and `.inference` are
sections. Call the builder for a filled field, e.g.
`config.trainer_config().output_dir`.

Outside prime-rl, the `prime` CLI's schema worker and the k8s operator's
engine render (`run_engine.py`) import the old paths.
PrimeIntellect-ai/prime#1284 reads both. #4909 lists every launcher
break of the stack.
- **Custom SLURM templates.** The multi-node and P/D ranks now run `uv
run engine @ "$CONFIG_PATH"` on engine-only JSON, which has no `router`
key. A custom `slurm.template_path` copied from `main` that still runs
`uv run inference @ "$CONFIG_PATH"` on each rank fails without an error:
`InferenceConfig` then defaults to a vllm-router, so every rank starts
its own router on `server.port` and moves its engine to `backend_port`.
Migration: run `uv run engine` on the ranks, as `_launch_rank.sh.j2`
does.

## Verification

On 2569ff7, on macOS without torch or vllm:

- **Launcher output.** I dry-ran the `rl`, `sft` and `inference`
launchers for 103 cases: every checked-in config that loads, plus
synthetic P/D, Mooncake, multi-node, single-node SLURM and sft
online-eval cases. Against `main` (47f3ec3), every value a process
reads is unchanged. The JSONs only lose the removed keys above
(`log.interval`/`log.log_data`, `router`/`backend_port` in the per-rank
files, the launcher-filled section fields in `rl.json` and `sft.json`).
The sbatch scripts start the ranks with `uv run engine` in place of `uv
run inference`.
- **Engine ≡ routerless inference.**
`test_engine_serves_per_rank_configs_like_a_routerless_inference` parses
the multi-node and P/D per-rank JSON under `EngineConfig` and under
`InferenceConfig --router None`, which the ranks ran before. Both give
the same vLLM namespace, including `kv_transfer_config`.
- **Tests.** The config, launch, router, resume, client, dynamo and
algorithm tests: 879 passed.

| Change removed | Result |
| --- | --- |
| `output_dir` back on `TrainerSection` |
`test_entrypoints_reject_component_fields_their_launcher_fills`: `DID
NOT RAISE` |
| `env_worker_pool_replicas` back on `OrchestratorSection` | `DID NOT
RAISE` (2 cases) |
| `offline` back on the rl shared `[monitors.wandb]` | `DID NOT RAISE` |
| engine-only fields in the per-rank JSON |
`test_engine_serves_per_rank_configs_…`: `router: Extra inputs are not
permitted` |
| a component imports an entrypoint | `test_config_layout`:
`components/router.py imports prime_rl.configs.entrypoints.rl` |

These rows ran before the restack, on earlier commits of this branch and
of the closed #4905. This PR keeps the code under test unchanged. No GPU
run.

## Merge order

Base of the stack: this PR → #4909 → #4919 → #4928. Rebase each onto
`main` after a squash merge.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **High Risk**
> This is a breaking public import and CLI layout change across the
whole repo; external tools (e.g. Prime CLI, k8s operator) must adopt the
new paths before merge/deploy.
> 
> **Overview**
> Reorganizes **`prime_rl.configs`** by role: **`entrypoints/`** for
user-written configs (`RLConfig`, `SFTConfig`, `EvalConfig`,
`InferenceConfig`, …) and **`components/`** for per-process configs
(`TrainerConfig`, `OrchestratorConfig`, `RouterConfig`,
`EnvWorkerPoolConfig`, online eval). Adds **`EntrypointConfig`** and
**`ComponentConfig`** base markers; component configs now inherit
**`ComponentConfig`**.
> 
> Splits the former flat layout: **`EvalConfig`** moves to
**`entrypoints/eval`**; inference is split into
**`entrypoints/inference`** (public **`InferenceConfig`**) plus
**`components/engine`** (vLLM, deployment, KV offload) and
**`components/router`** (router backends). **`Live` / diff utilities**
move from **`prime_rl.configs.diff`** to **`prime_rl.utils.diff`**.
**`RouterEntrypointConfig`** becomes **`RouterConfig`**; the old router
backend union is **`RouterBackendConfig`**.
> 
> **`uv run`** script entrypoints for **`trainer`**, **`orchestrator`**,
**`router`**, and **`env-worker-pool`** now target
**`prime_rl.components.*`** instead of **`prime_rl.entrypoints.*`**. CI
slim-import checks, docs, and skills are updated to the new import
paths. **All old `prime_rl.configs.{rl,trainer,inference,...}` import
paths are removed** (no aliases).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
ab4c7ee. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant