Skip to content

RL diagnostics: documents-seen clock, model-version broadcast, reward + per-token model_version, data-wait#553

Open
jlamypoirier wants to merge 4 commits into
mainfrom
jlp_rl_metrics
Open

RL diagnostics: documents-seen clock, model-version broadcast, reward + per-token model_version, data-wait#553
jlamypoirier wants to merge 4 commits into
mainfrom
jlp_rl_metrics

Conversation

@jlamypoirier

@jlamypoirier jlamypoirier commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Claude Opus 4.8, on behalf of @jlamypoirier.

Summary

Consolidates the remaining RL diagnostics on the Fast-LLM trainer side so the trainer is a single,
reliable source of truth for GSPO/GRPO runs — logged from the exact tensors each step trained on.

The config unification + GSPO/GRPO policy metrics landed separately in #555; this PR is rebased on
top of it
and adds the document clock, the version broadcast, the reward / per-token-version data, and
the data-wait timer. Paired PipelineRL changes (raw-reward forwarding + document-count model version)
live in a separate PR against PipelineRL's fast-llm branch. Backward-compatible with the current producer.

Changes

  • documents_seen / num_documents. Reimplemented on main, independent of docs_per_step, from
    the per-step DP-summed document count (the loss-normalization divisor). Persisted in checkpoint
    metadata. Offered as an alternative W&B x-axis via a lazily-declared define_metric (RL runs only;
    the global step is unchanged).
  • Document-count model version. weights_ready now carries document_count (= documents_seen)
    alongside the existing step, so consumers can measure staleness in documents (DeepSpeed-aligned).
    Keeping step makes this backward-compatible.
  • reward and per-token model_version. Two optional per-token fields threaded through the RL
    streaming schema and data pipeline (reusing TokenDataDocument/TokenDataBatch); both optional and
    guarded on presence. reward is the raw reward (distinct from the group-relative advantage). The
    shared policy-gradient loss logs mean/max/min of each when present (folded into the PolicyMetricsLevel
    metric set from Unify policy-loss metrics config and add GSPO metrics #555). Staleness is documents_seen − model_version, derivable from the logged stats.
  • data_wait_time_ms. The schedule runner already timed data-loader waits but discarded the value;
    it is now logged as an input-starvation metric.

Tests

  • The reward/version registration is checked against an independent plain-Python reference
    (test_policy_data_metrics), and the streaming schema round-trips the new fields (test_streaming_dataset).
  • Rebased onto Unify policy-loss metrics config and add GSPO metrics #555 (now in main); CI validates the full suite.

jlamypoirier added a commit that referenced this pull request Jul 8, 2026
Coarse review fixes for PR #553:
- Extract the shared GRPO/GSPO metric LossDef list into
  LanguageModelPolicyGradientLoss._policy_metric_definitions(*extra); GSPO
  passes its num_segments def. Removes ~13 duplicated lines, order-preserving.
- Add a GSPO-metrics subtest to _run_lm_loss_distributed so
  compute_gspo_metrics' vocab-parallel group all-reduce path is exercised.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jlamypoirier and others added 4 commits July 8, 2026 13:08
Reintroduce the per-step document count and cumulative documents-seen
metrics on the static-schedule path, independent of `docs_per_step`.

`ScheduleRunner` exposes the whole-step DP-summed document count
(`num_documents_in_batch`, the loss-normalization divisor) as
`_num_documents_in_batch`, set once per step in `_preprocess_data`; it is
`None` when the data carries no document counts (non-RL runs). The trainer
accumulates it into `_documents_seen` every step (persisted in checkpoint
metadata) and logs `num_documents` + `documents_seen` when available.

`Wandb` lazily declares `training/documents_seen` as an alternative
`step_metric` for `training/*` on the first log that carries it, so it can
be used as a cross-run x-axis without affecting non-RL runs. The global
`wandb.log(step=...)` step is unchanged, so both axes remain available.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The `weights_ready` event now carries `document_count` (= documents_seen)
alongside the existing `step` (= completed step). Consumers stamp
`document_count` onto rollouts so staleness is measured in documents,
aligning with DeepSpeed's document clock, while `step` remains available
for logging. Keeping `step` makes the change backward-compatible.

Threads `documents_seen` through the `TrainerCallback.run_begin` /
`step_end` hooks (a training-progress counter alongside `step`).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The schedule runner already timed how long it blocked on the data loader
but only warned past a threshold and discarded the value. Accumulate it
into the step metrics as `data_wait_time_ms` (0 when never starved), so
input starvation is visible in the training logs and W&B.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add two optional per-token fields to the RL streaming schema and thread
them through the data pipeline alongside `advantages` /
`old_log_probabilities` (reusing `TokenDataDocument`/`TokenDataBatch`):
- `reward`: the raw (un-normalized) reward, a per-rollout scalar broadcast
  per-token — distinct from the group-relative `advantage`.
- `model_version`: the model version each token was generated under
  (documents-seen units), one per token, for staleness diagnostics.

Both are optional (absent when the producer does not send them), so the
batch/target plumbing guards on presence.

The shared policy-gradient loss logs mean/max/min of each supplied field
when `metrics != none` (GRPO and GSPO), registered only when the data is
present. Staleness is `documents_seen - model_version`, derivable from the
logged version stats and `documents_seen`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jlamypoirier jlamypoirier changed the title RL diagnostic metrics: unified policy-loss metrics, GSPO metrics, documents-seen, reward/version, data-wait RL diagnostics: documents-seen clock, model-version broadcast, reward + per-token model_version, data-wait Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant