Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1bbbf9231 | ||
|
|
f399e2664c |
+3
-1
@@ -2,6 +2,8 @@
|
||||
|
||||
Documenting changes which affect configuration usage patterns (added/moved/removed/renamed fields, notable logic changes).
|
||||
|
||||
- **`orchestrator.advantage.length_weighted_mean`**: Removed. The default advantage now always uses the plain per-problem mean baseline unless `orchestrator.advantage.length_shaping_alpha` is set. Existing configs must delete this field. (2026-03-19)
|
||||
- **`orchestrator.advantage.length_shaping_alpha`**: Added Group Relative Reward Rescaling coefficient to the default advantage config. When set, applies length-based GR3 shaping during advantage computation and requires `orchestrator.buffer.online_difficulty_filtering = true` (default: `None`) (2026-03-18)
|
||||
- **`prime_monitor.log_extras.sample_ratio`**: Added ratio-based rollout sampling (0.0–1.0, default: None). When set, caps the number of rollouts logged per step to `len(rollouts) * sample_ratio`. `None` preserves current behavior (log all rollouts). Interacts with existing `interval` gate which still runs first. (2026-03-12)
|
||||
- **`client.connect_timeout`**: Added configurable TCP connect timeout for inference API requests (default: 30.0s). Previously hardcoded to 5.0s. Helps with vLLM or cluster flakiness (2026-03-11)
|
||||
- **`model.fused_lm_head_token_chunk_size`**: Added as the fused LM-head chunking field for the token-chunked implementation. Unlike the removed `model.fused_lm_head_chunk_size`, this chunks over flattened sequence tokens rather than vocabulary rows. `model.fused_lm_head_chunk_size` is no longer accepted; switch configs to `model.fused_lm_head_token_chunk_size` explicitly. (2026-03-09)
|
||||
@@ -107,4 +109,4 @@ Documenting changes which affect configuration usage patterns (added/moved/remov
|
||||
- **`trainer.loss` (default loss)**: Made IPO (DPPO-Binary TV variant ([arxiv](https://arxiv.org/pdf/2602.04879)) + Kimi-K2.5 KL ([Kimi-K2.5](https://arxiv.org/pdf/2602.02276))) the default loss. Removed `ratio_type`, `token_mask_low`, `token_mask_high`, `sequence_clip_high`, `geo_mask_low`, `geo_mask_high`, `sequence_mask_low`, `sequence_mask_high`. Added `ipo_mask_low` (default: 0.2) and `ipo_mask_high` (default: 0.2) for token-level probability-difference masking. Changed `kl_tau` default from `0.0` to `1e-3`. (2026-03-02)
|
||||
- **Metrics logging overhaul**: All orchestrator metrics now follow a `{metric}/{scope}/{stat}` naming convention where scope is `all` (global) or an env name. Per-env breakdowns are always logged (previously only when >1 env). Key renames: `reward/mean` → `reward/all/mean`, `batch/solve_none` → `solve_none/all`, `val_reward/` → `val/reward/`, `metrics/{name}` → `metrics/{env}/{name}`, `stop_condition/{sc}` → `stop_condition/all/{sc}`, `error/mean` → `error/all/mean`. New per-env metrics: `solve_none/{env}`, `solve_all/{env}`, `effective_batch_size/{env}`, `stop_condition/{env}/generation_truncated`, `stop_condition/{env}/{sc}`, `error/{env}/mean`, plus per-env breakdowns for `seq_len`, `prefill_len`, `decode_len`, `is_truncated`, `samples_per_rollout`, `num_turns`, `generation_ms`, `scoring_ms`. Removed: `reward/std`, `reward/median`, per-error-type breakdown (`error/{error_type}`). Env name `"all"` is reserved and rejected at config validation. Env name validation now strips `@version` suffixes to match runtime behavior (e.g. `math@1.0` and `math@2.0` correctly detected as duplicates). Solve stats now use `example_id` grouping instead of index arithmetic (pre-existing bug fix). (2026-03-08)
|
||||
- **`wandb.shared`** (experimental): Added shared W&B mode that logs trainer and orchestrator metrics to a single W&B run instead of two separate runs. Uses `wandb.Settings(mode="shared")` (requires wandb SDK >= 0.19.9). Enabled by default on the RL entrypoint. Disable with `--wandb.shared False`. Run ID is communicated via `WANDB_SHARED_RUN_ID` env var; process role via `WANDB_SHARED_LABEL`. Non-primary processes retry `wandb.init` up to 30 times waiting for the primary to create the run. Works with multi-node SLURM. (2026-03-18)
|
||||
- **`wandb.id`**: Removed from `WandbConfig`. Run IDs are now managed internally via env vars for shared mode. (2026-03-18)
|
||||
- **`wandb.id`**: Removed from `WandbConfig`. Run IDs are now managed internally via env vars for shared mode. (2026-03-18)
|
||||
|
||||
@@ -551,7 +551,10 @@ class DefaultAdvantageConfig(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
type: Literal["default"] = "default"
|
||||
length_weighted_mean: bool = False
|
||||
length_shaping_alpha: Annotated[
|
||||
float | None,
|
||||
Field(description="Penalty coefficient for Group Relative Reward Rescaling (GR³). Recommended value: 0.33"),
|
||||
] = None
|
||||
|
||||
|
||||
class CustomAdvantageConfig(BaseModel):
|
||||
@@ -945,6 +948,13 @@ class OrchestratorConfig(BaseConfig):
|
||||
)
|
||||
return self
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_length_shaping_requires_online_difficulty_filtering(self):
|
||||
if isinstance(self.advantage, DefaultAdvantageConfig) and self.advantage.length_shaping_alpha is not None:
|
||||
if not self.buffer.online_difficulty_filtering:
|
||||
raise ValueError("Group Relative Reward (GR³) scaling requires online difficulty filtering")
|
||||
return self
|
||||
|
||||
@model_validator(mode="after")
|
||||
def auto_setup_bench(self):
|
||||
if self.bench:
|
||||
|
||||
@@ -474,6 +474,13 @@ class CheckpointConfig(BaseConfig):
|
||||
|
||||
weights: WeightCheckpointConfig | None = WeightCheckpointConfig()
|
||||
|
||||
weights_only: Annotated[
|
||||
bool,
|
||||
Field(
|
||||
description="When true, only save weight checkpoints (no optimizer/scheduler state). Much faster and smaller than full checkpoints, but cannot resume training.",
|
||||
),
|
||||
] = False
|
||||
|
||||
resume_step: Annotated[
|
||||
int | None,
|
||||
Field(
|
||||
|
||||
@@ -33,16 +33,21 @@ Expected signature:
|
||||
"""
|
||||
|
||||
|
||||
def default_advantage_fn(inputs: AdvantageInputs, length_weighted_mean: bool = False) -> AdvantageOutputs:
|
||||
def default_advantage_fn(
|
||||
inputs: AdvantageInputs,
|
||||
length_shaping_alpha: float | None = None,
|
||||
) -> AdvantageOutputs:
|
||||
"""Default GRPO advantage: reward minus per-problem baseline."""
|
||||
if length_weighted_mean:
|
||||
baseline = (inputs.rewards * inputs.completion_lengths).sum(
|
||||
dim=1, keepdim=True
|
||||
) / inputs.completion_lengths.sum(dim=1, keepdim=True)
|
||||
else:
|
||||
baseline = inputs.rewards.mean(dim=1, keepdim=True)
|
||||
rewards = inputs.rewards
|
||||
|
||||
return AdvantageOutputs(advantages=inputs.rewards - baseline)
|
||||
if length_shaping_alpha is not None:
|
||||
completion_lengths = inputs.completion_lengths.to(dtype=rewards.dtype)
|
||||
lengths_normalized = completion_lengths / completion_lengths.mean(dim=1, keepdim=True)
|
||||
length_shaping = (1 + length_shaping_alpha * lengths_normalized) ** -1
|
||||
rewards = rewards * length_shaping
|
||||
baseline = rewards.mean(dim=1, keepdim=True)
|
||||
|
||||
return AdvantageOutputs(advantages=rewards - baseline)
|
||||
|
||||
|
||||
def setup_advantage_fn(config: AdvantageConfig) -> AdvantageFn:
|
||||
@@ -57,7 +62,10 @@ def setup_advantage_fn(config: AdvantageConfig) -> AdvantageFn:
|
||||
return advantage_fn
|
||||
|
||||
def advantage_fn(inputs: AdvantageInputs) -> AdvantageOutputs:
|
||||
return default_advantage_fn(inputs, length_weighted_mean=config.length_weighted_mean)
|
||||
return default_advantage_fn(
|
||||
inputs,
|
||||
length_shaping_alpha=config.length_shaping_alpha,
|
||||
)
|
||||
|
||||
return advantage_fn
|
||||
|
||||
|
||||
@@ -247,21 +247,23 @@ def train(config: TrainerConfig):
|
||||
and not (is_first_step or is_last_step)
|
||||
and progress.step % config.ckpt.interval == 0
|
||||
):
|
||||
# Single-run: Save full checkpoint
|
||||
logger.info(f"Saving checkpoint at step {progress.step}")
|
||||
save_ckpt_start_time = time.perf_counter()
|
||||
ckpt_manager.save(progress.step, model, [optimizer], scheduler, progress)
|
||||
save_ckpt_time = time.perf_counter() - save_ckpt_start_time
|
||||
save_ckpt_time = 0
|
||||
|
||||
if not config.ckpt.weights_only:
|
||||
# Single-run: Save full checkpoint
|
||||
logger.info(f"Saving checkpoint at step {progress.step}")
|
||||
save_ckpt_start_time = time.perf_counter()
|
||||
ckpt_manager.save(progress.step, model, [optimizer], scheduler, progress)
|
||||
save_ckpt_time += time.perf_counter() - save_ckpt_start_time
|
||||
|
||||
# Maybe clean up old checkpoints
|
||||
ckpt_manager.maybe_clean()
|
||||
|
||||
# Save weight checkpoint
|
||||
if weight_ckpt_manager is not None:
|
||||
logger.info(f"Saving weight checkpoint at step {progress.step}")
|
||||
save_ckpt_start_time = time.perf_counter()
|
||||
weight_ckpt_manager.save(progress.step, model, tokenizer)
|
||||
|
||||
# Maybe clean up old weight checkpoint
|
||||
save_ckpt_time += time.perf_counter() - save_ckpt_start_time
|
||||
weight_ckpt_manager.maybe_clean()
|
||||
elif config.max_concurrent_runs > 1:
|
||||
# Multi-run: Save per-run checkpoints (each run has its own interval from orchestrator config)
|
||||
@@ -611,8 +613,9 @@ def train(config: TrainerConfig):
|
||||
|
||||
# Write final checkpoint (only for single-run mode; multi-run checkpoints are managed by MultiCheckpointManager)
|
||||
if config.max_concurrent_runs == 1 and ckpt_manager is not None:
|
||||
logger.info("Writing final checkpoint")
|
||||
ckpt_manager.save(progress.step, model, [optimizer], scheduler, progress)
|
||||
if not (config.ckpt and config.ckpt.weights_only):
|
||||
logger.info("Writing final checkpoint")
|
||||
ckpt_manager.save(progress.step, model, [optimizer], scheduler, progress)
|
||||
ckpt_manager.maybe_clean()
|
||||
|
||||
if config.max_concurrent_runs == 1 and weight_ckpt_manager is not None:
|
||||
|
||||
@@ -276,20 +276,23 @@ def train(config: SFTConfig):
|
||||
and not (is_first_step or is_last_step)
|
||||
and progress.step % config.ckpt.interval == 0
|
||||
):
|
||||
# Save full checkpoint
|
||||
logger.info(f"Saving checkpoint at step {progress.step}")
|
||||
save_ckpt_start_time = time.perf_counter()
|
||||
ckpt_manager.save(progress.step, model, [optimizer], scheduler, progress, dataloader=dataloader)
|
||||
save_ckpt_time = time.perf_counter() - save_ckpt_start_time
|
||||
save_ckpt_time = 0
|
||||
|
||||
if not config.ckpt.weights_only:
|
||||
# Save full checkpoint
|
||||
logger.info(f"Saving checkpoint at step {progress.step}")
|
||||
save_ckpt_start_time = time.perf_counter()
|
||||
ckpt_manager.save(progress.step, model, [optimizer], scheduler, progress, dataloader=dataloader)
|
||||
save_ckpt_time += time.perf_counter() - save_ckpt_start_time
|
||||
|
||||
# Maybe clean up old checkpoints
|
||||
ckpt_manager.maybe_clean()
|
||||
|
||||
# Save weight checkpoint
|
||||
if weight_ckpt_manager is not None:
|
||||
logger.info(f"Saving weight checkpoint at step {progress.step}")
|
||||
save_ckpt_start_time = time.perf_counter()
|
||||
weight_ckpt_manager.save(progress.step, model, tokenizer)
|
||||
# Maybe clean up old weight checkpoint
|
||||
save_ckpt_time += time.perf_counter() - save_ckpt_start_time
|
||||
weight_ckpt_manager.maybe_clean()
|
||||
else:
|
||||
save_ckpt_time = 0
|
||||
@@ -494,8 +497,9 @@ def train(config: SFTConfig):
|
||||
|
||||
# Write final checkpoint
|
||||
if ckpt_manager is not None:
|
||||
logger.info("Writing final checkpoint")
|
||||
ckpt_manager.save(progress.step, model, [optimizer], scheduler, progress, dataloader=dataloader)
|
||||
if not (config.ckpt and config.ckpt.weights_only):
|
||||
logger.info("Writing final checkpoint")
|
||||
ckpt_manager.save(progress.step, model, [optimizer], scheduler, progress, dataloader=dataloader)
|
||||
ckpt_manager.maybe_clean()
|
||||
|
||||
# Write final weight checkpoint
|
||||
|
||||
@@ -15,24 +15,24 @@ def test_default_advantage_fn_simple_mean():
|
||||
rewards=torch.tensor([[1.0, 0.5, 0.8], [0.2, 0.9, 0.1]]),
|
||||
completion_lengths=torch.tensor([[10, 12, 8], [15, 11, 9]]),
|
||||
)
|
||||
result = default_advantage_fn(inputs, length_weighted_mean=False)
|
||||
result = default_advantage_fn(inputs)
|
||||
|
||||
assert result.advantages.shape == (2, 3)
|
||||
# Check that mean is subtracted per row
|
||||
assert torch.allclose(result.advantages.mean(dim=1), torch.zeros(2), atol=1e-6)
|
||||
|
||||
|
||||
def test_default_advantage_fn_length_weighted():
|
||||
def test_default_advantage_fn_gr3_length_shaping():
|
||||
inputs = AdvantageInputs(
|
||||
rewards=torch.tensor([[1.0, 0.5, 0.8]]),
|
||||
completion_lengths=torch.tensor([[10, 20, 10]]),
|
||||
)
|
||||
result = default_advantage_fn(inputs, length_weighted_mean=True)
|
||||
|
||||
# Length-weighted mean: (1.0*10 + 0.5*20 + 0.8*10) / (10+20+10) = 28/40 = 0.7
|
||||
expected_baseline = 0.7
|
||||
expected = torch.tensor([[1.0 - expected_baseline, 0.5 - expected_baseline, 0.8 - expected_baseline]])
|
||||
result = default_advantage_fn(inputs, length_shaping_alpha=0.33)
|
||||
|
||||
expected = torch.tensor([[0.20915856, -0.25799648, 0.04883792]])
|
||||
assert torch.allclose(result.advantages, expected, atol=1e-6)
|
||||
assert torch.allclose(result.advantages.mean(dim=1), torch.zeros(1), atol=1e-6)
|
||||
|
||||
|
||||
def test_compute_advantages_with_config():
|
||||
|
||||
Reference in New Issue
Block a user