Skip to content

fix(logging): make collector reward reporting timely - #1331

Merged
TATP-233 merged 2 commits into
dev/issue-1304-motion-numba-body-statefrom
fix/offpolicy-reward-log-cadence
Aug 27, 2026
Merged

fix(logging): make collector reward reporting timely#1331
TATP-233 merged 2 commits into
dev/issue-1304-motion-numba-body-statefrom
fix/offpolicy-reward-log-cadence

Conversation

@TATP-233

Copy link
Copy Markdown
Collaborator

问题

FastSAC / TD3 / FlashSAC(共用 off-policy collector)与 APPO 训练中,tensorboard reward/mean 和终端 logger 的 reward 更新过慢。实测 logs/fast_sac/G1MotionTrackingSAC(num_envs=2048, ~67k steps/s):reward/mean 24994 个点中数值仅变化 2499 次(恰好 1/10)。两层滞后叠加:

  1. Collector 上报频率低:每 num_envs * 10 步(10 个采集 cycle)才发一次 reward 消息,而 learner 每个 cycle 跑 1 次 iteration,reward 每 ~10 次 iteration 才变一次。
  2. Runner 端双重平均:每条消息本身已是"最近 100 episode 均值",runner 又把它放进 deque(maxlen=100)(APPO 为最近 50/200 条)再平均,曲线滞后约 ~1000 次 iteration。
  3. 附带问题:collector 的 ep_rewards / ep_lengths 为无界 list,随训练时长持续增长。

修复

  • collector(offpolicy / appo / hora appo 三个 worker):每个采集 cycle 上报一次 metrics;episode reward/length 窗口改为 deque(maxlen=100) 有界滚动窗口(statistics.mean 直接作用于窗口,语义不变)。
  • runner(offpolicy double_buffer_runner、appo、hora appo):消息均值窗口缩短为最近 10 条上报——每条已是 100-episode 均值,10 条足以平滑且几乎无滞后。
  • APPO 侧 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.pytest_appo_worker.pytest_appo_runner*.pytest_offpolicy_runner_unit.pytest_offpolicy_double_buffer_runner.pytest_offpolicy_logger.py 等 150 项通过。
  • 远程 CI 按用户要求跳过等待。

🤖 Generated with Kimi Code

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
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>
@TATP-233
TATP-233 merged commit 457b1a9 into dev/issue-1304-motion-numba-body-state Aug 27, 2026
@TATP-233
TATP-233 deleted the fix/offpolicy-reward-log-cadence branch August 27, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant