Skip to content

[logging] Publish the training loop phase as a Prometheus gauge#1923

Open
eicherseiji wants to merge 3 commits into
NovaSky-AI:mainfrom
eicherseiji:seiji/training-phase-gauge
Open

[logging] Publish the training loop phase as a Prometheus gauge#1923
eicherseiji wants to merge 3 commits into
NovaSky-AI:mainfrom
eicherseiji:seiji/training-phase-gauge

Conversation

@eicherseiji

@eicherseiji eicherseiji commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Publishes which macro-phase the fully async training loop is in as a Prometheus gauge. Today, joining "what was the loop doing" to "how busy were the GPUs" means hand-correlating the experiment tracker against Prometheus by wall-clock.

New metric:

  • skyrl_training_phase{phase=...}: 1.0 for the active phase, 0.0 for the rest. Phases match the loop's Timer() keys (wait_for_generation_buffer, convert_to_training_input, run_training, sync_weights, eval, save_checkpoints) plus the default generating, so the wandb timing/* keys and the Prometheus label share one vocabulary.

Ray exports it to the same Prometheus that scrapes node GPU metrics, so per-phase GPU utilization is a single-store query:

avg(ray_node_gpus_utilization) and on() (ray_skyrl_training_phase{phase="eval"} == 1)

Prometheus also survives a cluster restart, when the tracker may be unreachable.

How

New module skyrl/train/utils/phase_metrics.py with TrainingPhaseGauge, following the one-module-per-concern layout of ray_gpu_monitor.py. The trainer constructs it in __init__ and sets the phase at each existing Timer() boundary. Each transition writes only the two changed series; construction seeds all series so PromQL selectors never hit a missing one. Best-effort: it no-ops when Ray metrics are unavailable and warns on unknown phase names, so it never breaks training or tests.

Tests

  • tests/train/utils/test_phase_metrics.py (new): exactly one phase active, context-manager restore, unknown-phase rejection, no-op when Ray is unavailable. 5 passed.
  • ruff and black clean on changed files. End to end needs a GPU cluster.

Adds skyrl/train/utils/phase_metrics.py with TrainingPhaseGauge, which
sets a skyrl_training_phase gauge to 1.0 for the active macro-phase and
0.0 for the rest via ray.util.metrics. Ray exports it to the same
Prometheus that scrapes node GPU metrics, so phase windows join GPU
utilization on one wall-clock axis without correlating the experiment
tracker by hand. The async loop sets the phase at each existing Timer
boundary. Best-effort: the gauge silently no-ops when Ray metrics are
unavailable, so it never breaks training or tests.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a TrainingPhaseGauge to publish the training loop's current macro-phase (such as eval, training, weight synchronization, and checkpointing) to Prometheus via Ray metrics. This allows training loop phases to be overlaid with cluster-wide GPU utilization metrics. The feedback suggests validating phase names against the defined list of allowed phases to prevent developer typos and silent failures, along with adding a corresponding unit test for this validation.

Comment thread skyrl/train/utils/phase_metrics.py Outdated
Comment thread tests/train/utils/test_phase_metrics.py Outdated
- Emit only the two changed series per transition instead of sweeping
  all phases; the full sweep runs once at construction to seed every
  series for PromQL selectors.
- Warn and keep the current phase on an unknown phase name instead of
  silently zeroing everything.
- Rename phases to match their paired Timer keys so wandb timing/* keys
  and the Prometheus phase label share one vocabulary.
- Construct the gauge in __init__ behind trainer.enable_training_phase_gauge,
  matching the RayGpuMonitor lifecycle.
- Deduplicate docstrings and comments; add unknown-phase and
  disabled-by-flag tests.
The gauge writes two in-process values per phase transition with no thread or I/O, so there is nothing an operator needs to switch off. Construct it unconditionally; it already no-ops without Ray.
eicherseiji added a commit to eicherseiji/SkyRL that referenced this pull request Jul 18, 2026
ScalarGauges had no functional dependency on TrainingPhaseGauge; the
stack existed only because both classes shared phase_metrics.py. Move
ScalarGauges to its own module (scalar_gauges.py, one module per
concern) and revert the phase-gauge content from this branch's tree, so
this PR is independently mergeable and its diff is buffer-only. Forward
revert, no history rewrite; NovaSky-AI#1923 still owns the phase gauge.
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