Skip to content

perf: 优化 ObservationManager 正常 step 固定管线(#1259 U2) #1279

Description

@TATP-233

Parent: #1259

Depends on: #1272 / PR #1274(U1 已合并)、#1269 / PR #1270(R2 已合并)
启动授权:maintainer 已明确要求执行 #1259 Wave 3 U2。

一句话问题

U1/R2 合并后的 sac/g1_motion_tracking profile 显示,正常 step 的 ObservationManager 固定管线(noise、copy/clip/scale、NaN check、concat)在 MuJoCo/Motrix 均约 3.6–3.7 ms/step。当前实现对每个 term 无条件 copy(),有限值检查分别扫描 NaN 与 Inf,随后再拼接结果;这些固定成本可在 owner 内减少,而不改变 observation term 或 manager lifecycle。

最小交付结果

ObservationManager 正常 full-batch step 路径内消除可证明冗余的数组复制与有限值扫描,并收敛拼接周边开销;保持逐 term 计算和 noise/RNG 消耗顺序、输出 shape/dtype/ownership、clip/scale、NaN policy/诊断、delay/history 与 R2 partial-reset 语义。

In scope

  • 落点限于 ObservationManager 及其 focused tests;必要时可在既有私有 helper 内预计算纯静态 pipeline metadata。
  • 只在下游不会原地修改 term-owned array 时跳过 copy;需要原地 clip/scale 的路径仍必须使用 owned storage。
  • 将正常 finite fast path 收敛为单次扫描;异常路径继续区分 NaN/Inf、报告原 term 和真实 env id,并保持 fail-closed。
  • 保持 noise config/model 的调用次数、调用顺序、输入 shape 与 env-owned RNG 最终状态逐位一致。
  • 覆盖 concatenate/dict group、clip/scale/noise、delay/history、NaN policies 和 partial reset 的 parity/ownership tests。
  • 复用现有 collector benchmark,报告同 commit before/after 的 mba_obs_compute_ms、固定管线 timing 与 collector throughput。

Non-goals

  • 不改 observation term 签名、term 执行顺序、维度、obs_groups_spec、配置或公共 manager lifecycle。
  • 不改 R2 partial-reset 稀疏重建、U1 state cache、RewardManager/U3、command、backend、runner/IPC/learner。
  • 不合并跨 group/term 的业务计算,不改变 noise 数值/RNG、NaN 策略、delay/history 或 reset/final observation。
  • 不新增 direct fallback、execution mode、长期性能 CI 或 benchmark framework。

Owner 与预计改动

  • Owner:src/unilab/managers/observation_manager.py
  • 预计 2–5 个文件、≤400 行净手写改动、1 个 PR;base 为 dev/issue-1042-manager-based-api
  • 永久维护成本限于固定管线的数组 ownership 与 finite-check parity tests。

Acceptance criteria

  • 正常 step 的 observation、noise 与 env RNG state 在固定 seed 多步 A/B 中逐位一致;term 调用顺序与次数不变。
  • clip/scale 不修改 term owner 暴露的源数组;concatenated/dict、delay/history 与 R2 partial reset 行为不变。
  • NaN/Inf error/warn/sanitize/disabled 的结果、term context 与 env IDs 保持。
  • 适用 case 的 finite-check timing 明显下降,正常 mba_obs_compute_ms 有可重复改善,collector 无超出重复运行噪声的退化;若收益不足以覆盖新增分支/metadata 维护成本则停止扩张。
  • focused tests 与最终提交本地 make test-all 通过;按 Roadmap: 优化必选的 Manager-Based runtime collector 吞吐并完成 #1042 性能验收 #1259 child 例外不触发或等待远程 CI。

Stop conditions

  • 需要改变 observation term/public manager lifecycle、noise RNG 序列、output ownership、delay/history 或 R2 reset 语义。
  • 需要修改 reward/getter/backend/runner/config,或引入 task-specific fast path。
  • 重复运行无法区分收益,或优化需要长期缓存/双缓冲且 alias 失效边界无法证明。
  • 达到 15 文件、800 行、一个 PR 上限,或出现第二个可独立交付结果。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions