fix(logging): make collector reward reporting timely - #1331
Merged
TATP-233 merged 2 commits intoAug 27, 2026
Merged
Conversation
Reward displays (tensorboard reward/mean and the terminal logger) lagged badly on off-policy and APPO runs: - collectors sent metrics only every num_envs * 10 env steps, so the reported reward changed just once per ~10 learner iterations; - runners then averaged the last 100 (off-policy) or 50 (APPO) reports, each already a rolling 100-episode mean, delaying the visible curve by ~1000 iterations. Report metrics every collector cycle, keep the runner-side window at the last 10 reports, and bound the per-worker episode reward/length buffers with deque(maxlen=100) instead of lists that grew for the whole run. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
TATP-233
changed the base branch from
main
to
dev/issue-1304-motion-numba-body-state
August 27, 2026 06:41
ManagerBasedRlEnv.reset() replaced state.info["log"] with the reset-only extras (Episode_Reward/*), wiping the fresh per-step reward/* entries that _update_state_in_read_phase() had just computed for the current transition. On any step where at least one env resets — with thousands of envs, nearly every step — collectors therefore saw no reward/* keys at all, so the per-term reward components in tensorboard and the terminal logger stayed frozen at one stale value for thousands of iterations (observed as long flat staircases on reward/motion_* etc.). Merge instead of replace on the autoreset path: the pre-reset per-step entries stay, reset extras layer on top. Standalone (non-autoreset) resets are unchanged. Co-Authored-By: Claude Fable 5 <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.
问题
FastSAC / TD3 / FlashSAC(共用 off-policy collector)与 APPO 训练中,tensorboard
reward/mean和终端 logger 的 reward 更新过慢。实测logs/fast_sac/G1MotionTrackingSAC(num_envs=2048, ~67k steps/s):reward/mean24994 个点中数值仅变化 2499 次(恰好 1/10)。两层滞后叠加:num_envs * 10步(10 个采集 cycle)才发一次 reward 消息,而 learner 每个 cycle 跑 1 次 iteration,reward 每 ~10 次 iteration 才变一次。deque(maxlen=100)(APPO 为最近 50/200 条)再平均,曲线滞后约 ~1000 次 iteration。ep_rewards/ep_lengths为无界 list,随训练时长持续增长。修复
deque(maxlen=100)有界滚动窗口(statistics.mean直接作用于窗口,语义不变)。double_buffer_runner、appo、hora appo):消息均值窗口缩短为最近 10 条上报——每条已是 100-episode 均值,10 条足以平滑且几乎无滞后。put_latest_metrics在 learner stall 时丢弃过期消息,提高频率无堆积风险。效果:reward 更新延迟从 ~1000 iteration 降到 ~10 个 cycle(上述 run 中约 0.3 秒),终端与 tensorboard 曲线及时反映当前策略表现。
Validation
make test-all通过(首次运行有 1 个 pre-existing 失败test_removed_legacy_env_packages_stay_removed,原因为工作区残留的空目录src/unilab/envs/{locomotion,manipulation,motion_tracking}(无文件、git 未跟踪)触发了 namespace package 检测;删除空目录后全量通过)。tests/algos/test_offpolicy_worker.py、test_appo_worker.py、test_appo_runner*.py、test_offpolicy_runner_unit.py、test_offpolicy_double_buffer_runner.py、test_offpolicy_logger.py等 150 项通过。🤖 Generated with Kimi Code