Fix TensorboardCallback logging for off-policy algorithms (DDPG/TD3/SAC)#1422
Open
jenish-25 wants to merge 1 commit into
Open
Conversation
…dCallback TensorboardCallback._on_rollout_end assumed the model always exposes a rollout_buffer (A2C/PPO). Off-policy algorithms (DDPG, TD3, SAC) use a replay_buffer instead, so the callback raised a KeyError every rollout, logged None reward stats, and printed noisy errors. Read whichever buffer the model exposes and compute reward min/mean/max over the valid (filled) region, so reward logging works for both on- and off-policy algorithms. Add unit tests covering both buffer types, the partially-filled replay buffer, and the no-buffer case. Fixes AI4Finance-Foundation#1395
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.
Summary
Fixes #1395.
TensorboardCallback._on_rollout_endassumed the model always exposes arollout_buffer, which only on-policy algorithms (A2C, PPO) have. Off-policy algorithms (DDPG, TD3, SAC) expose areplay_bufferinstead, so the callback raised aKeyErroron every rollout, fell into theexceptbranch, loggedNonefortrain/reward_min|mean|max, and printedLogging Error: ...noise. Reward curves were effectively broken for off-policy training.Fix
Read whichever buffer the model actually exposes and compute the reward statistics over the valid (filled) region:
This reads the buffer from
self.model(stable across SB3 versions) rather thanself.locals, so reward logging now works for both algorithm families. Theimport statisticsit replaced is removed.Tests
Added
unit_tests/test_tensorboard_callback.pycovering:rollout_buffer→ logs min/mean/maxreplay_buffer→ logs min/mean/max, noNoneleaks (the DDPG / off-policy algorithms fail due to rollout_buffer logging in FinRL 0.3.8 #1395 regression)All four pass;
blackis clean on the changed files.Note
This is a clean re-submission of the previously-closed #1404 (a maintainer asked for a fresh PR in that thread). The implementation reads the buffer off the model and adds the missing tests.
cc @bruceyang @spencerromo @xiaoyang