From 56a0624e608c9377453b295afdfee2cfe3cefa0b Mon Sep 17 00:00:00 2001 From: Sami Jaghouar Date: Fri, 17 Apr 2026 23:48:19 +0000 Subject: [PATCH 1/2] chore: remove prefix-cache-salt and reset-prefix-cache config flags Hardcode the defaults: always set cache_salt on inference requests (keyed by ckpt_step) and never reset the prefix cache after weight or LoRA updates. The salt alone is sufficient to invalidate stale KV states across policy updates, so the reset path is redundant. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/prime_rl/configs/inference.py | 18 ------------------ src/prime_rl/configs/orchestrator.py | 18 ------------------ src/prime_rl/inference/vllm/server.py | 13 +------------ src/prime_rl/orchestrator/envs.py | 10 ++++------ src/prime_rl/orchestrator/orchestrator.py | 7 ++----- src/prime_rl/orchestrator/scheduler.py | 4 +--- tests/unit/orchestrator/test_scheduler.py | 1 - 7 files changed, 8 insertions(+), 63 deletions(-) diff --git a/src/prime_rl/configs/inference.py b/src/prime_rl/configs/inference.py index 23a3a5b3c8f..a429b12858b 100644 --- a/src/prime_rl/configs/inference.py +++ b/src/prime_rl/configs/inference.py @@ -244,19 +244,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.""" @@ -426,11 +413,6 @@ class InferenceConfig(BaseConfig): dry_run: Annotated[bool, Field(description="Only validate and dump resolved configs and exit early.")] = False - experimental: Annotated[ - InferenceExperimentalConfig, - Field(description="Experimental features for inference."), - ] = InferenceExperimentalConfig() - @model_validator(mode="after") def validate_multi_node_requires_slurm(self): if self.deployment.type == "multi_node" and self.slurm is None: diff --git a/src/prime_rl/configs/orchestrator.py b/src/prime_rl/configs/orchestrator.py index c37914b7a84..cda98b38e21 100644 --- a/src/prime_rl/configs/orchestrator.py +++ b/src/prime_rl/configs/orchestrator.py @@ -809,19 +809,6 @@ class NCCLWeightBroadcastConfig(BaseModel): ] -class OrchestratorExperimentalConfig(BaseConfig): - """Experimental features for the orchestrator.""" - - use_prefix_cache_salt: Annotated[ - 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).""" @@ -1052,11 +1039,6 @@ class OrchestratorConfig(BaseConfig): ), ] = False - experimental: Annotated[ - OrchestratorExperimentalConfig, - Field(description="Experimental features for the orchestrator."), - ] = OrchestratorExperimentalConfig() - @model_validator(mode="before") @classmethod def _env_to_train(cls, data: Any) -> Any: diff --git a/src/prime_rl/inference/vllm/server.py b/src/prime_rl/inference/vllm/server.py index 2244b705c30..2499c58e112 100644 --- a/src/prime_rl/inference/vllm/server.py +++ b/src/prime_rl/inference/vllm/server.py @@ -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"} @@ -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) @@ -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}'") diff --git a/src/prime_rl/orchestrator/envs.py b/src/prime_rl/orchestrator/envs.py index d9844c37035..5bece496c1e 100644 --- a/src/prime_rl/orchestrator/envs.py +++ b/src/prime_rl/orchestrator/envs.py @@ -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 @@ -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( @@ -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( @@ -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 diff --git a/src/prime_rl/orchestrator/orchestrator.py b/src/prime_rl/orchestrator/orchestrator.py index 2eda300b84f..95cb3906a3b 100644 --- a/src/prime_rl/orchestrator/orchestrator.py +++ b/src/prime_rl/orchestrator/orchestrator.py @@ -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 @@ -380,7 +379,6 @@ 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( @@ -388,7 +386,7 @@ async def orchestrate(config: OrchestratorConfig): 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 ] @@ -718,7 +716,6 @@ 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( @@ -726,7 +723,7 @@ def compute_solve_rates(df): 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 ] diff --git a/src/prime_rl/orchestrator/scheduler.py b/src/prime_rl/orchestrator/scheduler.py index 70e33286646..cdd5f22bc2c 100644 --- a/src/prime_rl/orchestrator/scheduler.py +++ b/src/prime_rl/orchestrator/scheduler.py @@ -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: @@ -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 @@ -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 diff --git a/tests/unit/orchestrator/test_scheduler.py b/tests/unit/orchestrator/test_scheduler.py index 9c9c7ac50de..af388ade6e3 100644 --- a/tests/unit/orchestrator/test_scheduler.py +++ b/tests/unit/orchestrator/test_scheduler.py @@ -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 From 26fdbc9aa39fd40fa4328e0e1a2fe25a8226cb90 Mon Sep 17 00:00:00 2001 From: Sami Jaghouar Date: Sat, 18 Apr 2026 00:14:00 +0000 Subject: [PATCH 2/2] chore: keep empty experimental sub-configs as extension points Co-Authored-By: Claude Opus 4.7 (1M context) --- src/prime_rl/configs/inference.py | 9 +++++++++ src/prime_rl/configs/orchestrator.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/prime_rl/configs/inference.py b/src/prime_rl/configs/inference.py index a429b12858b..b00a7ddec42 100644 --- a/src/prime_rl/configs/inference.py +++ b/src/prime_rl/configs/inference.py @@ -244,6 +244,10 @@ def validate_replicas_divide_nodes(self): ] +class InferenceExperimentalConfig(BaseConfig): + """Experimental features for inference.""" + + class InferenceConfig(BaseConfig): """Configures inference.""" @@ -413,6 +417,11 @@ class InferenceConfig(BaseConfig): dry_run: Annotated[bool, Field(description="Only validate and dump resolved configs and exit early.")] = False + experimental: Annotated[ + InferenceExperimentalConfig, + Field(description="Experimental features for inference."), + ] = InferenceExperimentalConfig() + @model_validator(mode="after") def validate_multi_node_requires_slurm(self): if self.deployment.type == "multi_node" and self.slurm is None: diff --git a/src/prime_rl/configs/orchestrator.py b/src/prime_rl/configs/orchestrator.py index cda98b38e21..ba0a2fa6cb0 100644 --- a/src/prime_rl/configs/orchestrator.py +++ b/src/prime_rl/configs/orchestrator.py @@ -809,6 +809,10 @@ class NCCLWeightBroadcastConfig(BaseModel): ] +class OrchestratorExperimentalConfig(BaseConfig): + """Experimental features for the orchestrator.""" + + class TeacherModelConfig(BaseConfig): """Configures the teacher model for computing teacher logprobs (e.g. for distillation).""" @@ -1039,6 +1043,11 @@ class OrchestratorConfig(BaseConfig): ), ] = False + experimental: Annotated[ + OrchestratorExperimentalConfig, + Field(description="Experimental features for the orchestrator."), + ] = OrchestratorExperimentalConfig() + @model_validator(mode="before") @classmethod def _env_to_train(cls, data: Any) -> Any: