Skip to content

feat: type the vLLM args that prime-rl reads - #4925

Closed
mikasenghaas wants to merge 1 commit into
feat/engine-layoutfrom
feat/typed-vllm-fields
Closed

mikasenghaas wants to merge 1 commit into
feat/engine-layoutfrom
feat/typed-vllm-fields

Conversation

@mikasenghaas

@mikasenghaas mikasenghaas commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Summary

Why. [inference.vllm] forwards any key to vLLM. prime-rl also reads nine of these pass-through keys itself, with getattr(vllm, key, default) or model_extra.get(key). So a wrong type reached the validators unchecked, and every reader had its own fallback. Example: setup_dummy_load found the user's load_format with "load_format" not in model_extra, and the P/D draft check searched raw override dicts for speculative_config.

Idea. Make each key that prime-rl reads a typed VllmConfig field:

Field Type, default Read by
tokenizer str | None = None auto parser resolution
load_format str | None = None setup_dummy_load
speculative_config dict | None = None draft swaps, dummy-load draft check, sampler-logprobs check
quantization_config dict | None = None NVFP4 expert check
moe_backend str | None = None NVFP4 expert check, $PRL_DEFAULT_MOE_BACKEND
pipeline_parallel_size int ≥ 1 = 1 engine placement
headless bool = False API server count
data_parallel_start_rank, data_parallel_address int/str | None = None multi-node DP env
  • to_namespace leaves a None field out (_OMIT_IF_NONE), so vLLM applies its own default, as it did for an unset extra.
  • EngineSection.vllm_overrides is replaced by speculative_configs, the draft of each engine (base engine and P/D role overrides). Only the dummy-load check read it.
  • Every other key still passes through untyped.

Breaking

  • The nine keys are validated. A value of the wrong type (e.g. pipeline_parallel_size = 0, a non-table speculative_config) now fails at resolve time. Before, it reached vLLM. No checked-in config changes.
  • Engine JSON holds the nine keys. Each engine and rl.json writes them with their defaults. prime-rl parses both forms.

Verification

On 815e9b0, on macOS without torch or vllm:

  • Launcher output. I dry-ran the 103 launcher cases against feat: size each engine with one layout function #4924 (e073486). The only difference is the new keys at their defaults (null, false, 1). No value changes.
  • vLLM namespace. I built to_namespace() for all 76 engine JSONs in both snapshots. The only difference is headless=False and pipeline_parallel_size=1, which are vLLM's defaults. vllm serve parses the namespace with parse_args(namespace=…), which keeps the set values.
  • CLI. uv run inference --vllm.speculative-config '{"method": "eagle3", …}' --vllm.quantization-config '{…}' --vllm.load-format dummy --vllm.pipeline-parallel-size 2 --vllm.headless resolves to the typed fields with api_server_count = 0 and no extras.
  • Tests. The config, launch, router, resume, client, dynamo, algorithm and model-source tests: 804 passed. New: test_the_vllm_args_prime_rl_reads_are_typed (kebab-case input, namespace values, None omitted, bounds) and test_a_pd_role_draft_without_its_own_weights_fails_under_a_dummy_target.
Change removed Result
speculative_config field (back to an extra) 130 tests fail: 'VllmConfig' object has no attribute 'speculative_config'
headless field (back to an extra) 205 tests fail: 'VllmConfig' object has no attribute 'headless'
load_format in _OMIT_IF_NONE test_the_vllm_args_prime_rl_reads_are_typed fails: None reaches the namespace
P/D role drafts in speculative_configs test_a_pd_role_draft_without_its_own_weights_fails_under_a_dummy_target fails: did not raise
pipeline_parallel_size bound test_the_vllm_args_prime_rl_reads_are_typed fails: did not raise

Merge order

Stacked on #4924 (#4899 → #4905 → #4909 → #4919 → #4921 → #4922 → #4923 → #4924 → this PR).

🤖 Generated with Claude Code


Note

Medium Risk
Config validation and namespace behavior change for nine inference fields; wrong types now fail earlier, but vLLM-facing defaults when unset should stay equivalent.

Overview
Adds nine typed fields on VllmConfig for vLLM keys that prime-rl reads itself (tokenizer, load_format, speculative_config, quantization_config, moe_backend, pipeline_parallel_size, headless, data_parallel_start_rank, data_parallel_address), so Pydantic validates them instead of leaving them in model_extra with ad hoc getattr/model_extra lookups.

EngineSection.vllm_overrides is replaced by speculative_configs, which collects draft configs from the base engine and from P/D prefill_vllm_overrides / decode_vllm_overrides for dummy-load checks. to_namespace omits those fields when None via an expanded _OMIT_IF_NONE. Call sites (setup_dummy_load, RL/inference validators, multi-node DP setup, GPU placement) now use the typed attributes.

Breaking: wrong types for these keys fail at config resolve time; resolved engine JSON includes the new fields at defaults.

Tests cover kebab-case CLI input, namespace round-trip, and P/D MTP drafts under dummy targets.

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

prime-rl read nine vLLM pass-through args with getattr or model_extra,
so a typo or a wrong type reached vLLM unchecked and every reader
needed a fallback. They are now typed VllmConfig fields. A None value
is still left out of the vLLM namespace, so vLLM keeps its default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mikasenghaas

Copy link
Copy Markdown
Member Author

Folded into #4928. 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
## Summary

**Why.** After #4909, every process reads a complete component config.
But the values in those configs were still resolved in many places:

- `rl` copied run-level fields (`max_steps`, `resume`, `ckpt`,
`monitors`, `rollout_transport`) into `[trainer]` and `[orchestrator]`,
and then checked that the copies were equal.
- Defaults applied only when a field was absent from `model_fields_set`.
A resolved config counts every field as set, so parsing `rl.json` or
`sft.json` again could build different components.
- Builders set values on configs that were already validated, and those
values skipped the validators.
- Six code paths sized the engines' data parallelism and API servers,
each with its own rules.
- prime-rl read nine untyped vLLM pass-through keys with `getattr`.
- P/D role settings reached a rank twice: from the engine JSON, and from
the sbatch (`ROLE_EXTRA`, role env exports).
- The `rl` and `sft` validators wrote derived values into the user's
sections, so results depended on validator order.

**Idea.** Resolve each value in one place, from values only, and
validate it once:

```
user TOML ──► RLConfig (sections as written; validators only check)
                 │
                 ├─ resolved_inference()   LoRA, router replay, NVFP4, dummy load,
                 │                         sampling masks, engine_layout()
                 ├─ orchestrator_config()  draft swaps, score-centering logprobs,
                 │                         client URLs, metrics roles
                 ▼
            components()  ──► built and validated once ──► cross-process checks
                                                         (NVFP4, speculative logprobs)
```

- **Run-level fields** exist once, at the top level of `rl`. The
builders pass them in, as they pass `output_dir`. A setting in such a
block that only one process reads stays in that process's section:
`[trainer.ckpt]` (`async_save`, `remote`, `skip_dataloader`,
`skip_optimizer`), `[orchestrator.ckpt]` (`rollouts`,
`rollouts_save_timeout`), `[orchestrator.monitors.file]`
(`trace_sample`, `live`). The builders merge the two parts.
- **Explicit "derive it" values.** `None`, or `"auto"` where `None`
already has a meaning, replace the `model_fields_set` checks (14 → 0). A
client keeps its default `base_url` until a launcher fills it, and the
builders find that default by its value.
- **Validate once.** The builders merge every value first and validate
once. `copy_validated` replaces `model_copy(update=…)`.
- **One layout function.** `engine_layout()` / `fit_engines()` in
`components/engine/layout.py`. `data_parallel_size` and
`api_server_count` default to `"auto"`.
- **Typed vLLM fields.** `tokenizer`, `load_format`,
`speculative_config`, `quantization_config`, `moe_backend`,
`pipeline_parallel_size`, `headless` and
`data_parallel_{start_rank,address}`. A `None` is not passed to vLLM.
- **P/D role settings** come only from `engine-<role>.json`. The sbatch
passes only host-dependent values (`data_parallel_address`,
`data_parallel_rank`).
- **Builders derive, validators check.** `rl.json` and `sft.json` keep
what the user wrote. Checks that span processes run on the built
configs. So a speculative draft in `decode_vllm_overrides` is checked
like one on `[inference.vllm]`.
- Out of scope: the top-level run fields (`run.name`,
`weight_broadcast`, `deployment.num_infer_nodes`, `slurm.template_path`)
are still filled by validators.

## Breaking

- **Run-level fields of `rl`.** Each field now has one place:
- `[trainer]` and `[orchestrator]` no longer take `max_steps`, `resume`
or `rollout_transport`. Set them at the top level.
- `[ckpt]` takes only what both processes share: `interval`,
`keep_last`, `keep_interval`, `output_dir`. Move `interval` and the
others out of `[trainer.ckpt]` and `[orchestrator.ckpt]` into `[ckpt]`.
Move `rollouts` and `rollouts_save_timeout` from `[ckpt]` to
`[orchestrator.ckpt]`, and `async_save` and `remote` from `[ckpt]` to
`[trainer.ckpt]` (e.g. `--ckpt.rollouts` →
`--orchestrator.ckpt.rollouts`). A `[trainer.ckpt]` or
`[orchestrator.ckpt]` without `[ckpt]` raises.
- `[monitors]` turns the monitors on for both processes.
`[orchestrator.monitors]` takes only `file.trace_sample` and
`file.live`, which leave the top-level `[monitors.file]`.
- `SharedWandbConfig`, `SharedMonitorsConfig` and
`SharedCheckpointConfig` are removed. `rl` rejects
`monitors.wandb.offline = true`.
- research-prod at 906b2e8d: `int4/rl/prod/rl.toml` must move `rollouts`
and `rollouts_save_timeout` from `[ckpt]` to `[orchestrator.ckpt]`. Its
other 112 configs that parse on `main` parse unchanged.
- **`None` means "derive it".** To get the old result, set an explicit
value: `kv_load_failure_policy = "fail"` under bidirectional P/D,
explicit `inference_metrics_roles`, explicit `admin_base_url`.
- **Engine layout.** An explicit `data_parallel_size` or
`data_parallel_size_local` that does not fill the GPUs now raises on
multi-node and P/D (before, it was kept). An explicit `api_server_count`
stays, but under `nccl` or `modelexpress` weight broadcast it must not
be below the engine's local data parallel ranks. A lower count now
raises: vLLM then starts too few workers, and the weight transfer waits
forever. `VllmConfig().data_parallel_size` and `.api_server_count` are
`"auto"` until a layout resolves them.
- **`max_lora_rank`.** An explicit `inference.vllm.max_lora_rank` larger
than the trainer's LoRA rank now stays. Before, `rl` and `sft` replaced
it with the trainer's rank, so vLLM now allocates the larger LoRA
buffers. Remove the key to serve exactly the trainer's rank. A smaller
value now raises.
- **Typed vLLM keys.** A wrong type in one of the nine keys fails at
resolve time instead of in vLLM.
- **Derived values leave the sections.**
`config.inference.vllm.enable_lora`, `.data_parallel_size`,
`config.orchestrator.speculative_decoding`, the score-centering
`sampling.logprobs` and the client URLs keep the user's values. Read the
derived values from `engine_configs()`, `orchestrator_config()`,
`online_eval_config()` or `resolved_inference()`. `rl.json` and
`sft.json` now hold the user's values (e.g. `api_server_count =
"auto"`); the component JSONs are unchanged.
- **sbatch templates.** `inference.sbatch.j2` and
`multi_node_rl.sbatch.j2` lose the template vars `prefill_env_vars`,
`decode_env_vars`, `prefill_vllm_extra_json`, `decode_vllm_extra_json`
and `prefill_deepep_high_throughput`. A custom template that uses them
or `ROLE_EXTRA` breaks. A P/D role's `env_vars` now reach the engine
only when it starts, not as a shell export before `uv run`. So they win
over the per-rank `UCX_NET_DEVICES` pinning, and a variable that must
exist before Python starts (e.g. `LD_PRELOAD`) no longer takes effect.
- **Hosted runs: the `inference` component of
PrimeIntellect-ai/prime#1284.** Its `legacy_inference` dumps the
`[inference]` section, which now keeps the user's values. I ran the
worker against #4919 and this PR. On this PR the hosted engine loses the
derived `data_parallel_size` and `api_server_count` (they become
`"auto"`, so the engine runs DP = 1 while `trainer.json` waits for N
transfer workers), `enable_lora` and `max_lora_rank`,
`enable_return_routed_experts`, `enable_return_sampling_mask` and
`load_format = "dummy"`. The SFT online-eval split also loses the
derived `client.admin_base_url`. Fix in the worker: dump
`config.resolved_inference()` when the schema has it, and take the eval
JSON from `dump_components(config)["online-eval"]`.
- `InferenceSection.engine_config` takes `require_admin_token` before
`role`. Pass `role=` by keyword.
- **Builder errors.** A builder (`trainer_config()`, `engine_config()`,
...) that gets an invalid value raises `ValueError` (`The TrainerConfig
that this config builds is invalid: <path>: <message>`), not the
component's `ValidationError`. Entrypoint parsing still raises
`ValidationError`.
- No checked-in config changes.

## Verification

On 3603799, on macOS without torch or vllm. CI runs the full unit
suite.

**End to end over every checked-in config.** I dry-ran the local and
SLURM launchers for 104 cases. They cover every checked-in `rl`, `sft`
and `inference` TOML and documented overlay stack, plus synthetic
multi-node, P/D, SLURM and SFT online-eval cases. For each case, the
script checks four things:

1. The entrypoint parses, as on `main`: 102 of 104 parse on `main` and
on every PR of the stack. My script picks the wrong entrypoint for the
other 2, so they skip on `main` too.
2. **Round trip.** The entrypoint's dump parses again to the same dump
and the same `dump_components()`.
3. **Fixed point.** Each of the 402 component JSONs parses into its
class and dumps unchanged.
4. **Per-process values** match the snapshot of #4919.

| Tip | Entrypoint dump not a fixed point | Components change after
re-parse | Component JSON not a fixed point |
| --- | --- | --- | --- |
| #4909 (c86c474) | 3 (SFT `vllm.tokenizer`) | 11 (SFT
`vllm.tokenizer`, P/D prefill `kv_load_failure_policy` `recompute` →
`None`) | 0 |
| #4919 (92c8097) | 3 | 11 | 0 |
| this PR (3603799) | 0 | 0 | 0 |

- **Launcher output vs. #4919.** The dry-run JSON differs in key order
and in these fields:
- `trainer.json` and `orchestrator.json`: `monitors.file.float_decimals
= 6` in the two `color-codeword` configs now reaches both processes (it
was 4).
- `engine.json`: the new typed vLLM keys at their defaults, and
`data_parallel_size_local = 1` (was `null`) in `recipes/intellect-3.1`
and `recipes/minimax-m2.5` (DP = 1, so vLLM behaves the same).
- `rl.json`, `sft.json`: the user's values, as listed under Breaking,
and in `rl.json` the component-only checkpoint and trace settings under
`[trainer]` and `[orchestrator]`.

The builder refactor leaves every component JSON and sbatch of #4919
byte-identical.
- **P/D sbatch.** Before c165715, all 72 vLLM settings in `ROLE_EXTRA`
and all 49 role env exports across the 11 P/D cases matched
`engine-<role>.json`, with 0 mismatches. So dropping them from the
sbatch leaves each rank's settings unchanged.
- **Speculative drafts in P/D overrides.** `rl` now rejects score
centering with a speculative draft in `decode_vllm_overrides` (`With
speculative decoding, sampler logprobs … need truncated train
sampling`), as it does for a draft on `[inference.vllm]`. #4919 accepts
it.
- **Single-node SLURM `inference` with `deployment.type = "multi_node"`
and `num_nodes = 1`.** The sbatch now runs `engine` per rank. #4919 runs
`uv run inference` on the engine-only `inference.json`, which fails.
- **research-prod (906b2e8d).** I parsed its 167 documented config
stacks from `research-prod/prime-rl` on `main` (42e1e43) and on this
PR. 113 parse on `main`, and the same 113 parse here. The env packages
of `int4/rl/prod/rl.toml` are missing on my machine, so I swapped its
train sources for a stub. With its two `[ckpt]` lines moved, it resolves
to the same values as on `main`: trace sample 0.1 without live traces,
checkpoints every 20 steps with rollouts and a 180 s timeout, and DP 8 /
8 local / 8 API servers per engine. Its NUMA sbatch template still finds
its one `uv run orchestrator` line.
- **Tests.** The 17 config, launch, router, resume, client, dynamo,
algorithm and model-source test files: 990 passed in 7 s.

The first six rows ran on the commits of the closed #4921–#4925, before
they were folded into this PR. Rows 15–19 ran on 1c92480, the last
three on 3603799, the others on 2ba08c1.

| Change removed | Result |
| --- | --- |
| run-level fields in `_run_fields()` |
`test_run_level_fields_reach_trainer_and_orchestrator` fails |
| prefill policy derived from the value (back to `fields_set`) |
`test_resolved_configs_parse_to_the_same_components[rl-pd-bidirectional]`
fails |
| role vLLM overrides validated with the build (back to `setattr`) |
`test_engines_and_routers_are_built_whole[rl-pd-prefill-overrides]`
fails |
| LoRA → 1 API server in `engine_layout` |
`test_rl_engine_layout[…trainer4]`: `(4, None, 4) != (4, None, 1)` |
| `speculative_config` field (back to an extra) | 130 tests fail |
| P/D role drafts in `speculative_configs` |
`test_a_pd_role_draft_without_its_own_weights_fails_under_a_dummy_target`:
did not raise |
| LoRA in `resolved_inference()` |
`test_rl_sections_keep_the_values_the_user_wrote` fails |
| NVFP4 env defaults in `resolved_inference()` |
`test_rl_nvfp4_experts_set_up_matching_engines` fails |
| NVFP4 check on the built engines | same test: did not raise |
| draft fill in `orchestrator_config()` |
`test_modelexpress_serves_a_draft_and_swaps_it` fails |
| score-centering logprobs in `orchestrator_config()` |
`test_rl_launcher_config_roundtrip`: `None == 4` |
| metrics roles in `orchestrator_config()` |
`test_modelexpress_under_pd_transfers_to_every_prefill_and_decode_gpu`
fails |
| speculative sampler-logprobs check on the built configs |
`test_rl_checks_settings_that_must_agree_on_the_built_configs`: did not
raise |
| SFT LoRA, client URLs or dummy load in the builders |
`test_sft_sections_keep_the_values_the_user_wrote` fails |
| default `base_url` found by value (back to `model_fields_set`) |
`test_resolved_configs_parse_to_the_same_components[rl-inference-port]`
and `[sft-online-eval-port]` fail |
| API-server check under in-memory weight broadcast |
`test_in_memory_weight_transfer_needs_an_api_server_per_rank`: did not
raise |
| wired configs copied in `build_component_config` |
`test_components_share_no_run_level_instance` fails |
| component name in builder errors |
`test_a_component_error_names_the_component` fails |
| `is_multi_node` in `inference.sbatch.j2` (back to `num_nodes > 1`) |
`test_a_one_node_multi_node_deployment_runs_its_engine_per_rank` fails |
| `[trainer.ckpt]` / `[orchestrator.ckpt]` merged into the component
checkpoint |
`test_ckpt_takes_shared_settings_at_the_top_and_component_settings_in_the_sections`
and both `test_ckpt_rollouts_*` tests fail |
| trace options of `[orchestrator.monitors.file]` merged |
`test_trace_options_reach_only_the_orchestrator` fails |
| check that a component ckpt section needs `[ckpt]` |
`test_ckpt_takes_shared_settings_…`: did not raise |

The old `rl` check for llm-d with router replay is gone: the inference
section's own check now catches it on the resolved config, so the test
still raises.

No GPU run. The P/D sbatch evidence ran on 5456cb0, before this
branch's rebase onto the new #4919 tip.

## Merge order

Merge last, after #4899 → #4909 → #4919. It is stacked on #4919
(`feat/configs-layout`). Rebase it onto `main` after each squash merge.

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

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **High Risk**
> Large breaking config/API surface (CLI paths, engine layout
validation, sbatch template vars) affects every RL/SFT launch;
mis-derived engine DP/API counts can deadlock weight transfer.
> 
> **Overview**
> **Config layout.** `rl` now owns run-wide settings only at the top
level (`max_steps`, `resume`, `[ckpt]`, `[monitors]`,
`rollout_transport`). Component sections hold side-specific knobs
(`[trainer.ckpt]`, `[orchestrator.ckpt.rollouts]`,
`[orchestrator.monitors.file]`). Builders merge run + section into
validated component JSON once via `build_component_config` /
`copy_validated`, instead of copying fields through
`propagate_shared_fields` and post-hoc equality checks.
> 
> **Inference derivation.** New `resolved_inference()` (and SFT
analogue) centralizes dummy load, LoRA, router replay, NVFP4 env,
sampling masks, and **`engine_layout()`** / `fit_engines()` for
`data_parallel_size` and `api_server_count` (defaults `"auto"`). vLLM
options move from untyped extras to typed fields on `VllmConfig`. P/D
role engines are built only from `engine_config()` JSON—SLURM templates
drop `ROLE_EXTRA` / role-specific vLLM override template vars.
> 
> **Orchestrator wiring** moves into `orchestrator_config()` (draft
swaps, score-centering logprobs, client/admin URLs, disaggregated
metrics roles). Cross-process checks (NVFP4 engines, speculative +
sampler logprobs) run on built `components()`.
> 
> **Docs and launchers** switch CLI examples to prefixed paths
(`--orchestrator.ckpt.rollouts`, `--trainer.ckpt.async-save`). Run
owners and Prime monitor read `config.monitors` / `config.max_steps` at
entrypoint level; `rl` rejects shared W&B offline mode.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
3603799. 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