Skip to content

[Roadmap#2583] 消费 unisim.utils.math 统一旋转原语 + 训练热路径 GPU-resident 同步消除 - #2586

Merged
TATP-233 merged 4 commits into
mainfrom
dev/issue-2583-unify-math-rotation
Nov 6, 2026
Merged

TATP-233 merged 4 commits into
mainfrom
dev/issue-2583-unify-math-rotation

Conversation

@TATP-233

@TATP-233 TATP-233 commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

概要

实现 #2583 的 unilab 侧(Child 1+3+4 合并):删除全部本地四元数/旋转重复实现,统一经薄 shim 消费 unisim.utils.math;并按审计消除训练热路径的强制 host 同步点。

依赖已就绪:unisim-core==2.7.0 已发布(unilabsim/unisim#525 合入),本分支 pin 已升至 2.7.0(含 pyproject.rocm.toml + uv.rocm.lock 同步),CI 可独立验证。

改动

数学原语收敛

  • 删除 src/unilab/base/rotation.py(479 行)与 tasks/motion_tracking/common/tensor_rotation.py(143 行)
  • 新增薄 shim src/unilab/utils/math.py:from unisim.utils.math import ... 纯转发 39 个名字,零逻辑;无前缀 = Torch,np_ = NumPy
  • 迁移全部调用方:envs/mdp/{observations,events,ray_observation,rewards,terminations}、velocity_command、base/{entity,reset_state}、tasks/motion_tracking/common/{manager_terms,motion_loader}、scripts/motion、tests
  • 语义适配:ray_observation 外积语义在调用方显式 reshape;euler N==1 squeeze 行为变化处已适配;torch↔numpy parity 实测

Child 4 防 latent 同步风险

  • 新增 tests/architecture/test_host_rotation_sync_boundary.py:热路径目录禁止 _host_root_link_* 引用、禁止 .cpu()/.numpy() 后 10 行内 quat 调用
  • 审计确认 _host_root_link_lin/ang_vel_b 训练热路径零调用
  • 新增 ADR-0022(unisim 为数学原语唯一 owner)

热路径 GPU-resident 修复(审计驱动,同步探针实测对照基线)

  • terminations _state_tensor 有限性校验接入 deferred verdict(每步 2→0 次同步)
  • circular buffer 首 push 探测改 host 计数(1→0)
  • event manager interval 触发改 host 下界(静窗 1→0,RNG 消耗不变)
  • ApplyBodyImpulse cooldown/sustain 改 host 镜像(4→0)
  • torch_env autoreset 冗余判断/计时(4→2,结构性保留)
  • reset_selectors 双 bool 归一(2→1);reset_state 校验接 verdict sink、修正 torch.equal 错误注释
  • termination manager reset 指标改 poll 边界 drain
  • poll_finite_validation 联动 packed-reset verdict(eager→strict / defer→deferred)并在 poll 边界 drain,闭环无静默锁存

defer_finite_validation 默认翻转为 True:有限性检查默认设备侧累积、固定 poll 边界发布(interval 默认仍为 1,四个训练 owner YAML 保持显式 32);eager 路径测试显式 pin False。

CUDA profiler 实证:19 个 torch 原语 workload 零 memcpy/memset 事件,无新增 D2H/H2D。

验证

  • make test-all(对 PyPI 发行的 unisim-core 2.7.0):2930 passed / 0 failed,ruff / mypy / pyright(0 errors),benchmark smoke 35/35 + 36/36
  • 验收自查:rg "def (quat_mul|quat_apply|quat_apply_inverse|quat_from_euler_xyz)" src/unilab 零命中

附带

Refs #2583

…uplicates

Remove src/unilab/base/rotation.py and motion_tracking tensor_rotation.py;
all rotation/quaternion call sites now consume unisim.math through the thin
re-export package src/unilab/math (hard cut, no shims). Inline duplicates in
envs/mdp (observations, events, ray_observation) and motion_loader converge
on the shared primitives. Add host-rotation-sync architecture guard tests
and ADR-0022 recording unisim as the sole owner of math primitives.

Refs #2583
Replace the src/unilab/math package (rotation_numpy/rotation_tensor
modules with identical names) with a single thin shim
src/unilab/utils/math.py re-exporting unisim.utils.math: unprefixed
names are Torch operators (mjlab-aligned), NumPy counterparts carry the
np_ prefix. Update all call sites, docs, and ADR-0022 accordingly.

Refs #2583
Audit-driven GPU-resident fixes (sync probe verified against HEAD
baseline):

- terminations: route _state_tensor finite checks through the env's
  deferred finite verdict instead of per-step blocking bool()
- circular buffer: replace first-push bool(any()) probe with host-side
  row counting; steady-state append is sync-free
- torch_env: drop redundant done-mask re-evaluation and timing float()
- event manager: host lower-bound gating for interval triggers (no
  device read during quiet windows), RNG consumption unchanged
- events.ApplyBodyImpulse: host mirrors for cooldown/sustain windows
- entity wrench validation wired into the deferred verdict recorder
- reset_selectors: fold resolve_reset_env_ids bounds checks into one
  device reduction
- reset_state: verdict sink for payload finite checks; fix wrong
  torch.equal no-sync comment; propagate packed-reset validation mode
  (strict when eager, deferred when the env defers)
- termination manager: drain reset metrics at the poll boundary
- env poll_finite_validation now also drains the backend packed-reset
  verdict, closing the deferred-validation loop

Refs #2583
…re to 2.7.0

Finite checks now accumulate device-side and publish at the fixed poll
boundary by default (interval unchanged at 1; training owner YAMLs keep
their explicit interval 32). Tests covering the eager fail-closed paths
pin defer_finite_validation=False explicitly.

Pin unisim-core==2.7.0 (unisim.utils.math + packed reset verdict API);
ROCm track updated in sync (pyproject.rocm.toml + uv.rocm.lock).

Refs #2583
@TATP-233
TATP-233 marked this pull request as ready for review November 6, 2026 04:27
@TATP-233
TATP-233 requested a review from caozx1110 as a code owner November 6, 2026 04:27
@TATP-233
TATP-233 merged commit 51361ea into main Nov 6, 2026
13 of 22 checks passed
@TATP-233
TATP-233 deleted the dev/issue-2583-unify-math-rotation branch November 6, 2026 04:34
@TATP-233 TATP-233 mentioned this pull request Nov 6, 2026
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