Log weight-sync time as a streaming-trainer metric#560
Merged
Conversation
The streaming callback broadcasts the full model to the inference actor on every successful step, synchronously inside the training loop, but nothing measured how long it took. Time it and log `weight_sync_time_ms` so the share of step time spent shipping weights is visible in the training logs and W&B. Timing uses CUDA events read one step later, so the always-on timer adds no CPU sync on the broadcast (which otherwise overlaps the next step's compute); the CPU/gloo broadcast path falls back to a plain wall-clock measurement. Callbacks may now return a metrics dict from `step_end`, merged into the step's training metrics. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…tention Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The streaming trainer callback broadcasts the full model to the inference actor on every successful step — synchronously, inside the training loop (so it's part of
step_time_ms) — but nothing measured how long that takes. This logs it asweight_sync_time_ms, so the share of step time spent shipping weights is visible in the training logs and W&B.Part of the RL-diagnostics initiative (making the Fast-LLM trainer the single source of truth for RL metrics); shipped as an independent PR since it's self-contained and touches no wire schema.
How
iter_checkpointZeRO-gather + NCCL push) with CUDA events on the broadcasting rank. The result is read one step later (_weight_sync_pending+Event.query()), so the always-on timer never forces a CPU stall — the broadcast otherwise overlaps the next step's compute, and readingelapsed_timeimmediately would serialize them.broadcast()runs withasync_op=False(work.wait()), so the current stream is ordered after the transfer and theendevent captures true completion. The CPU/gloo broadcast path (non-NCCL) falls back to a plainperf_countermeasurement, which needs no deferral.TrainerCallback.step_endmay now return adict[str, Any] | Noneof scalar metrics; the trainer merges any returned dicts into the step's training metrics alongside**train_metrics. Base callback returnsNone.Cost
Zero on the disabled path (non-streaming runs never construct the callback). On the streaming path: two reusable CUDA events and one deferred
elapsed_timeread per logging step — negligible against a full-model gather+broadcast, and no added GPU sync.Testing
No unit test: the path requires a live Redis + external-world rendezvous + CUDA, there's no streaming-callback test harness, and the only logic is the CUDA-event deferral state machine. Verified imports + black locally; the metric is validated on a live streaming RL run (the new key appears under
training/*).🤖 Generated with Claude Code