Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2fdffa7d3d |
@@ -347,6 +347,14 @@ class RLConfig(BaseConfig):
|
||||
self.weight_broadcast = SharedWeightBroadcastConfig(type="filesystem")
|
||||
else:
|
||||
self.weight_broadcast = SharedWeightBroadcastConfig()
|
||||
if self.weight_broadcast.type == "nccl" and self.trainer.model.lora is not None:
|
||||
# LoRA adapters are transferred via the filesystem (loaded from disk by the inference
|
||||
# servers); NCCL broadcast only writes a STABLE marker, so LoRA over NCCL cannot transfer
|
||||
# an adapter and would hang/fail on the startup weight sync.
|
||||
raise ValueError(
|
||||
"LoRA training is not yet supported with NCCL weight broadcast. "
|
||||
"Set weight_broadcast.type = 'filesystem'."
|
||||
)
|
||||
if self.weight_broadcast.type == "nccl":
|
||||
inference_world_size = self.inference.parallel.dp * self.inference.parallel.tp if self.inference else 1
|
||||
self.trainer.weight_broadcast = TrainerNCCLWeightBroadcastConfig(
|
||||
|
||||
@@ -101,6 +101,11 @@ MAX_CONSECUTIVE_EMPTY_BATCHES = 10
|
||||
# resumed when the watcher advances ``policy.version``.
|
||||
TARGET_LAG = 1
|
||||
|
||||
# Default wait for the trainer's startup weight broadcast when no ckpt block
|
||||
# configures ``wait_for_weights_timeout`` (e.g. a from-scratch run). The
|
||||
# broadcast is always coming, so wait rather than fail immediately.
|
||||
STARTUP_WEIGHT_WAIT_TIMEOUT_S = 1200
|
||||
|
||||
|
||||
class Orchestrator:
|
||||
# Set in ``__init__``
|
||||
@@ -315,19 +320,29 @@ class Orchestrator:
|
||||
# trainer even when ``ckpt.skip_progress`` left the counter unrestored.
|
||||
self.progress.step = self.resume_step + 1
|
||||
get_logger().info(f"Resuming orchestrator from checkpoint step {self.resume_step}")
|
||||
check_exists = config.weight_broadcast.type != "nccl"
|
||||
wait_timeout = config.ckpt.wait_for_weights_timeout if config.ckpt else None
|
||||
weights_path = get_weight_dir(
|
||||
config.output_dir, self.resume_step, check_exists=check_exists, wait_timeout=wait_timeout
|
||||
)
|
||||
await self.policy_inference.update_weights(weights_path, lora_name=self.lora_name, step=self.resume_step)
|
||||
if self.lora_name is not None:
|
||||
self.policy_inference.update_model_name(self.lora_name)
|
||||
self.policy.model_name = self.lora_name
|
||||
self.policy.version = self.resume_step
|
||||
else:
|
||||
get_logger().info("Training from scratch")
|
||||
|
||||
# Sync inference to the incoming policy before the first step, whether fresh (v0 = base) or
|
||||
# resumed (v{resume_step}). This pauses inference and rendezvouses with the trainer's
|
||||
# first-step broadcast (train.py), so inference serves the correct policy from step 1. Keeping
|
||||
# it unconditional makes trainer/orchestrator startup symmetric and avoids the resume deadlock
|
||||
# where inference waited for weights the trainer only sent at the end of a step.
|
||||
sync_version = self.resume_step if self.resume_step is not None else 0
|
||||
check_exists = config.weight_broadcast.type != "nccl"
|
||||
# Wait for the trainer's startup broadcast to land. On a fresh start there is no ckpt block,
|
||||
# so fall back to a default timeout instead of not waiting at all (which would raise before
|
||||
# broadcasts/step_0/STABLE is written when using filesystem weight broadcast).
|
||||
wait_timeout = config.ckpt.wait_for_weights_timeout if config.ckpt else STARTUP_WEIGHT_WAIT_TIMEOUT_S
|
||||
weights_path = get_weight_dir(
|
||||
config.output_dir, sync_version, check_exists=check_exists, wait_timeout=wait_timeout
|
||||
)
|
||||
await self.policy_inference.update_weights(weights_path, lora_name=self.lora_name, step=sync_version)
|
||||
if self.lora_name is not None:
|
||||
self.policy_inference.update_model_name(self.lora_name)
|
||||
self.policy.model_name = self.lora_name
|
||||
self.policy.version = sync_version
|
||||
|
||||
self.train_source = TrainSource(self.train_envs, seed=42)
|
||||
self.eval_source: EvalSource | None = (
|
||||
EvalSource(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import copy
|
||||
import time
|
||||
from typing import Callable
|
||||
|
||||
import torch
|
||||
@@ -12,7 +11,6 @@ from prime_rl.configs.trainer import OptimizerConfig
|
||||
from prime_rl.trainer.parallel_dims import ParallelDims
|
||||
from prime_rl.trainer.runs import get_multi_run_manager
|
||||
from prime_rl.trainer.sign_sgd import SignSGD
|
||||
from prime_rl.trainer.world import get_world
|
||||
from prime_rl.utils.logger import get_logger
|
||||
|
||||
|
||||
@@ -121,14 +119,7 @@ def setup_optimizer(
|
||||
# Wait for run 0 to be created in the multi run manager
|
||||
# Otherwise, the creation will reset the parameters
|
||||
multi_run_manager = get_multi_run_manager()
|
||||
world = get_world()
|
||||
logger = get_logger()
|
||||
while 0 not in multi_run_manager.idx_2_id:
|
||||
if world.is_master:
|
||||
multi_run_manager.discover_runs()
|
||||
multi_run_manager.synchronize_state()
|
||||
logger.info(f"Waiting for run 0 to be created {multi_run_manager.id_2_idx=}")
|
||||
time.sleep(1)
|
||||
multi_run_manager.wait_for_run(0)
|
||||
named_params = multi_run_manager.get_named_parameters_for_run(0)
|
||||
|
||||
optimizer = _create_optimizer(config, named_params, parallel_dims)
|
||||
|
||||
@@ -255,6 +255,7 @@ def train(config: TrainerConfig):
|
||||
logger.info(f"Tracing to {config.trace_path}")
|
||||
prof = profile(activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA], record_shapes=True).__enter__()
|
||||
maybe_record_function = record_function
|
||||
start_step = progress.step
|
||||
while True:
|
||||
# Reset peak memory stats
|
||||
torch.cuda.reset_peak_memory_stats()
|
||||
@@ -265,6 +266,18 @@ def train(config: TrainerConfig):
|
||||
logger.debug(f"Starting training step {progress.step}")
|
||||
step_start_time = time.perf_counter()
|
||||
|
||||
# Broadcast the incoming policy (v{progress.step-1}) before waiting for its rollouts. #2896
|
||||
# broadcasts at the END of a step, so the first step would otherwise block on rollouts the
|
||||
# inference engines cannot produce until they receive v{progress.step-1} (the orchestrator
|
||||
# pauses inference at startup to sync it). This happens whether resuming (v{checkpoint_step})
|
||||
# or starting fresh (v0), keeping trainer and orchestrator startup symmetric.
|
||||
if progress.step == start_step and weight_broadcast is not None:
|
||||
logger.info(f"Broadcasting startup policy weights (v{progress.step - 1}) to inference engines")
|
||||
multi_run_manager.wait_for_run(0)
|
||||
for idx in multi_run_manager.used_idxs:
|
||||
multi_run_manager.ready_to_update[idx] = True
|
||||
weight_broadcast.broadcast_weights(model, step=progress.step - 1)
|
||||
|
||||
# Wait for the batch to be available
|
||||
logger.debug("Waiting for training batch to arrive")
|
||||
wait_for_batch_start_time = time.perf_counter()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import pickle
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Callable, Optional
|
||||
@@ -463,6 +464,20 @@ class MultiRunManager:
|
||||
# Properties and Accessors
|
||||
# =========================================================================
|
||||
|
||||
def wait_for_run(self, idx: int = 0, poll_interval: float = 1.0) -> None:
|
||||
"""Block until run ``idx`` is registered. Master discovers from disk; all ranks synchronize.
|
||||
|
||||
Runs are otherwise only discovered during batch collection (``packer.discover_runs``), so
|
||||
callers that need a run before the first batch (optimizer setup, first-step weight sync)
|
||||
use this to populate ``idx_2_id``/``used_idxs``.
|
||||
"""
|
||||
while idx not in self.idx_2_id:
|
||||
if self.world.is_master:
|
||||
self.discover_runs()
|
||||
self.synchronize_state()
|
||||
self.logger.info(f"Waiting for run {idx} to be created ({self.id_2_idx=})")
|
||||
time.sleep(poll_interval)
|
||||
|
||||
@property
|
||||
def used_idxs(self):
|
||||
return sorted(self.idx_2_id.keys())
|
||||
|
||||
Reference in New Issue
Block a user