Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56a9402953 | ||
|
|
0c0b92f99c | ||
|
|
84ce4d6677 |
@@ -301,6 +301,11 @@ class EvalConfig(BaseConfig):
|
||||
"""If True, skip the startup eval that otherwise runs before any
|
||||
train rollouts."""
|
||||
|
||||
retrigger_on_resume: bool = False
|
||||
"""If True, re-trigger evals at the checkpoint step on resume (e.g. after a
|
||||
crash that left in-flight evals unfinished). By default, assumes a clean
|
||||
exit where all evals already completed."""
|
||||
|
||||
@model_validator(mode="after")
|
||||
def resolve_env_defaults(self):
|
||||
"""Resolve per-env overrides: inherit group-level sampling, num_examples,
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "prime-rl"
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
description = "Async RL Training at Scale"
|
||||
readme = "README.md"
|
||||
requires-python = "~=3.12.0"
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import torch
|
||||
|
||||
from prime_rl.inference.vllm.padded_input_scrub import monkey_patch_vllm_padded_input_scrub
|
||||
|
||||
|
||||
def apply_shared_vllm_patches():
|
||||
"""vLLM general plugin: prime-rl patches that must run in every vLLM process.
|
||||
@@ -16,7 +14,6 @@ def apply_shared_vllm_patches():
|
||||
monkey_patch_nano_v3_reasoning_parser()
|
||||
monkey_patch_qwen3_coder_param_newline_trim()
|
||||
monkey_patch_minimax_m2_think_end_passthrough()
|
||||
monkey_patch_vllm_padded_input_scrub()
|
||||
monkey_patch_return_routed_experts_with_nixl_connector()
|
||||
monkey_patch_kv_xfer_finished_tolerate_freed()
|
||||
monkey_patch_online_fp8_parameter_cast()
|
||||
|
||||
@@ -10,14 +10,10 @@ def setup_vllm_env(config: InferenceConfig):
|
||||
# spawn is more robust in vLLM nightlies and Qwen3-VL (fork can deadlock with multithreaded processes)
|
||||
os.environ.setdefault("VLLM_WORKER_MULTIPROC_METHOD", "spawn")
|
||||
|
||||
# Force the V1 GPU model runner. vLLM 0.24.0 routes Llama/Mistral/Qwen3 plus MoE archs
|
||||
# (DeepseekV2, Qwen2Moe, GraniteMoe; the 0.23 MoE/quantized guard was removed) to the
|
||||
# V2 runner, which has no `_preprocess` hook for our padded-input scrub (see
|
||||
# inference/vllm/padded_input_scrub.py) and doesn't zero the padded decode tail
|
||||
# itself; that stale tail poisons CUDA-graph replay as NaN logits (reproduced on
|
||||
# Nemotron-Nano SWE, PR #2506; upstream fix vllm#42779 is still unmerged). V1 keeps
|
||||
# the scrub effective for every model and is also required for routed-experts capture
|
||||
# (the NIXL PD path rejects V2). setdefault so it stays overridable.
|
||||
# Force the V1 GPU model runner. vLLM routes Llama/Mistral/Qwen3 plus MoE archs
|
||||
# (DeepseekV2, Qwen2Moe, GraniteMoe) to the V2 runner by default, but V2 doesn't
|
||||
# support routed-experts capture (the NIXL PD path rejects it). setdefault so it
|
||||
# stays overridable.
|
||||
os.environ.setdefault("VLLM_USE_V2_MODEL_RUNNER", "0")
|
||||
|
||||
# vLLM 0.24.0 flipped VLLM_ENFORCE_STRICT_TOOL_CALLING's default to True, which
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import threading
|
||||
from collections.abc import Sequence
|
||||
from typing import Any
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_INSTALL_LOCK = threading.Lock()
|
||||
_INSTALLED = False
|
||||
|
||||
|
||||
def monkey_patch_vllm_padded_input_scrub() -> None:
|
||||
"""Zero vLLM's padded model inputs before graph replay.
|
||||
|
||||
vLLM pads decode batches up to CUDA graph capture sizes. Some kernels read
|
||||
model-input tensors past the scheduled-token prefix, so stale values in the
|
||||
padded tail can affect replayed decode graphs. Keep this shim until the
|
||||
vLLM-side fix is available in the pinned runtime.
|
||||
|
||||
Remove this patch once https://github.com/vllm-project/vllm/pull/42779 is
|
||||
included in the vLLM release we pin/use.
|
||||
"""
|
||||
global _INSTALLED
|
||||
with _INSTALL_LOCK:
|
||||
if _INSTALLED:
|
||||
return
|
||||
|
||||
from vllm.v1.worker.gpu_model_runner import GPUModelRunner
|
||||
|
||||
if getattr(GPUModelRunner, "_prime_rl_padded_input_scrub", False):
|
||||
_INSTALLED = True
|
||||
return
|
||||
|
||||
original_preprocess = GPUModelRunner._preprocess
|
||||
|
||||
def _patched_preprocess(
|
||||
self: Any,
|
||||
scheduler_output: Any,
|
||||
num_input_tokens: int,
|
||||
intermediate_tensors: Any | None = None,
|
||||
) -> tuple[Any, ...]:
|
||||
result = original_preprocess(
|
||||
self,
|
||||
scheduler_output,
|
||||
num_input_tokens,
|
||||
intermediate_tensors,
|
||||
)
|
||||
|
||||
num_scheduled_tokens = int(scheduler_output.total_num_scheduled_tokens)
|
||||
_zero_padded_model_inputs(
|
||||
result,
|
||||
num_scheduled_tokens,
|
||||
int(num_input_tokens),
|
||||
)
|
||||
return result
|
||||
|
||||
GPUModelRunner._preprocess = _patched_preprocess
|
||||
GPUModelRunner._prime_rl_padded_input_scrub = True
|
||||
_INSTALLED = True
|
||||
|
||||
logger.warning("Enabled vLLM padded model-input scrub.")
|
||||
|
||||
|
||||
def _zero_padded_model_inputs(
|
||||
preprocess_result: Sequence[Any],
|
||||
num_scheduled_tokens: int,
|
||||
num_input_tokens: int,
|
||||
) -> None:
|
||||
"""Zero the model-input tail beyond scheduled tokens in-place."""
|
||||
if num_input_tokens <= num_scheduled_tokens:
|
||||
return
|
||||
|
||||
input_ids = preprocess_result[0]
|
||||
inputs_embeds = preprocess_result[1]
|
||||
positions = preprocess_result[2]
|
||||
pad_slice = slice(num_scheduled_tokens, num_input_tokens)
|
||||
|
||||
if input_ids is not None:
|
||||
input_ids[pad_slice].zero_()
|
||||
if inputs_embeds is not None:
|
||||
inputs_embeds[pad_slice].zero_()
|
||||
if positions is not None:
|
||||
if positions.ndim == 1:
|
||||
positions[pad_slice].zero_()
|
||||
else:
|
||||
positions[..., pad_slice].zero_()
|
||||
@@ -25,7 +25,6 @@ from prime_rl.inference.patches import (
|
||||
monkey_patch_nano_v3_reasoning_parser,
|
||||
monkey_patch_strip_routed_experts_from_chat,
|
||||
monkey_patch_tokenize_params_validation,
|
||||
monkey_patch_vllm_padded_input_scrub,
|
||||
)
|
||||
|
||||
# NOTE: Fix harmony stop token propagation for GPT-OSS models
|
||||
@@ -37,9 +36,6 @@ monkey_patch_tokenize_params_validation()
|
||||
# NOTE: Register Nano V3 reasoning parser so configs can use
|
||||
# `reasoning_parser = "nano_v3"` without a vLLM plugin file.
|
||||
monkey_patch_nano_v3_reasoning_parser()
|
||||
# NOTE: Optional mitigation for vLLM padded decode inputs until the native fix
|
||||
# is available in our pinned runtime.
|
||||
monkey_patch_vllm_padded_input_scrub()
|
||||
# NOTE: routed_experts are consumed only via the serialized /generate path (router
|
||||
# replay). The chat-completions path encodes them as a base64 np.save string the PD
|
||||
# router cannot merge, which fails eval rollouts (they use chat completions). Strip
|
||||
|
||||
@@ -470,7 +470,11 @@ class Orchestrator:
|
||||
]
|
||||
|
||||
# Base-model eval (policy v0) — fires before any train rollouts, logged at the first
|
||||
# step, unless ``eval.skip_first_step=True`` (or this is a resume)
|
||||
# step, unless ``eval.skip_first_step=True``. On resume, defaults to assuming a clean
|
||||
# exit (evals already completed); set ``eval.retrigger_on_resume=True`` to also re-fire
|
||||
# interval-aligned evals at the checkpoint step (e.g. after a crash).
|
||||
if config.eval is not None and config.eval.retrigger_on_resume and self.resume_step is not None:
|
||||
self.maybe_trigger_eval(self.resume_step)
|
||||
self.maybe_trigger_eval(self.progress.step)
|
||||
|
||||
# Anchor step-time clock so the first step measures startup → first batch
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import torch
|
||||
|
||||
import prime_rl.inference.vllm.padded_input_scrub as padded_input_scrub
|
||||
from prime_rl.inference.vllm.padded_input_scrub import (
|
||||
_zero_padded_model_inputs,
|
||||
monkey_patch_vllm_padded_input_scrub,
|
||||
)
|
||||
|
||||
|
||||
def test_monkey_patch_preprocess_matches_vllm_preprocess_signature(monkeypatch):
|
||||
from vllm.v1.worker.gpu_model_runner import GPUModelRunner
|
||||
|
||||
calls = {}
|
||||
|
||||
def fake_preprocess(
|
||||
self,
|
||||
scheduler_output,
|
||||
num_input_tokens,
|
||||
intermediate_tensors=None,
|
||||
):
|
||||
calls["args"] = (
|
||||
self,
|
||||
scheduler_output,
|
||||
num_input_tokens,
|
||||
intermediate_tensors,
|
||||
)
|
||||
return (
|
||||
torch.tensor([10, 11, 12, 991, 992]),
|
||||
None,
|
||||
torch.tensor([0, 1, 2, 991, 992]),
|
||||
intermediate_tensors,
|
||||
{},
|
||||
None,
|
||||
)
|
||||
|
||||
monkeypatch.setattr(padded_input_scrub, "_INSTALLED", False)
|
||||
monkeypatch.setattr(GPUModelRunner, "_preprocess", fake_preprocess)
|
||||
monkeypatch.setattr(
|
||||
GPUModelRunner,
|
||||
"_prime_rl_padded_input_scrub",
|
||||
False,
|
||||
raising=False,
|
||||
)
|
||||
|
||||
monkey_patch_vllm_padded_input_scrub()
|
||||
|
||||
self = object()
|
||||
scheduler_output = SimpleNamespace(total_num_scheduled_tokens=3)
|
||||
intermediate_tensors = object()
|
||||
result = GPUModelRunner._preprocess(self, scheduler_output, 5, intermediate_tensors)
|
||||
|
||||
assert calls["args"] == (
|
||||
self,
|
||||
scheduler_output,
|
||||
5,
|
||||
intermediate_tensors,
|
||||
)
|
||||
assert result[0].tolist() == [10, 11, 12, 0, 0]
|
||||
assert result[2].tolist() == [0, 1, 2, 0, 0]
|
||||
|
||||
|
||||
def test_zero_padded_model_inputs_leaves_scheduled_prefix_intact():
|
||||
input_ids = torch.tensor([10, 11, 12, 991, 992])
|
||||
positions = torch.tensor([0, 1, 2, 991, 992])
|
||||
preprocess_result = (input_ids, None, positions, None, {}, None)
|
||||
|
||||
_zero_padded_model_inputs(
|
||||
preprocess_result,
|
||||
num_scheduled_tokens=3,
|
||||
num_input_tokens=5,
|
||||
)
|
||||
|
||||
assert input_ids.tolist() == [10, 11, 12, 0, 0]
|
||||
assert positions.tolist() == [0, 1, 2, 0, 0]
|
||||
|
||||
|
||||
def test_zero_padded_model_inputs_zeroes_embeddings_and_mrope_positions():
|
||||
inputs_embeds = torch.ones((5, 4))
|
||||
inputs_embeds[3:] = 7
|
||||
positions = torch.tensor(
|
||||
[
|
||||
[0, 1, 2, 991, 992],
|
||||
[0, 1, 2, 993, 994],
|
||||
[0, 1, 2, 995, 996],
|
||||
]
|
||||
)
|
||||
preprocess_result = (None, inputs_embeds, positions, None, {}, None)
|
||||
|
||||
_zero_padded_model_inputs(
|
||||
preprocess_result,
|
||||
num_scheduled_tokens=3,
|
||||
num_input_tokens=5,
|
||||
)
|
||||
|
||||
torch.testing.assert_close(inputs_embeds[:3], torch.ones((3, 4)))
|
||||
torch.testing.assert_close(inputs_embeds[3:], torch.zeros((2, 4)))
|
||||
assert positions.tolist() == [
|
||||
[0, 1, 2, 0, 0],
|
||||
[0, 1, 2, 0, 0],
|
||||
[0, 1, 2, 0, 0],
|
||||
]
|
||||
|
||||
|
||||
def test_zero_padded_model_inputs_noops_without_padding():
|
||||
input_ids = torch.tensor([10, 11, 12])
|
||||
positions = torch.tensor([0, 1, 2])
|
||||
preprocess_result = (input_ids, None, positions, None, {}, None)
|
||||
|
||||
_zero_padded_model_inputs(
|
||||
preprocess_result,
|
||||
num_scheduled_tokens=3,
|
||||
num_input_tokens=3,
|
||||
)
|
||||
|
||||
assert input_ids.tolist() == [10, 11, 12]
|
||||
assert positions.tolist() == [0, 1, 2]
|
||||
Reference in New Issue
Block a user