[LLM] WS4 Post-Training Observability: Implement PostTrainingLogger - #3950
[LLM] WS4 Post-Training Observability: Implement PostTrainingLogger#3950coder-jayp wants to merge 4 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3950
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 4a2d797 with merge base d7659c7 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
| Prefix | Label Applied | Example |
|---|---|---|
[Algorithm] |
new algo | [Algorithm] Add new RL objective |
[BE] |
BE | [BE] Improve error messages |
[Benchmark] or [Benchmarks] |
Benchmarks | [Benchmark] Add collector benchmark |
[BugFix] |
BugFix | [BugFix] Fix memory leak in collector |
[Example] or [Examples] |
Examples | [Example] Add training script |
[Feature] |
Feature | [Feature] Add new optimizer |
[Doc] or [Docs] |
Documentation | [Doc] Update installation guide |
[Refactor] |
Refactoring | [Refactor] Clean up module imports |
[CI] |
CI | [CI] Fix workflow permissions |
[Test] or [Tests] |
Tests | [Tests] Add unit tests for buffer |
[Trainer] or [Trainers] |
Trainers | [Trainer] Add trainer config |
[Environment] or [Environments] |
Environments | [Environments] Add Gymnasium support |
[Data] |
Data | [Data] Fix replay buffer sampling |
[LLM] |
llm/ | [LLM] Add reward model integration |
[Minor] |
small change | [Minor] Fix typo in error message |
[Performance] or [Perf] |
Performance | [Performance] Optimize tensor ops |
[BC-Breaking] |
bc breaking | [BC-Breaking] Remove deprecated API |
[Deprecation] |
Deprecation | [Deprecation] Mark old function |
[Algorithm] or [Algorithms] |
new algo | [Algorithm] Add new objective |
[Quality] |
Quality | [Quality] Fix typos and add codespell |
[Versioning] |
versioning | [Versioning] Bump release version |
[WIP] |
WIP | [WIP] Draft implementation |
Note: Common variations like singular/plural are supported (e.g., [Doc] or [Docs]).
|
@vmoens, I would appreciate your feedback on this when you have a moment. Thanks. |
|
Hi @theap06, any feedback on this PR? |
theap06
left a comment
There was a problem hiding this comment.
Sorry for the late reply! Left some comments.
|
|
||
| with torch.no_grad(): | ||
| try: | ||
| reward_list = batch.get(("next", "reward"), default=None, as_list=True) |
There was a problem hiding this comment.
This reads from batch, not replay_buffer[:]. Old code for these three metric families read the whole buffer. Should rename the keys or read from replay_buffer
| # _storage is private; max_size is a public plain attribute on Storage. | ||
| storage = replay_buffer._storage # noqa: SLF001 | ||
| if hasattr(storage, "max_size") and storage.max_size > 0: | ||
| metrics["buffer/utilization"] = ( |
There was a problem hiding this comment.
RayReplayBuffer never sets self._storage so it raises an AttributeError. also, the buffer/utilization never logs for grpo since both use the rayreplaybuffer
| ) | ||
| except Exception: # noqa: BLE001 | ||
| pass | ||
| legacy_metrics["reward from batch"] = float(batch["next", "reward"].mean()) |
There was a problem hiding this comment.
Only the rb_content block above this is guarded; the loss.loss_sft reads here aren't and nothing wraps the log_training_metrics either.
| @@ -919,91 +919,55 @@ def log_training_metrics( | |||
| ): | |||
There was a problem hiding this comment.
A few keys got renamed without any docstrings or deprecation warnings. ei_utils.py keeps everything alive via _LEGACY_KEY_MAP, worth doing the same here
| with torch.no_grad(): | ||
| optim_steps = global_step // gradient_accumulation_steps | ||
| legacy_metrics: dict[str, Any] = {} | ||
| try: |
There was a problem hiding this comment.
All 11 warnings are made every call. Instead, worth a module-level flag so it's not 11 warnings. Warn calls every logged step.
|
@theap06 Thanks for the detailed review. All points addressed. |
d8539b2 to
7bdfa15
Compare
…ce, GRPO deprecations, guard EI reads
…se-batch support Follow-ups to review, on top of the rebase onto main (which drops the objectives migration already merged as pytorch#3888): - Loss fields are discovered by iterating the TensorClass loss output instead of a hardcoded 11-name allowlist, so a new loss term is logged automatically. Plain objects still work via their attribute dict. - Metric-computation failures warn once per site at WARNING level instead of five blanket except-Exception blocks logging at debug: an observability component that silently emits nothing is worse than one that raises. - training/grad_norm is omitted on accumulation steps rather than logged as a literal 0.0, which polluted any aggregate over the series. - batch/reward_std is omitted for single-element batches (std would be NaN). - as_list=True returns a plain tensor for dense (padded) batches; all three read sites now handle both the ragged and the dense form. The dense form previously made every batch/* metric silently disappear. - Deprecations follow CLAUDE.md 12: the legacy GRPO keys are emitted again during the window (previously they were warned about but not emitted, and three keys plus two renames had no deprecation at all), the category is FutureWarning (DeprecationWarning is hidden by default), and the removal target is v0.16.0 (two minors after v0.14; version.txt is 0.13). - Runnable Examples block on the class docstring, verified by execution. test/test_loggers.py: 50 passed. test/objectives: 7491 passed post-rebase. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
7bdfa15 to
4a2d797
Compare
Description
This PR implements the Observability workstream (WS4) from RFC #3948. It introduces a modular
PostTrainingLoggerthat unifies metric emission across TorchRL's post-training algorithms, making the observability stack consumable by external training loops.Key Changes:
PostTrainingLogger: New backend-agnostic logger for tracking loss components, buffer utilization, and inference staleness. Usesgetattrduck-typing to safely ingest bothGRPOLossOutputandSFTLossOutput.DeprecationWarnings (targeted for removal inv0.15.0perCLAUDE.md).test_loggers.py.Motivation and Context
Solves the need for component-level interoperability in TorchRL's LLM stack. Users can now drop this logger into their own existing loops without migrating their entire workflow.
close #3948
Types of changes
Checklist