You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
结论先行
UniLab 的社区兼容 Manager-Based API 已在 #1042 下形成稳定 authoring contract;#1292 又确认,
sac/g1_motion_tracking使用 mjwarp 时,瓶颈已从物理转移到 host NumPy manager 数值层和 reset:#1293–#1296 已完成逐 term profiling、有限值检查采样、reset row-scoped getter 和纯 NumPy 临时数组消除。它们解决了明确的局部浪费,Motrix 因 backend row-scoped 边界获得显著收益;但 mujoco/mjwarp 的
update_state端到端变化已接近单窗口噪声带,继续逐个修改 NumPy 表达式很难突破当前上限。本文讨论是否可从另一套 MotrixLab Manager API 设计中,只借鉴内部执行模型:
本文不建议替换 UniLab 公共 Manager-Based API,不授权重启 Numba 支持路径,也不改变
NpEnv、runner、IPC、checkpoint 或 backend lifecycle。相关记录:
当前数据的指向
#1293 在 8192 envs、mjwarp 上归属到
update_state的主要部分为:单个最大 term 是
termination/anchor_pos,但 #1296 证明其大头来自首次 robot-state gather/cache refresh,而不是 termination 数学本身。后续应把 getter、共享派生量、输出装配和多个 consumer 看作一个数据流,而不只按 term 名逐个优化。“未归属”的约一半时间可能包含 command 更新、manager 编排、observation mapping、logging/reduction、state replacement 或未埋点的派生计算,不能直接当成可消除开销;选方案前仍需更细的临时 profiling。
方向一:冷路径 StateReadPlan
MotrixLab 设计要求 term 先声明 simulator 输入。UniLab 不需要新增公开
sim_queries配置,但可在现有EntityScene/backend facade 上建立内部读取计划:计划提前固定实际需要的 root/joint/body/sensor 字段、selector/列顺序、full/reset-row 读取方式、多 term 共用的 getter/派生状态、可合并的跨语言 getter,以及 mutation 后需要失效的具体缓存。
UniLab 已有 update-phase
_EntityStateReadCache;这里建议增加的是冷路径依赖计划与 bulk/row 布局,不是第二套 scene/backend abstraction。若需要新的SimBackendbulk getter 或 mutation/version contract,必须拆成独立 backend child。方向二:预分配 ObservationAssemblyPlan
当前
ObservationManager.compute_group()的常见路径是:manager 构造时可计算每个 term 的最终 output slice,并分配 group buffer:
这不改变现有
func + params -> np.ndarraycontract,却可减少 term copy、临时 dict/list 和最终 concatenate。delay/history/noise、non-concatenated group 与 reset-row 分别生成冷路径 plan,不能在热路径动态探测。需要先验证
NpEnvStateobservation 引用生命周期;若 consumer 要求上一 transition 在下一 step 后仍不变,应使用 ping-pong buffer。方向三:统一 WorkspacePlan
MotrixLab 的固定字段可抽象为四类内部存储:
num_envs的运行期状态无需引入新 decorator 或公共 term 类型;只在 init/warmup 完成 shape/dtype 校验、分配和 first-touch。它本身未必带来明显 e2e 收益,但可为直接输出和融合实验提供稳定布局。
方向四:整阶段 fused kernel island
若前三项仍不能突破 mjwarp 上约 30 ms 的
update_state,唯一值得重新评估的编译方向不是逐 termnjit,而是一个共享输入的纯数值计算簇:一个 kernel 在同一 outer-env loop 中直接写 termination mask、reward slots/final reward、actor/critic observation slices 和必要 metrics,从而减少 Python dispatch、中间 ndarray、重复内存遍历和派生量重算。
按 #1293 的旧口径,上述 term/postprocess 合计约 14.7 ms;即使只减少一半,也可能比继续优化单 term 更接近可见 collector 收益。这个数字只是 POC 上限估计,不是收益承诺。
风险与 #932 的约束
#932 已证明 standalone kernel 收益不等于 collector e2e;task-specific 双实现、固定 term order、parity 与支持矩阵成本很高;Numba worker 会和 physics/Torch/replay 线程池竞争;自动 plan/fusion 对 task、规模、线程和 NUMA placement 敏感;cold JIT、cache、依赖和 CI 都有永久成本。
MotrixLab 设计可能改变结论的唯一前提,是它从源头把 term 数据/访问限制为静态 kernel-safe 结构,减少通用 routing 和自动分析失败。但如果 UniLab 最终仍维护 vectorized NumPy 与 compiled scalar 两份数学,这个优势就不存在,应停止实验。
明确不借鉴
func + params、function/class term 和批量 NumPy contract。@kernel_data、per-lane context 或njit暴露给 task author。建议验证顺序
A. 补齐热点归属(临时,只测不改)
测量 command compute/post_compute、observation mapping、logging/reduction、state replacement、Entity cache hit/miss/getter 字节量、NumPy allocation 和内存带宽。埋点产出结论后删除。
B. ObservationAssemblyPlan(低风险独立 child)
只做预分配 group layout 和 slice assembly;不改 term API、数学、noise/history 或 env lifecycle。验证三后端 A/B、observation lifetime、partial reset 与数值 parity。
C. StateReadPlan(独立 owner child)
先只消费现有 public entity/backend surface;只有数据证明需要 bulk/row getter 时,另提
SimBackendcontract issue。D. Fused kernel POC(实验、非 production)
sac/g1_motion_tracking一个纯数值簇;对于需要新依赖或长期第二执行路径的方案,建议预先采用更高 gate,例如:两台不同 CPU 上 mjwarp collector e2e 稳定提升至少 15%,mujoco/motrix 无统计显著回退,且没有第二份 term 数学。阈值应由 maintainer 在 POC 前确认;未达到即删除实验。
规模与永久维护成本
这不是一个 implementation issue。A/B/C/D 必须分别只有一个主要结果:
希望讨论的问题
EntityScene内部,还是需要 public bulk-view contract?本 Discussion 只用于选择下一项评估工作;批准讨论本身不授权公共 contract、backend capability 或 production compiled execution path。
All reactions