Repository navigation
[metrics] W&B: log each row with a trainer/step key, so later logs to a step are kept - #5903
Conversation
… a step are kept WandBLogger.log called wandb.log(metrics, step=N, commit=True). W&B drops any later log to a step it already sent, so validation logged at a step that training already logged never reached W&B. At the core defaults (log_freq=10, validator freq=10) that is every validation row; RL drops its final pass. Now every row carries the training step as "trainer/step", and rows log without step=, so W&B sends each one at once and keeps it. define_metric makes trainer/step the x-axis of the generated charts, and its summary the max. W&B's _step now counts rows: METRICS.md says how to rewind or fork by trainer/step, and what changes for saved panels and resumed run ids.
…p= rule once
summary="max" only adds a trainer/step.max summary key; summary["trainer/step"] still holds the
last row's value, so the comment that claimed otherwise was wrong. The plain
define_metric("trainer/step") matches the run that showed every row kept.
The reason rows log without step= now lives at the log call and in METRICS.md only.
|
Reply from claude: requesting a review of this draft. @claude please review |
There was a problem hiding this comment.
Verdict: Needs discussion -- the patch is correct and the smallest of the three open fixes for this bug (#5227, #5648, #5903). But it changes what W&B's Step means for every W&B user, and the maintainers have to choose one of the three PRs.
What this PR does. WandBLogger.log no longer passes step= to wandb.log. Instead it adds the training step to every row as a regular key, trainer/step, and __init__ uses define_metric to make trainer/step the x-axis for all metrics. So every call becomes its own row, sent right away, and W&B never sees a log to a step lower than the one it already has, which is when it drops rows.
Example. Core trainer at the defaults (log_freq=10, validator freq=10), step 10:
main: wandb.log({loss..}, step=10, commit=True) -> W&B internal step becomes 11
wandb.log({validation_metrics/loss..}, step=10, ...) -> 10 < 11, dropped
PR: wandb.log({loss.., trainer/step: 10}) -> _step=k
wandb.log({validation_metrics/loss.., trainer/step: 10}) -> _step=k+1, kept
I checked this on HEAD: Trainer.train logs training (trainer.py:494) and then validation (trainer.py:539 -> MetricsProcessor.log_validation, metrics.py:652) at the same step. So on main every core validation row is dropped at the defaults.
Must fix
- PR description: "Summary (human-written)" is empty. Also, the description mentions "an open RL-only draft", "an open PR", "the open issue", and "the RL periodic-validation PR" without numbers. Link them (#5648, #5227, the issue, the validation PR) so maintainers can compare.
- Overlapping PRs: #5227 (yours) and #5648 (vkuzo) edit the same
wandb.logline, so only one of the three can land. If maintainers pick this one, close #5227, and coordinate with vkuzo on #5648. #5648 uses the sametrainer/step+define_metricidea, but as an opt-instep_metricargument and only for RL. torchtitan/observability/METRICS.md:38-- the doc narrates history ("before this change"). Inline suggestion attached.
Questions
- For maintainers: are you OK with
_step/Stepcounting rows instead of training steps for all W&B users? That affects saved panels,WANDB_RESUME_FROM/WANDB_FORK_FROM(?_step=Nno longer means training step N), and duplicate rows when a run logs again under the same run id. The PR lists these costs honestly. In my view it is still the right trade: #5227 needs a newBaseLogger.commit()hook thattrainer.pyand torchft must call at the right time, and #5648 adds a knob and leaves core validation dropped. - The test-plan item "saved panel in a project with an older run" is still unchecked. Please run it before this leaves draft: it is the one user-visible cost not yet measured.
Details
- Gate: the problem is real on
main, and the fix is at the right layer (the W&B logger itself). There is no new config field and no new hook in core, and TensorBoard and MLflow are untouched. Net +10 lines of code plus 14 lines of docs. define_metric("trainer/step")followed bydefine_metric("*", step_metric="trainer/step"):"*"also matchestrainer/stepitself. That is the same shape as W&B's documenteddefine_metric("train/*", step_metric="train/step")example, and the PR's online read-back shows it works.- Within each series,
trainer/steponly goes up (training rows always; validation passes run one after another), so the lines draw correctly. Out-of-order rows only appear in the mixedtrainer/stepcolumn of the runs table, which the PR already lists as a cost. - The
tagprefix never touches thetrainer/stepkey. No in-repo caller passes a non-Nonetagtoday, so a taggedstepmetric can't collide with it. - No new test is needed. The updated RL assert covers the call shape, and asserting the
define_metricmock calls would just repeat mock calls (tests.md).
Not verified: how saved W&B panels show a mix of old runs (x-axis Step) and new runs (x-axis trainer/step).
|
Reply from claude: requesting a review of the updated draft. @claude please review |
There was a problem hiding this comment.
Verdict: Needs discussion -- the code has no new problems since the last review, and the METRICS.md history wording is fixed. Two decisions still belong to the maintainers: which of #5227 / #5648 / #5903 lands, and whether W&B's Step should count rows for every W&B user.
What changed since the last review (commits 8e34bc1, a45e04a, plus a merge of main). These touch only METRICS.md and wording. The metrics.py logic is the same: rows go out without step=, carry trainer/step, and define_metric("*", step_metric="trainer/step") runs once in __init__ (metrics.py:254-265).
Example. Core trainer at the defaults, step 10:
main: log({loss..}, step=10, commit=True) -> sent; W&B's step moves past 10
log({validation_metrics/loss..}, step=10) -> dropped
PR: log({loss.., trainer/step: 10}) -> _step=k
log({validation_metrics/loss.., trainer/step: 10}) -> _step=k+1, kept
Status of earlier must-fix items
- Description links: resolved. #5027, #5227, #5648 and #5228 are now numbered.
METRICS.mdnarrating history: resolved.METRICS.md:38now states only the current rule ("In saved panels, usetrainer/stepas the x-axis").- "Summary (human-written)": still empty. The author fills this in, not an agent, before the PR leaves draft.
- Overlap with #5227 and #5648: still open. All three edit the same
wandb.logline, so only one can land. If this one is picked, close #5227 and coordinate with vkuzo on #5648.
Questions
- For maintainers: is
_step/Stepcounting rows (not training steps) acceptable for all W&B users? The costs are in the description andMETRICS.md:37-44: saved panels,?_step=NinWANDB_RESUME_FROM/WANDB_FORK_FROM, and replayed steps appearing twice when a run logs again under the same id. I still think this is the right trade over #5227, which adds aBaseLogger.commit()call to core, and #5648, which is RL only and leaves core validation dropped. - Test-plan item "saved panel in a project with an older run" is still unchecked. It is the one user-visible cost no one has measured yet.
Details
WandBLogger.logis the onlywandb.log/define_metriccall in the repo, so no other callsite still passesstep=.- The
tagprefix applies only to metric keys.trainer/stepis never prefixed, and no in-repo caller passes a non-Nonetag. - The docstring example (
metrics.py:208-210) usesvalidation_loss, but the real key isvalidation_metrics/loss. That only matters for illustration and doesn't need a change. - No new test needed: the updated RL assert (
tests/rl/unit_tests/cpu/test_metrics.py:690) pins the call shape.
Not verified: how saved W&B panels display a mix of old runs (x-axis Step) and new runs (x-axis trainer/step).
felipemello1
left a comment
There was a problem hiding this comment.
this pr doesnt make any chanes to RL or the trainer. Do we need to?
Also, you ran wandb in main vs this pr. Please highlight the results in the pr.
|
Reply from claude: addressed the open review items at 7c5a54b:
@claude please review |
|
Claude finished @felipemello1's task in 1m 29s —— View job Needs discussion: the earlier bot items are resolved, but your own 02:20 comments on |
There was a problem hiding this comment.
Verdict: Needs discussion -- the code is still correct, and every item from the last bot review is resolved. Two of your own 02:20 inline comments are still open at HEAD. Maintainers still have to choose between this PR and #5648, and decide whether W&B's Step should count rows.
What this PR does. WandBLogger.log no longer passes step= to wandb.log. It adds the training step to each row as a trainer/step key, and define_metric makes trainer/step the x-axis of the charts. Each call becomes its own row, so a validation row logged after training at the same step is no longer dropped.
Example. Core trainer at the defaults, step 10:
main: log({loss..}, step=10, commit=True) -> sent
log({validation_metrics/loss..}, step=10) -> dropped
PR: log({loss.., trainer/step: 10}) -> _step=k
log({validation_metrics/loss.., trainer/step: 10}) -> _step=k+1, kept
Status of earlier items
- Human-written summary: resolved.
- #5227: resolved, now closed.
- How #5648 differs: resolved, explained in the body. #5648 (vkuzo) is still open and edits the same line, so a maintainer has to choose one PR.
Stepcounting rows: the body now cites W&B'swandb.logdocstring. The decision still belongs to the maintainers.- Docstring key: resolved (
validation_metrics/loss).
Must fix
torchtitan/observability/METRICS.md:33-45-- your comment (make it less verbose; does titan resume runs?) is still open. On resume: every launch, checkpoint resume included, creates a new W&B run, becauseWANDB_RUN_ID/WANDB_RESUME_FROM/WANDB_FORK_FROMare unset by default (metrics.py:243-249). So the duplicate-rows bullet can go. The inline comment has a 5-line suggestion.torchtitan/observability/metrics.py:263-264-- your comment (the wording reads like it describes the old behavior) is still open. The inline comment has a 2-line suggestion.
Answers to your 02:20 review
- "This PR doesn't change RL or the trainer. Do we need to?" No. Core (
MetricsProcessor) and RL recipes (torchtitan_recipes/rl/alphabet_sort.py) both log through thisWandBLogger.log, so fixing it here covers both. The only RL change needed is the updated assert intests/rl/unit_tests/cpu/test_metrics.py:690. Changing the trainer would be the #5227 approach, which is now closed. - "Highlight main vs this PR results." Done: the body now has the dapo_math table (validation rows: 2 here vs 1 on main). The two runs aren't the same length (10 vs 50 steps), but the dropped row (the final pass) is the same in both, so the comparison holds.
Not verified: what wandb.init(id=<existing id>) does without resume= in wandb 0.31; how saved panels show a mix of old (Step) and new (trainer/step) runs.
…the code relies on
|
Reply from claude: answers to the 02:20 review, at 7b9805a:
@claude please review |
|
Claude finished @felipemello1's task in 39s —— View job Needs discussion: everything from earlier reviews is resolved at 7b9805a and I found no new problems; maintainers still need to choose between this PR and #5648 and decide whether W&B's |
There was a problem hiding this comment.
Verdict: Needs discussion -- every author and bot item is now resolved at 7b9805a and I found no new problems. Two decisions are left for the maintainers: whether this PR or #5648 lands, and whether W&B's Step should count rows for every W&B user.
What this PR does. WandBLogger.log no longer passes step= to wandb.log. It adds the training step to each row as a trainer/step key, and define_metric("*", step_metric="trainer/step") makes that key the x-axis. Each call becomes its own row, so a validation row logged after training at the same step is no longer dropped.
Example. Core trainer at the defaults, step 10:
main: log({loss..}, step=10, commit=True) -> sent
log({validation_metrics/loss..}, step=10) -> dropped
PR: log({loss.., trainer/step: 10}) -> _step=k
log({validation_metrics/loss.., trainer/step: 10}) -> _step=k+1, kept
Status of earlier items
METRICS.md:33-37(you asked for it to be less verbose and to drop the resume note): resolved. It is now 5 lines. The replay bullet is gone, which is right, since every launch starts a new run unlessWANDB_RUN_IDis set. The?_step=Nclause stays, because_stepno longer means the training step.metrics.py:263-264comment (it read like the old behavior): resolved. It now states only what the code relies on.- "Does RL or the trainer need a change?": resolved, no.
WandBLoggeris the onlywandb.log/define_metriccall in the repo. CoreMetricsProcessorand every RL recipe (dapo_math,search_r1,verifiers_dapo_math,alphabet_sort) build it fromWandBLogger.Config(). The RL test goes throughMetricsProcessor.log->WandBLogger.log, so its updated assert pins the new call shape. - main-vs-PR results: resolved. The first Results block runs the same core debug recipe on both: 1 of 4 validation rows on main, 4 of 4 on this PR.
Questions
- For maintainers: #5648 (vkuzo, still open) edits the same
wandb.logline as an opt-in that only RL uses. Only one of the two can land. Please pick one, and decide whetherStepcounting rows (the costs are in the description andMETRICS.md) is acceptable for all W&B users.
Not verified: how saved W&B panels show a mix of runs from before this PR (no trainer/step key) and runs from after it.
Summary (human-written)
Previously I added "commit=True" to titan, because in coreweave i would see multiple steps and wouldnt see logging.
This damage pretraining, because log is called twice, and once you log a step, you connect log again for the same step.
This PR solves both problems in one way:
This automatically commits, and support multiple .log calls to the same step.
Agent details
TLDR: W&B drops every validation row logged at a step that training already logged. That is every core validation row at the default settings. Now each W&B row carries the training step as
trainer/stepand logs withoutstep=, so W&B keeps every row, in core training and RL alike. On the core debug model, main keeps 1 of 4 validation rows in W&B; this PR keeps 4 of 4.Problem
WandBLogger.logcallswandb.log(metrics, step=N, commit=True).Trainer.train).log_freq=10, validatorfreq=10), both log at the same steps, so every core validation row is dropped.Solution
trainer/step.step=, so W&B sends each one at once.commit=Trueis W&B's default whenstepis not given.define_metricmakestrainer/stepthe x-axis of the generated charts.trainer/step.Results
wandb.logcalls that pass nostep=, a CPU repro also measured rows landing in 7-18 s, and every row surviving a kill 20 s after the last log.Costs. W&B's
_step(Stepin the UI) now counts rows:Stepon its x-axis must switch totrainer/step. Runs from before this PR have notrainer/step, so a panel that mixes old and new runs needsStepfor the old ones. Not checked in the UI.WANDB_RESUME_FROMandWANDB_FORK_FROMtake<run>?_step=N. To rewind to training step S, look up the_stepof a row whosetrainer/stepis S (METRICS.mdshows how). A rewind also drops validation rows for older steps that were logged after that row.WANDB_RUN_IDto an existing run (torchtitan starts a new run on every launch): the run appends its rows, so replayed steps show twice. Before, W&B dropped them.trainer/stepcolumn shows the last row's step. After a validation row for an older step, that is not the newest step.You may ask:
step=, so core validation rows stay dropped (wandb silently drop validator log #5027). This PR changes the default for core and RL.commit=True? W&B then holds row N until step N + 1 logs. RL rows would land one RL step late (minutes), and a scancel or time limit would lose the last row.Stepcounts rows for every W&B user? It follows W&B's own guidance. Thewandb.logdocstring (wandb 0.31.0) says the step must always increase, that any metric can be the x-axis, and that it is often better to treat the W&B step like a timestamp than a training step.NOTE:
Test plan
tests/unit_tests/cpu: 1927 passed, 5 failed, 5 skipped, 3 xfailed, 1 error. Main fails the same 5 tests and errors on the same file on this host (aarch64 CPU: inductor's flex_attention lowering in the LoRA and Qwen3.5 mrope tests, and the quantization test's import).{"k": 1.0, "trainer/step": 3}(tests/rl/unit_tests/cpu/test_metrics.py).trainer/stepkey (checked on the 11-02 dapo run's rows), so a panel ontrainer/stephas no x value for them.RL Multi-GPU Unit Testsfailstest_bitwise_parity.py::TestBitwiseParityQwen35DebugVarlen::test_trainer_vs_vllm_prefill. Main9f70e5597fails the same test.