Skip to content

Fix CircularBuffer backfill broadcast for >2D data#1046

Merged
kevinzakka merged 1 commit into
mainfrom
fix-circular-buffer-nd-backfill
Jun 4, 2026
Merged

Fix CircularBuffer backfill broadcast for >2D data#1046
kevinzakka merged 1 commit into
mainfrom
fix-circular-buffer-nd-backfill

Conversation

@kevinzakka

@kevinzakka kevinzakka commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

CircularBuffer.append crashed with a broadcast mismatch when the buffered data had more than two dimensions. The first-push backfill hard-coded a 3-D broadcast, which misaligns the batch axis with the trailing axis once DcMotorActuator's variable delay stacks targets into a 3-D tensor. It now derives the broadcast shape from data.ndim so backfill works for any rank. The regression came from #1031, which swapped the dimension-agnostic mask for a sync-free torch.where but baked in 3-D views.

Supersedes #1045 by @ZzzzzzS, who diagnosed the bug and wrote an equivalent fix (credited as co-author).

The first-push backfill in CircularBuffer.append hard-coded a 3-D broadcast
(is_first_push[None, :, None] and data[None, :, :]), which only lines up when
the buffer is exactly (max_len, batch, feature). DcMotorActuator with a
variable delay lag range stacks position, velocity, and effort targets into a
3-D tensor (num_envs, num_targets, 3), making the buffer 4-D. The hard-coded
condition then misaligns the batch axis with the num_targets axis and raises a
broadcast error whenever num_envs != num_targets. The fix derives the broadcast
shape from data.ndim so it works for tensors of any rank.

Supersedes #1045.

Co-authored-by: ZzzzzzS <ZhouZishun@mail.zzshub.cn>
@kevinzakka kevinzakka force-pushed the fix-circular-buffer-nd-backfill branch from 99a0754 to 1c2b483 Compare June 4, 2026 16:45
@kevinzakka kevinzakka enabled auto-merge (squash) June 4, 2026 16:48

@rdeits-bd rdeits-bd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry about that and thanks for the fix. I don't see any new CUDA sync issues after this change.

@kevinzakka kevinzakka merged commit 1d14740 into main Jun 4, 2026
16 checks passed
@kevinzakka kevinzakka deleted the fix-circular-buffer-nd-backfill branch June 4, 2026 17:11
Qingxiaoming pushed a commit to Qingxiaoming/mjlab that referenced this pull request Jun 18, 2026
The first-push backfill in CircularBuffer.append hard-coded a 3-D broadcast
(is_first_push[None, :, None] and data[None, :, :]), which only lines up when
the buffer is exactly (max_len, batch, feature). DcMotorActuator with a
variable delay lag range stacks position, velocity, and effort targets into a
3-D tensor (num_envs, num_targets, 3), making the buffer 4-D. The hard-coded
condition then misaligns the batch axis with the num_targets axis and raises a
broadcast error whenever num_envs != num_targets. The fix derives the broadcast
shape from data.ndim so it works for tensors of any rank.

Supersedes mujocolab#1045.

Co-authored-by: ZzzzzzS <ZhouZishun@mail.zzshub.cn>
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.

2 participants