fix(gym): separate policy and controller action traces - #695
Conversation
|
| def test_controller_action_refreshes_executed_qpos_snapshot() -> None: | ||
| """A direct controller command must not reuse a prior manager snapshot.""" | ||
| env = _controller_action_env() | ||
| env._last_action_manager_qpos = torch.full((2, 3), 99.0) | ||
|
|
||
| prepared = env._preprocess_action(ControllerAction(torch.ones(2, 3))) | ||
|
|
||
| assert isinstance(prepared, ControllerAction) | ||
| torch.testing.assert_close(env._last_action_manager_qpos, torch.ones(2, 3)) |
There was a problem hiding this comment.
Mixed recording remains untested These tests stop after preprocessing and masking; they never check what the recorder saves from executed-qpos history. Add a recording test with simultaneous policy and legacy recorders whose action widths differ. Without it, the mixed-contract behavior this change targets can regress unnoticed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/gym/envs/test_demo.py
Line: 224-232
Comment:
**Mixed recording remains untested** These tests stop after preprocessing and masking; they never check what the recorder saves from executed-qpos history. Add a recording test with simultaneous policy and legacy recorders whose action widths differ. Without it, the mixed-contract behavior this change targets can regress unnoticed.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
ac264d2 to
87e2625
Compare
87e2625 to
f7af523
Compare
| if ( | ||
| expert_spec is not None | ||
| and expert_spec.joint_command_mode == "position_velocity" | ||
| ): | ||
| # Position-velocity expert rows are already encoded as | ||
| # [qpos, qvel] in the rollout buffer. Executed qpos history | ||
| # intentionally contains only qpos and must not replace it. | ||
| return torch.as_tensor(stored_actions).detach().cpu().clone() |
There was a problem hiding this comment.
Legacy recorder saves policy requests When a policy-contract recorder runs alongside a legacy recorder in a position-velocity expert environment, the shared rollout buffer holds policy requests rather than
[qpos, qvel] commands. This branch returns those requests for the legacy recorder, so it saves actions with the wrong meaning and potentially the wrong width for its declared expert schema.
Prompt To Fix With AI
This is a comment left during a code review.
Path: embodichain/lab/gym/envs/managers/datasets.py
Line: 515-522
Comment:
**Legacy recorder saves policy requests** When a policy-contract recorder runs alongside a legacy recorder in a position-velocity expert environment, the shared rollout buffer holds policy requests rather than `[qpos, qvel]` commands. This branch returns those requests for the legacy recorder, so it saves actions with the wrong meaning and potentially the wrong width for its declared expert schema.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Description
This PR makes EmbodiChain action semantics explicit across RL rollouts, expert demonstrations, and LeRobot recording.
Previously, one rollout action field could represent either a raw policy request or an executed controller command. That ambiguity caused stale qpos snapshots, incompatible action widths when policy and joint recorders were combined, and loss of velocity data for position-velocity demonstrations.
The implementation now provides:
ActionTracewith separaterequested,processed, andexecutedaction stages.rollout_action_semanticsvalues for policy-request and expert-controller buffers.[qpos, qvel]position-velocity expert actions.The existing action contracts and rollout buffer layout remain compatible; the new trace and semantics metadata clarify how each recorded action should be interpreted.
Related: #680
Type of change
Validation
black --check --diff --color ./passed.git diff --checkpassed.Checklist
black .command to format the code base.