Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26db10418e | ||
|
|
c2a84f5604 | ||
|
|
bdac9df86e |
@@ -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)
|
||||
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
from collections import Counter
|
||||
from pathlib import Path
|
||||
from typing import NamedTuple
|
||||
|
||||
@@ -106,12 +107,21 @@ class Scheduler:
|
||||
self.inflight_group_rollouts.clear()
|
||||
self.cancelled_rollouts_count += count
|
||||
|
||||
async def _select_least_loaded_client(self) -> vf.ClientConfig:
|
||||
"""Select the client with the fewest in-flight tasks."""
|
||||
clients = self.inference_pool.clients
|
||||
while not clients:
|
||||
await asyncio.sleep(1)
|
||||
clients = self.inference_pool.clients
|
||||
inflight_by_url = Counter(info.client_config.api_base_url for info in self.inflight_group_rollouts.values())
|
||||
return min(clients, key=lambda c: inflight_by_url[c.api_base_url])
|
||||
|
||||
async def schedule_group_rollout(self):
|
||||
"""Asynchronously schedules a group rollout request."""
|
||||
if self.rate_limiter:
|
||||
await self.rate_limiter.acquire()
|
||||
example = self.buffer.sample_examples(n=1)[0]
|
||||
client_config = await self.inference_pool.get_next_client()
|
||||
client_config = await self._select_least_loaded_client()
|
||||
run_group_task = asyncio.create_task(
|
||||
run_group(
|
||||
env=self.env,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user