Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/prime_rl/configs/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,6 @@ def validate_replicas_divide_nodes(self):
class InferenceExperimentalConfig(BaseConfig):
"""Experimental features for inference."""

reset_prefix_cache_after_update: Annotated[
bool,
Field(
description="Whether to reset the prefix cache after weight updates (update_weights, load_lora_adapter). "
"Ensures all KV states are recomputed with the new weights at the cost of extra prefill. "
"When False, prefer using orchestrator.experimental.use_prefix_cache_salt to invalidate stale caches via salt instead.",
),
] = False


class InferenceConfig(BaseConfig):
"""Configures inference."""
Expand Down
9 changes: 0 additions & 9 deletions src/prime_rl/configs/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,15 +812,6 @@ class NCCLWeightBroadcastConfig(BaseModel):
class OrchestratorExperimentalConfig(BaseConfig):
"""Experimental features for the orchestrator."""

use_prefix_cache_salt: Annotated[

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty experimental config classes left as dead code

Low Severity

After removing their only fields, OrchestratorExperimentalConfig and InferenceExperimentalConfig are now empty classes with no fields. They are still instantiated as experimental fields on OrchestratorConfig and InferenceConfig, but nothing in the codebase accesses .experimental anymore. The PR description explicitly states the intent to remove these classes and their parent fields, but this wasn't carried out.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 26fdbc9. Configure here.

bool,
Field(
description="Whether to set a cache_salt on inference requests that changes with each weight update. "
"This invalidates prefix-cached KV states from previous policies without resetting the entire cache, "
"while preserving cache hits for in-flight off-policy rollouts.",
),
] = True


class TeacherModelConfig(BaseConfig):
"""Configures the teacher model for computing teacher logprobs (e.g. for distillation)."""
Expand Down
13 changes: 1 addition & 12 deletions src/prime_rl/inference/vllm/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,16 @@ async def resume(request: Request):
async def update_weights(request: Request):
data = await request.json()
await engine_client(request).collective_rpc("update_weights_from_path", args=(data.get("weight_dir"),))
if request.app.state.reset_prefix_cache_after_update:
await engine_client(request).reset_prefix_cache()
return {"status": "ok"}


@router.post("/load_lora_adapter")
async def load_lora_adapter(lora_request: LoadLoRAAdapterRequest, raw_request: Request):
"""Load a LoRA adapter, optionally resetting the prefix cache.

Wrapper around vLLM's /v1/load_lora_adapter that also resets the prefix cache
to invalidate KV states computed with old weights (unless disabled via config).
"""
"""Wrapper around vLLM's /v1/load_lora_adapter."""
handler = models(raw_request)
response = await handler.load_lora_adapter(lora_request)
if isinstance(response, ErrorResponse):
return JSONResponse(content=response.model_dump(), status_code=response.error.code)
if raw_request.app.state.reset_prefix_cache_after_update:
await engine_client(raw_request).reset_prefix_cache()
return {"status": "ok"}


Expand Down Expand Up @@ -274,8 +266,6 @@ async def custom_init_app_state(
"""
await init_app_state(engine_client, state, args, supported_tasks)

state.reset_prefix_cache_after_update = getattr(args, "reset_prefix_cache_after_update", True)

if "generate" in supported_tasks and state.openai_serving_chat is not None:
original_chat = state.openai_serving_chat
serving_chat = object.__new__(OpenAIServingChatWithTokens)
Expand Down Expand Up @@ -342,7 +332,6 @@ def server(config: InferenceConfig, vllm_extra: dict[str, Any] | None = None):

args.tool_call_parser = resolve_tool_call_parser(args.model, args.tool_call_parser)
args.enable_auto_tool_choice = args.tool_call_parser is not None
args.reset_prefix_cache_after_update = config.experimental.reset_prefix_cache_after_update
if args.tool_call_parser is not None:
logger.info(f"Using tool_call_parser='{args.tool_call_parser}' for model '{args.model}'")

Expand Down
10 changes: 4 additions & 6 deletions src/prime_rl/orchestrator/envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ def _spawn(
self._env_server_process = process
return address

def _sampling_args_with_salt(self, cache_salt: str | None) -> dict:
if cache_salt is None:
return self.sampling_args
def _sampling_args_with_salt(self, cache_salt: str) -> dict:
sampling_args = {**self.sampling_args}
extra_body = {**sampling_args.get("extra_body", {}), "cache_salt": cache_salt}
sampling_args["extra_body"] = extra_body
Expand All @@ -117,7 +115,7 @@ async def run_rollout(
client: vf.ClientConfig,
example: dict,
model_name: str,
cache_salt: str | None = None,
cache_salt: str,
) -> vf.RolloutOutput:
"""Run a single rollout for an example."""
return await self.env.run_rollout(
Expand All @@ -136,7 +134,7 @@ async def run_group(
example: dict,
model_name: str,
rollouts_per_example: int,
cache_salt: str | None = None,
cache_salt: str,
) -> list[vf.RolloutOutput]:
"""Run a group of rollouts for an example. Required for group-scoring envs."""
return await self.env.run_group(
Expand Down Expand Up @@ -181,7 +179,7 @@ async def evaluate(
get_client: Callable[[], Awaitable[vf.ClientConfig]],
ckpt_step: int,
step: int,
cache_salt: str | None = None,
cache_salt: str,
) -> list[vf.RolloutOutput]:
num_examples = len(self.examples)
rollouts_per_example = self.config.rollouts_per_example
Expand Down
7 changes: 2 additions & 5 deletions src/prime_rl/orchestrator/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ async def orchestrate(config: OrchestratorConfig):
enable_policy_updates=enable_policy_updates,
lora_name=config.model.lora.name if config.model.lora else None,
config=config,
use_prefix_cache_salt=config.experimental.use_prefix_cache_salt,
)
scheduler.model_name = rollout_model_name

Expand Down Expand Up @@ -380,15 +379,14 @@ async def orchestrate(config: OrchestratorConfig):
logger.info("Cancelling in-flight training rollouts before starting evals to avoid congestion.")
await scheduler.cancel_inflight_rollouts()

eval_cache_salt = str(ckpt_step) if config.experimental.use_prefix_cache_salt else None
eval_results = await asyncio.gather(
*[
eval_env.evaluate(
model_name=scheduler.model_name,
get_client=inference_pool.get_eval_client,
ckpt_step=ckpt_step,
step=progress.step,
cache_salt=eval_cache_salt,
cache_salt=str(ckpt_step),
)
for eval_env in envs_to_eval
]
Expand Down Expand Up @@ -718,15 +716,14 @@ def compute_solve_rates(df):

if config.eval and eval_envs is not None:
logger.info("Running final evals")
final_cache_salt = str(ckpt_step) if config.experimental.use_prefix_cache_salt else None
eval_results = await asyncio.gather(
*[
eval_env.evaluate(
model_name=scheduler.model_name,
get_client=inference_pool.get_eval_client,
ckpt_step=ckpt_step,
step=progress.step,
cache_salt=final_cache_salt,
cache_salt=str(ckpt_step),
)
for eval_env in eval_envs
]
Expand Down
4 changes: 1 addition & 3 deletions src/prime_rl/orchestrator/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def __init__(
tasks_per_minute: int | None,
enable_policy_updates: bool = True,
lora_name: str | None = None,
use_prefix_cache_salt: bool = False,
):
self.logger = get_logger()
if tasks_per_minute is not None:
Expand All @@ -87,7 +86,6 @@ def __init__(
self.strict_async_level = strict_async_level
self.enable_policy_updates = enable_policy_updates
self.lora_name = lora_name
self.use_prefix_cache_salt = use_prefix_cache_salt
self.model_name = self.config.model.name
self.json_logging = config.log.json_logging

Expand Down Expand Up @@ -198,7 +196,7 @@ async def schedule_rollout(self, group_id: int):
env_name = group.example["env_name"]
env = self.train_envs.get(env_name)

cache_salt = str(self.ckpt_step) if self.use_prefix_cache_salt else None
cache_salt = str(self.ckpt_step)
if env.requires_group_scoring:
rollout_count = group.rollouts_to_schedule
group.rollouts_to_schedule = 0
Expand Down
1 change: 0 additions & 1 deletion tests/unit/orchestrator/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def make_scheduler() -> Scheduler:
scheduler.inflight_policy_update_task = None
scheduler.update_policy_task = None
scheduler.enable_policy_updates = True
scheduler.use_prefix_cache_salt = False
return scheduler


Expand Down
Loading