Compare commits

...
Author SHA1 Message Date
JannikStandGitHub 26db10418e WIP fix: call evaluate with explicit keyword arguments (#1792)
Release / Push CUDA image to Docker (push) Canceled after 0s
* fix: call evaluate with explicit keyword arguments

* chore: apply ruff format to vf utils

* fix: lazy client selection for elastic inference during evals

* refactor: make clients optional, remove redundant params from eval calls
2026-02-15 14:06:11 -08:00
c2a84f5604 fix(logging): route fatal errors through custom JSON logger instead of default loguru (#1789)
Release / Push CUDA image to Docker (push) Canceled after 0s
@logger.catch used loguru's default global logger, not the custom logger
created by setup_logger(). This meant fatal exceptions bypassed the JSON
formatter entirely. Move exception logging into clean_exit using get_logger(),
with a safe fallback to loguru's default if the logger isn't set up yet.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 11:41:59 -08:00
7 changed files with 34 additions and 18 deletions
@@ -1,4 +1,3 @@
from loguru import logger
from verifiers.workers import ZMQEnvServer
from prime_rl.orchestrator.env_server.config import EnvServerConfig
@@ -9,7 +8,6 @@ from prime_rl.utils.utils import clean_exit, get_env_ids_to_install, install_env
@clean_exit
@logger.catch(reraise=True)
def run_server(config: EnvServerConfig):
setup_logger(config.log.level, json_logging=config.log.json_logging)
+11 -2
View File
@@ -1,4 +1,5 @@
import time
from collections.abc import Awaitable, Callable
from typing import Any
import numpy as np
@@ -65,7 +66,6 @@ def compute_pass_at_k(rewards: list[int]) -> dict[str, float]:
async def evaluate_env(
env: vf.Environment,
env_name: str,
clients: list[vf.ClientConfig],
model_name: str,
sampling_args: dict,
num_examples: int,
@@ -73,11 +73,20 @@ async def evaluate_env(
max_retries: int,
ckpt_step: int,
step: int | None,
get_client: Callable[[], Awaitable[vf.ClientConfig]],
):
logger = get_logger()
logger.info(f"Evaluating {env_name} ({num_examples=}, {rollouts_per_example=})")
eval_start_time = time.perf_counter()
outputs = await evaluate(env, clients, model_name, sampling_args, num_examples, rollouts_per_example, max_retries)
outputs = await evaluate(
env=env,
model_name=model_name,
sampling_args=sampling_args,
num_examples=num_examples,
rollouts_per_example=rollouts_per_example,
get_client=get_client,
max_retries=max_retries,
)
eval_time = time.perf_counter() - eval_start_time
rows = []
+3 -6
View File
@@ -24,7 +24,6 @@ monkey_patch_chat_completion_logprobs()
import pandas as pd
import verifiers as vf
from loguru import logger
from transformers import AutoProcessor, AutoTokenizer
from prime_rl.orchestrator.buffer import Buffer
@@ -71,7 +70,6 @@ from prime_rl.utils.vlm import is_vlm_model
@clean_exit
@logger.catch(reraise=True)
async def orchestrate(config: OrchestratorConfig):
# Initialize the logger
logger = setup_logger(
@@ -388,13 +386,12 @@ async def orchestrate(config: OrchestratorConfig):
# this avoid doing eval across different checkpoints and avoid congestion
scheduler.checkpoint_ready.clear()
scheduler.cancel_all_inflight_rollouts()
results = await asyncio.gather(
*[
evaluate_env(
env=eval_env,
env_name=eval_env_name,
clients=inference_pool.clients,
get_client=inference_pool.get_next_client,
model_name=scheduler.model_name,
sampling_args=eval_sampling_args,
num_examples=eval_env_config.num_examples or config.eval.num_examples,
@@ -423,11 +420,11 @@ async def orchestrate(config: OrchestratorConfig):
val_task = asyncio.create_task(
generate(
env=train_env_group,
clients=inference_pool.clients,
model_name=scheduler.model_name,
examples=val_examples,
rollouts_per_example=config.val.rollouts_per_example,
sampling_args=sampling_args,
clients=inference_pool.clients,
pbar_description="Generating rollouts (val)",
)
)
@@ -730,7 +727,7 @@ async def orchestrate(config: OrchestratorConfig):
evaluate_env(
env=eval_env,
env_name=eval_env_name,
clients=inference_pool.clients,
get_client=inference_pool.get_next_client,
model_name=scheduler.model_name,
sampling_args=eval_sampling_args,
num_examples=eval_env_config.num_examples or config.eval.num_examples,
+18 -4
View File
@@ -1,5 +1,6 @@
import asyncio
import logging
from collections.abc import Awaitable, Callable
from itertools import cycle
from multiprocessing import Process
from typing import Any
@@ -111,11 +112,12 @@ async def run_group(
# TODO: migrate this to vf.Environment.generate() once it supports multiple clients
async def generate(
env: vf.Environment,
clients: list[vf.ClientConfig],
model_name: str,
examples: list,
rollouts_per_example: int,
sampling_args: dict,
clients: list[vf.ClientConfig] | None = None,
get_client: Callable[[], Awaitable[vf.ClientConfig]] | None = None,
max_retries: int = DEFAULT_RETRIES,
state_columns: list[str] = DEFAULT_STATE_COLUMNS,
pbar_description: str = "Generating rollouts",
@@ -128,10 +130,20 @@ async def generate(
Asynchronously generates and scores a list of groups.
"""
if not clients and get_client is None:
raise ValueError("generate requires at least one client or a get_client callback")
if get_client is None:
client_cycle = cycle(clients)
async def get_client() -> vf.ClientConfig:
return next(client_cycle)
total_rollouts = len(examples) * rollouts_per_example
pbar = ProgressTracker(total=total_rollouts, desc=pbar_description)
async def run_group_with_progress(client, example):
async def run_group_with_progress(example):
client = await get_client()
result = await run_group(
env=env,
client=client,
@@ -147,7 +159,7 @@ async def generate(
try:
group_outputs_list: list[list[vf.RolloutOutput]] = await asyncio.gather(
*[run_group_with_progress(client, example) for client, example in zip(cycle(clients), examples)]
*[run_group_with_progress(example) for example in examples]
)
finally:
pbar.close()
@@ -157,11 +169,12 @@ async def generate(
async def evaluate(
env: vf.Environment,
clients: list[vf.ClientConfig],
model_name: str,
sampling_args: dict,
num_examples: int,
rollouts_per_example: int,
clients: list[vf.ClientConfig] | None = None,
get_client: Callable[[], Awaitable[vf.ClientConfig]] | None = None,
max_retries: int = DEFAULT_RETRIES,
state_columns: list[str] = DEFAULT_STATE_COLUMNS,
) -> list[vf.RolloutOutput]:
@@ -176,6 +189,7 @@ async def evaluate(
outputs = await generate(
env=env,
clients=clients,
get_client=get_client,
model_name=model_name,
examples=inputs,
# _get_eval_inputs() already repeats the examples, this currently means
-2
View File
@@ -12,7 +12,6 @@ import torch
import torch.distributed as dist
import torch.distributed.nn as dist_nn
from torch.profiler import profile, ProfilerActivity, record_function
from loguru import logger
from prime_rl.trainer.ckpt import setup_ckpt_managers
from prime_rl.trainer.multi_ckpt import setup_multi_checkpoint_manager
from prime_rl.trainer.optim import setup_optimizer, setup_multi_optimizer
@@ -63,7 +62,6 @@ from torchtitan.distributed.utils import clip_grad_norm_
@clean_exit
@logger.catch(reraise=True)
def train(config: RLTrainerConfig):
# Setup world and logger
world = get_world()
-2
View File
@@ -12,7 +12,6 @@ from prime_rl.trainer.models.layers.attn import substitute_prime_rl_flash_attn
from prime_rl.utils.act_offloading import maybe_activation_offloading
import torch
from torch.profiler import profile, ProfilerActivity, record_function
from loguru import logger
from prime_rl.trainer.ckpt import setup_ckpt_managers
from prime_rl.utils.pathing import resolve_latest_ckpt_step
from prime_rl.trainer.sft.config import SFTTrainerConfig
@@ -51,7 +50,6 @@ from torchtitan.distributed.utils import clip_grad_norm_
@clean_exit
@logger.catch(reraise=True)
def train(config: SFTTrainerConfig):
# Setup world and logger
world = get_world()
+2
View File
@@ -130,6 +130,7 @@ def clean_exit(func: Callable) -> Callable:
wandb.finish()
return ret
except Exception as e:
get_logger().opt(exception=True).error(f"Fatal error in {func.__name__}")
wandb.finish(exit_code=1)
raise e
finally:
@@ -146,6 +147,7 @@ def clean_exit(func: Callable) -> Callable:
wandb.finish()
return ret
except Exception as e:
get_logger().opt(exception=True).error(f"Fatal error in {func.__name__}")
wandb.finish(exit_code=1)
raise e
finally: