Skip to content

Commit 62a9cb1

Browse files
bbutin-nvidiaclaude
andcommitted
Address PR #78 bokalnv review comments
Fixes 7 correctness bugs flagged in review, all verified against a live retarget_dataset.py run (sequential, speed-resampled, and parallel): - Shipped G1<->GR1 descriptors pointed at env IDs renamed by #79 (IsaacContrib-PickPlace-GR1T2-Abs / -Locomanipulation-G1-Abs); fixed the "iddle" typo alongside. - parallel_replay's end-of-run worker shutdown could hang forever: workers now synchronize on a shared _DrainBarrier instead of each independently racing provider.in_flight(), so they return together. - trajectory's robot_links_state quaternion reorder was hardcoded to the legacy WXYZ->XYZW permutation; it now reads the dataset's own is_legacy_quaternion_format() and uses identity for current XYZW files. - A subtask offset on an object-tracked carry was silently dropped (the carry override replaces the EEF command); apply_subtask_offsets now applies the same offset timeline to the tracked object's own trajectory. - retarget_frame: robot_base reanchored the EEF path after replay_speed resampling against the original-length source_base, causing a shape error for any non-1x speed; reordered to reanchor (EEF path + objects) right after env.reset_to, before resampling. - write_datagen_info recorded eef_pose/object_pose after env.step instead of before, one frame out of sync with the recorded action; moved ahead of the yield, and object_pose now mirrors Datastream.get_object_poses (reference frame + articulations) instead of a raw rigid-objects loop. - Added autodata_tests/retargeting/ to CI's pre-merge TEST_PATH, plus CPU tests for the risky math (offset timelines, carry-offset propagation, span boundary resolution, quat-order selection, drain-barrier logic). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent b22995a commit 62a9cb1

8 files changed

Lines changed: 390 additions & 99 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
# trials each) are heavy and run in the nightly instead. No marker filter, so
6363
# both subprocess and unit tests run.
6464
env:
65-
TEST_PATH: "autodata_tests/e2e/ autodata_tests/interfaces/ autodata_tests/core/ autodata_tests/utils/"
65+
TEST_PATH: "autodata_tests/e2e/ autodata_tests/interfaces/ autodata_tests/core/ autodata_tests/utils/ autodata_tests/retargeting/"
6666

6767
steps:
6868
- name: nvidia-smi

‎autodata_examples/retarget/g1_to_gr1_pick_place.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ write_datagen_info: true # write full datagen_info -> output is a drop-in gener
1313

1414
source_embodiment: ../embodiments/g1_ik_abs.yaml
1515
target_embodiment: ../embodiments/gr1_ik_abs.yaml
16-
target_env_name: Isaac-PickPlace-GR1T2-Abs-v0
16+
target_env_name: IsaacContrib-PickPlace-GR1T2-Abs
1717

1818
hand_policy: binary
1919
init_robot_from_ik: false
@@ -44,7 +44,7 @@ subtasks:
4444
object_tracking: object
4545

4646
- object_ref: world
47-
description: Go back to iddle
47+
description: Go back to idle
4848

4949
left:
5050
- object_ref: object
@@ -60,4 +60,4 @@ subtasks:
6060
object_tracking: object
6161

6262
- object_ref: world
63-
description: Go back to iddle
63+
description: Go back to idle

‎autodata_examples/retarget/gr1_to_g1_pick_place.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ write_datagen_info: true # write full datagen_info -> output is a drop-in gener
1313

1414
source_embodiment: ../embodiments/gr1_ik_abs.yaml
1515
target_embodiment: ../embodiments/g1_ik_abs.yaml
16-
target_env_name: Isaac-PickPlace-Locomanipulation-G1-Abs-v0
16+
target_env_name: IsaacContrib-PickPlace-Locomanipulation-G1-Abs
1717

1818
hand_policy: binary
1919
# The G1 target's locomanipulation action has a body channel; hold it at this default during replay.
@@ -47,7 +47,7 @@ subtasks:
4747
object_tracking: object
4848

4949
- object_ref: world
50-
description: Go back to iddle
50+
description: Go back to idle
5151

5252
left:
5353
- object_ref: object
@@ -63,4 +63,4 @@ subtasks:
6363
object_tracking: object
6464

6565
- object_ref: world
66-
description: Go back to iddle
66+
description: Go back to idle

‎autodata_retargeting/parallel_replay.py‎

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ def _hold_action(env, env_id, target_adapter, passthrough) -> torch.Tensor:
7878
return action[0] if action.dim() > 1 else action
7979

8080

81+
class _DrainBarrier:
82+
"""Tracks how many workers have run out of plans, so they can all stop together.
83+
84+
``env_loop`` requires exactly one action per env on every tick, so a worker must never stop
85+
contributing actions while any other worker is still going to submit one. A worker only ever goes
86+
idle once (``next_for_env`` keeps returning ``None`` from then on), and it always ``observe()``-s a
87+
plan before it can go idle, so the count reaching ``num_envs`` is a consistent, race-free signal that
88+
every in-flight plan has been observed -- unlike re-checking ``provider.in_flight()`` independently on
89+
every worker, which can see a stale count while the last episode's worker is still finishing up.
90+
"""
91+
92+
def __init__(self, num_envs: int) -> None:
93+
self._num_envs = num_envs
94+
self._num_idle = 0
95+
96+
def mark_idle(self) -> None:
97+
self._num_idle += 1
98+
99+
def all_idle(self) -> bool:
100+
return self._num_idle == self._num_envs
101+
102+
81103
async def _replay_worker(
82104
ctx: ReplayContext,
83105
env,
@@ -86,23 +108,29 @@ async def _replay_worker(
86108
action_queue: asyncio.Queue,
87109
results: list[tuple[str, bool]],
88110
stats: dict[str, int],
111+
drain_barrier: _DrainBarrier,
89112
) -> None:
90113
"""One env's worker: pull plans from ``provider`` and replay them.
91114
92-
When the provider hands out nothing: if it is fully drained (nothing in flight on any env) the worker
93-
*returns* so ``env_loop`` terminates via its task-completion check (this covers an unreachable success
94-
target on a finite source); otherwise it *holds* at the current pose so the batched step keeps
95-
advancing the still-running workers.
115+
When the provider hands out nothing, the worker goes idle and holds at the current pose (so the
116+
batched step keeps advancing the still-running workers) until every other worker has also gone idle --
117+
see :class:`_DrainBarrier`. Only then do all workers return together, so ``env_loop`` terminates via
118+
its task-completion check (this covers an unreachable success target on a finite source).
96119
"""
97120
target_adapter = ctx.target_adapter
98121
env_ids = torch.tensor([env_id], device=env.device)
99122
hold_passthrough = None # last episode's passthrough, reused to hold the gripper at a valid command
123+
idle = False
100124
while True:
101-
# ``next_for_env`` is env-agnostic for the copy provider (its plans do not depend on which env runs
102-
# them). Synchronous, so each worker claims a distinct source episode + index.
103-
plan = provider.next_for_env(env_id)
104-
if plan is None:
105-
if provider.in_flight() == 0:
125+
if not idle:
126+
# ``next_for_env`` is env-agnostic for the copy provider (its plans do not depend on which env
127+
# runs them). Synchronous, so each worker claims a distinct source episode + index.
128+
plan = provider.next_for_env(env_id)
129+
if plan is None:
130+
idle = True
131+
drain_barrier.mark_idle()
132+
if idle:
133+
if drain_barrier.all_idle():
106134
return
107135
if hold_passthrough is None:
108136
hold_passthrough = _zeros_passthrough(env, target_adapter)
@@ -146,9 +174,10 @@ def run_parallel_replay(
146174
reset_queue: asyncio.Queue = asyncio.Queue() # unused here; env_loop expects the handle
147175
results: list[tuple[str, bool]] = []
148176
stats = {"num_success": 0, "num_failures": 0, "num_attempts": 0}
177+
drain_barrier = _DrainBarrier(num_envs)
149178

150179
tasks = [
151-
event_loop.create_task(_replay_worker(ctx, env, env_id, provider, action_queue, results, stats))
180+
event_loop.create_task(_replay_worker(ctx, env, env_id, provider, action_queue, results, stats, drain_barrier))
152181
for env_id in range(num_envs)
153182
]
154183
data_gen_tasks = asyncio.ensure_future(asyncio.gather(*tasks))

0 commit comments

Comments
 (0)