Skip to content

[BugFix] Fix missing raise, incorrect __torch_function__ return, and off-by-one in RayCollector#3530

Merged
vmoens merged 1 commit intopytorch:mainfrom
jashshah999:fix/missing-raise-and-offbyone-bugs
Feb 25, 2026
Merged

[BugFix] Fix missing raise, incorrect __torch_function__ return, and off-by-one in RayCollector#3530
vmoens merged 1 commit intopytorch:mainfrom
jashshah999:fix/missing-raise-and-offbyone-bugs

Conversation

@jashshah999
Copy link
Copy Markdown
Contributor

Summary

Fixes three independent bugs found during code review:

  • collectors/_runner.py: RuntimeError(MPS_ERROR) is constructed but never raised, silently allowing execution to continue when tensors are on MPS devices instead of failing with a clear error
  • data/tensor_specs.py: TensorSpec.__torch_function__ returns a NotImplementedError(...) instance instead of the NotImplemented sentinel, violating the __torch_function__ protocol and causing downstream confusion since the caller receives an exception object as a valid return value
  • collectors/distributed/ray.py: update_policy_weights_() is called with collector_index + 1, but collector_index is already 0-indexed (it comes from pending_tasks.pop(future)), so the +1 causes weight updates to target the wrong worker

Changes

All three fixes are minimal:

  1. Add raise before RuntimeError(MPS_ERROR) in _runner.py:490
  2. Replace return NotImplementedError(...) with return NotImplemented in tensor_specs.py:1232
  3. Remove + 1 from collector_index + 1 in ray.py:1013

Fixes #3000

…r_ids

1. collectors/_runner.py: Add missing `raise` before `RuntimeError(MPS_ERROR)`.
   The exception was constructed but never raised, silently allowing
   execution to continue when tensors are on MPS devices.

2. data/tensor_specs.py: Fix `__torch_function__` to return `NotImplemented`
   instead of `return NotImplementedError(...)`. The previous code returned
   an exception object as a value rather than following the standard
   `__torch_function__` protocol.

3. collectors/distributed/ray.py: Fix off-by-one in `_async_iterator` where
   `collector_index + 1` was passed to `update_policy_weights_()`.
   `collector_index` is already 0-indexed from `pending_tasks.pop(future)`,
   so the +1 causes weight updates to target the wrong worker.

Fixes pytorch#3000
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Feb 25, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3530

Note: Links to docs will display an error until the docs builds have been completed.

❌ 6 New Failures, 5 Pending, 21 Unrelated Failures

As of commit faa0a24 with merge base ab0a445 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Feb 25, 2026

Hi @jashshah999!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 25, 2026
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Feb 25, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Copy link
Copy Markdown
Collaborator

@vmoens vmoens left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

@vmoens vmoens merged commit ef3d275 into pytorch:main Feb 25, 2026
77 of 108 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BugFix CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Collectors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] RayCollector calls update_policy_weights_() with off-by-one index causing intermittent IndexError

2 participants