Skip to content

feat(telemetry): export rollout checkpoint metrics to Lens - #4730

Merged
terrykong merged 9 commits into
mainfrom
amahishi/feat-lens-runtime-diagnostics
Oct 27, 2026
Merged

terrykong merged 9 commits into
mainfrom
amahishi/feat-lens-runtime-diagnostics

Conversation

@macandro96

@macandro96 macandro96 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Export the rollout checkpoint measurements that Single Controller already logs to NeMo Lens / OpenTelemetry: completed save/restore phases and volumes, every periodic snapshot attempt (including skipped and failed ones), and one trace-only span per completed save.

Metrics. The logger tee recognizes timing/rollout_checkpoint and timing/rollout_recovery, records phase durations in rl.checkpoint.duration, and publishes snapshot row/group counts, reused/rerun sibling counts, and controller-sidecar bytes. It uses fixed operation/phase/category labels (declared as RL_CHECKPOINT_* constants), rejects invalid measurements, and adds no checkpoint or rollout IDs to metric labels. These metrics carry no goodput bucket: save phases nest inside total, so they must not be summed. Restore phases are disjoint and total_load_seconds keeps its existing meaning (their sum, excluding redispatch_schedule), not allocation-to-ready time.

Snapshot attempts. Completed saves alone cannot tell "snapshots never complete" apart from "telemetry is off". The tee also reads the controller's per-attempt rollout/checkpoint_outcome dict and exports rl.checkpoint.attempts (counter, labelled rl.checkpoint.outcome and rl.checkpoint.reason), rl.checkpoint.attempt_duration (histogram, by outcome), and rl.checkpoint.seconds_since_last_success (gauge; 0 on success, absent before the first one). Outcome and reason are decoded from the controller's one-hot flags and are fixed sets (3 outcomes, 8 reasons); an attempt that does not set exactly one of each is not counted. Skips are expected (a snapshot is only valid while the trainer is at a durable checkpoint step, so attempts after the next optimizer commit skip with missing_trainer_anchor); a climbing outcome=skipped with completed at zero is the signal that snapshots are not completing. The label lists are copied from rollout_checkpoint.py, which imports the GRPO stack, and a source-drift test keeps them equal.

Span. Each completed save also emits rl.sc.rollout_checkpoint.save, rebuilt from the logged timings rather than opened around the save, so the checkpoint path is untouched. It ends at telemetry/wall_time_seconds, starts total_save_seconds earlier, and carries the phase durations, volume counts, rl.checkpoint.snapshot_sequence and rl.iteration as attributes, so a slow save can be tied to its snapshot. It is gated by the checkpoint span group (in the default preset) but carries no rl.bucket: the snapshot pump runs beside training, so an overhead bucket would double-count wall clock in goodput. Phases are attributes, not child spans, because only their durations are logged. rl.iteration is set explicitly, as main's checkpoint_finalize_span does, so it names the step the snapshot is anchored to rather than whatever step is running when the pump fires. Like rl.checkpoint.finalize, the span is unbucketed because it overlaps training. Restore emits no span, since its phases run at different times in driver setup and in the controller. The span is emitted before metric registration, so a registry failure cannot suppress it.

TELEMETRY_WALL_TIME_METRIC moves to nemo_rl.telemetry.metrics (the tee reads it and must not import the logger); nemo_rl.utils.logger re-exports it, so existing imports are unchanged.

This PR does not change checkpoint execution or add runtime thread/event-loop instrumentation. The latter is reviewed independently in #4732. Both PRs target main and can land independently.

Issues

No separate issue; expose existing rollout checkpoint measurements through the existing Lens integration.

Usage

Enable telemetry and metric export using the existing configuration:

telemetry:
  enabled: true
  metrics_enabled: true

Configure the normal Lens/OTLP destination for the run. Read rl.checkpoint.duration by operation and phase, and use rl.checkpoint.rows, rl.checkpoint.groups, rl.checkpoint.siblings, and rl.checkpoint.sidecar_bytes for captured/restored volume. Watch rl.checkpoint.attempts by outcome and reason to see whether periodic snapshots are completing, and rl.checkpoint.seconds_since_last_success for how stale the newest one is. To find which save was slow, filter traces on rl.sc.rollout_checkpoint.save. These report finished operations and attempts; they are not an in-progress hang watchdog.

Validation

  • Merged with current main. Standalone tests/unit/telemetry on Python 3.13.14: 254 passed. tests/unit/utils/test_logger.py: 106 passed (covers the TELEMETRY_WALL_TIME_METRIC re-export). Run against main's pinned nemo-lens (4d045c0); the local container's older lens lacks span_attributes, which main now imports.
  • Coverage: save/restore metric mapping, operation separation, invalid/unknown-value filtering (including train_step / wall time), prefix isolation, no-op when not exporting for all three prefixes; save span timing, attributes, absence of rl.bucket, span-group gating, parenting to the current span, survival of a failed metric registration, and no span on restore; attempt outcomes counted by outcome/reason, staleness absent before the first success and 0 on success, malformed attempt dicts not counted.
  • New bidirectional drift test in test_source_drift.py follows every timing/rollout_* dict across single_controller.py and setup.py (including the restore dict carried from setup to the controller). Mutation-checked: an added unmapped restore key and a removed mapped key each fail it. A second drift test keeps the tee's attempt outcome/reason labels equal to the controller's Literal types (mutation-checked with an added reason). The span-docs drift guard now also covers spans emitted by nemo_rl/telemetry/metrics.py.
  • Pyrefly on metrics.py: 0 errors. Ruff lint/format clean on changed files.
  • Full repository/GPU validation remains for CI.

Before your PR is "Ready for review"

  • Read and followed contributor guidelines; commits are DCO signed off.
  • Added necessary tests.
  • Ran the relevant standalone unit tests locally; full functional tests remain for CI.
  • Updated observability documentation (metrics.md, span-groups.md).

@macandro96 macandro96 added the CI:L0 Run doctests and unit tests label Oct 14, 2026
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test e68e4bc

@copy-pr-bot

copy-pr-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Oct 14, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 14, 2026 21:31
@macandro96
macandro96 force-pushed the amahishi/feat-lens-runtime-diagnostics branch from e68e4bc to 14eed1b Compare October 14, 2026 21:50
@macandro96 macandro96 changed the title feat(telemetry): export checkpoint timings and async runtime diagnostics feat(telemetry): export rollout checkpoint metrics to Lens Oct 14, 2026
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 14eed1b

@macandro96
macandro96 requested review from rrs45 and saumishr October 15, 2026 17:21

@mehraakash mehraakash left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the tee of the completed rollout save/restore dicts into Lens. No bugs found: the mapping, scalar/finite/non-negative filtering, and early-return dispatch all check out against the controller sources, and the four new unit tests pass locally with nemo-lens installed.

10 inline comments: 4 should-fix (docs placement and a contradictory restore sentence, the conftest comment, the one-directional save-only drift test) and 6 nits (docstrings, constants for series/attribute names, per-family exception handler, two cheap test cases). The _FROZEN reset in conftest is correct and should stay; only its comment is off.

Generated by Claude Code

Comment thread docs/observability/metrics.md Resolved
Comment thread docs/observability/metrics.md Resolved
Comment thread docs/observability/metrics.md Resolved
Comment thread nemo_rl/telemetry/metrics.py Resolved
Comment thread nemo_rl/telemetry/metrics.py Resolved
Comment thread nemo_rl/telemetry/metrics.py Resolved
Comment thread nemo_rl/telemetry/metrics.py Resolved
Comment thread tests/unit/telemetry/conftest.py Resolved
Comment thread tests/unit/telemetry/test_metrics.py Resolved
Comment thread tests/unit/telemetry/test_metrics.py Resolved
Comment thread nemo_rl/telemetry/metrics.py Resolved
macandro96 and others added 2 commits October 15, 2026 17:49
Address review on the rollout checkpoint Lens export:
- Move the rl.checkpoint.* docs after the rollout recovery section,
  restore the page intro, list the phase/category label values, and
  scope "do not sum" to save phases (restore phases are disjoint).
- Declare RL_CHECKPOINT_* metric/attribute constants and derive
  registry keys with registry_key().
- Give the checkpoint family its own exception handler and a docstring.
- Replace the save-only drift test with a bidirectional one in
  test_source_drift.py that follows every timing/rollout_* dict,
  including the restore dict assembled across setup.py and the
  controller.
- Explain the vocabulary freeze reset in the telemetry conftest.

Also emit one trace-only rl.sc.rollout_checkpoint.save span per
completed save, rebuilt from the logged timings so the checkpoint path
is untouched. It is gated by the checkpoint span group but carries no
rl.bucket: the snapshot pump runs beside training, so an overhead bucket
would double-count wall clock in goodput. TELEMETRY_WALL_TIME_METRIC
moves to nemo_rl.telemetry.metrics and is re-exported by the logger.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
The save span needs only the tracer, but it sat behind
ensure_metric_group_registered(), so a lens without the metric registry
or a failed registration also dropped the trace. Emit it right after the
is_exporting check instead.

Add tests that the span survives a failed registration and that it
parents to the current span (the job span in the controller).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 1bbcad6

Comment thread nemo_rl/telemetry/metrics.py Resolved
macandro96 and others added 3 commits October 16, 2026 16:11
Only completed saves reached Lens, so a run whose periodic snapshots
were all skipped (e.g. missing_trainer_anchor once training moves past
each durable trainer checkpoint) emitted no rl.checkpoint.* at all, the
same output as telemetry being off.

Tee the controller's per-attempt rollout/checkpoint_outcome dict as
rl.checkpoint.attempts{outcome, reason}, rl.checkpoint.attempt_duration
{outcome} and rl.checkpoint.seconds_since_last_success. Outcome and
reason are decoded from the one-hot flags and are fixed sets; a dict
that does not set exactly one of each is not counted. The label lists
are copied from rollout_checkpoint.py, which imports the GRPO stack, and
a source-drift test keeps them equal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
main replaced the rl.step span attribute with RL_ITERATION_ATTR
(rl.iteration). Use it for the rollout save span, set explicitly as
checkpoint_finalize_span does, so the span carries the step the
snapshot is anchored to rather than an inherited iteration_scope value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
@macandro96
macandro96 requested a review from rrs45 October 16, 2026 23:27
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test ec5348f

@macandro96
macandro96 requested a review from terrykong October 20, 2026 17:12
macandro96 added a commit that referenced this pull request Oct 21, 2026
Base the integration on RL #4762 at 71d3b46. Preserve the integrated #4730 metrics and #4732 runtime diagnostics, the integration metric mappings, and Gym a2d8d9f0559faf14a05e8d4add2a00624c0dbcbd with ToolSimulationAgent recovery.

Standalone telemetry: 279 passed, 5 skipped. Real local Ray telemetry: 5 passed. Syntax, lint, imports and formatting pass. Production-container prefix CPU tests are pending in Slurm job 1356058; GPU save/restore validation remains outstanding.

Signed-off-by: Anish Mahishi <[email protected]>

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exports the Single-Controller rollout-checkpoint numbers already logged to W&B into Lens/OTel, plus one span per completed save.

Good shape: labels stay bounded (sequence, step and wall time only ride the span), each family has its own warn_once, and the tee decodes the controller's dicts correctly; the 58 telemetry tests pass locally.

All 12 earlier threads (mehraakash, rrs45) are addressed at ec5348f. Nothing blocks the merge; every comment is a suggestion.

  1. (C1) Most important: the tee re-types the controller's attempt keys and Literals; share them through metric_utils.py.
  2. (C10) metrics.md copies names and keys the code declares; point at the code across the file. This reverses the earlier ask for the 23-row table.
  3. (C12) Shorten the PR's long code comments to what the code can't show.
  4. (C11) The staleness gauge can't drive an alert; fix two doc lines and show one that works.
  5. (C3) Same fix for the gauge's help text.
  6. (C4) Delete the duplicate _FROZEN reset in conftest.py.
  7. (C5) Share the wall-time key and "train_step" through vocabulary.py.
  8. (C6) The drift test misses .update(...) keys.
  9. (C7) The rl.iteration comment gives the wrong reason.
  10. (C8) On v2 the actor, not the driver, emits most series.
  11. (C9) Document how to get useful percentiles from the 5 s default buckets.

Generated by Claude Code

Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-4730-checkpoint-to-lens.html

Comment thread nemo_rl/telemetry/metrics.py Resolved
Comment thread nemo_rl/telemetry/metrics.py Resolved
Comment thread tests/unit/telemetry/conftest.py Resolved
Comment thread nemo_rl/telemetry/metrics.py Resolved
Comment thread docs/observability/metrics.md Resolved
Comment thread docs/observability/metrics.md Resolved
Comment thread docs/observability/metrics.md Resolved
Comment thread docs/observability/metrics.md Resolved
Comment thread nemo_rl/telemetry/metrics.py Resolved
Address review on the rollout checkpoint Lens export:
- Share the snapshot-attempt prefix, value keys, reason-key helper and
  outcome/reason Literals through nemo_rl/algorithms/metric_utils.py, so
  the controller and the tee read one definition; drop the tee's copies
  and the Literal drift test.
- Share TELEMETRY_WALL_TIME_METRIC and TELEMETRY_TRAIN_STEP_KEY through
  nemo_rl/telemetry/vocabulary.py instead of a logger re-export.
- Teach the restore-key drift collector .update(...) and |=.
- Remove the duplicate vocabulary _FROZEN reset main already performs.
- Correct the staleness gauge help text and the rl.iteration comment.
- metrics.md: point at the declaring code instead of copying tables,
  say which process emits what on v1 vs v2, document the default
  histogram buckets and the exponential-histogram env var, and warn
  that the staleness gauge cannot drive an alert (with one that can).
- Shorten comments that restated docs or design history.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
@macandro96 macandro96 added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L0 Run doctests and unit tests labels Oct 25, 2026
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 7e993bc

macandro96 and others added 2 commits October 25, 2026 18:13
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Anish Mahishi <[email protected]>
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 216c77b

@macandro96
macandro96 requested a review from terrykong October 26, 2026 02:03
@terrykong
terrykong enabled auto-merge (squash) October 27, 2026 05:34
@terrykong
terrykong merged commit ac94db3 into main Oct 27, 2026
95 checks passed
@terrykong
terrykong deleted the amahishi/feat-lens-runtime-diagnostics branch October 27, 2026 05:35
macandro96 added a commit that referenced this pull request Oct 28, 2026
Main's Lens export (#4730) sends each rollout save and restore metric through
a fixed mapping, and a drift test fails when the controller logs a key the
mapping does not name. Turn-level recovery logs four such keys: how long Gym
held rollout dispatch for a save, the episodes that save could not capture,
and the siblings a restore continued or restarted.

gym_parked_seconds becomes a save duration phase, gym_parked. The other three
are sibling counts, beside the reused and rerun siblings a restore already
reports: continued, restarted and gym_restarted.

Signed-off-by: Anish Mahishi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
macandro96 added a commit that referenced this pull request Oct 28, 2026
Main's Lens export (#4730) sends each rollout save and restore metric through
a fixed mapping, and a drift test fails when the controller logs a key the
mapping does not name. Turn-level recovery logs four such keys: how long Gym
held rollout dispatch for a save, the episodes that save could not capture,
and the siblings a restore continued or restarted.

gym_parked_seconds becomes a save duration phase, gym_parked. The other three
are sibling counts, beside the reused and rerun siblings a restore already
reports: continued, restarted and gym_restarted.

Signed-off-by: Anish Mahishi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
macandro96 added a commit that referenced this pull request Oct 31, 2026
Main's Lens export (#4730) sends each rollout save and restore metric through
a fixed mapping, and a drift test fails when the controller logs a key the
mapping does not name. Turn-level recovery logs four such keys: how long Gym
held rollout dispatch for a save, the episodes that save could not capture,
and the siblings a restore continued or restarted.

gym_parked_seconds becomes a save duration phase, gym_parked. The other three
are sibling counts, beside the reused and rerun siblings a restore already
reports: continued, restarted and gym_restarted.

Signed-off-by: Anish Mahishi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
macandro96 added a commit that referenced this pull request Oct 31, 2026
Main's Lens export (#4730) sends each rollout save and restore metric through
a fixed mapping, and a drift test fails when the controller logs a key the
mapping does not name. Turn-level recovery logs four such keys: how long Gym
held rollout dispatch for a save, the episodes that save could not capture,
and the siblings a restore continued or restarted.

gym_parked_seconds becomes a save duration phase, gym_parked. The other three
are sibling counts, beside the reused and rerun siblings a restore already
reports: continued, restarted and gym_restarted.

Signed-off-by: Anish Mahishi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
macandro96 added a commit that referenced this pull request Oct 31, 2026
Main's Lens export (#4730) sends each rollout save and restore metric through
a fixed mapping, and a drift test fails when the controller logs a key the
mapping does not name. Turn-level recovery logs four such keys: how long Gym
held rollout dispatch for a save, the episodes that save could not capture,
and the siblings a restore continued or restarted.

gym_parked_seconds becomes a save duration phase, gym_parked. The other three
are sibling counts, beside the reused and rerun siblings a restore already
reports: continued, restarted and gym_restarted.

Signed-off-by: Anish Mahishi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
macandro96 added a commit that referenced this pull request Nov 2, 2026
Main's Lens export (#4730) sends each rollout save and restore metric through
a fixed mapping, and a drift test fails when the controller logs a key the
mapping does not name. Turn-level recovery logs four such keys: how long Gym
held rollout dispatch for a save, the episodes that save could not capture,
and the siblings a restore continued or restarted.

gym_parked_seconds becomes a save duration phase, gym_parked. The other three
are sibling counts, beside the reused and rerun siblings a restore already
reports: continued, restarted and gym_restarted.

Signed-off-by: Anish Mahishi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants