Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4541
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
On torch>=2.5, tensordict.utils.Buffer is an empty placeholder class, so isinstance checks against it are always False and the buffer branches in _cast, _map_weight and _to_module_compatible_tensor never run. Import torch.nn.Buffer from torchrl._utils, falling back to the tensordict copy on older torch. _make_target_param also checked isinstance(x, nn.Parameter) after taking x.data, which is never a Parameter; check the input instead. Fixes pytorch#4535
Contributor
|
This is the right fix, but don't merge this until torchRL pins a torch>=2.5 |
bsprenger
self-requested a review
October 10, 2026 17:16
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On torch>=2.5,
tensordict.utils.Bufferis an empty placeholder class, soisinstance(x, Buffer)is alwaysFalseand the buffer branches in_cast,_map_weightand_to_module_compatible_tensornever run: atorch.nn.Buffercomes back as a plain tensor.torchrl/_utils.pynow importstorch.nn.Buffer, falling back to the tensordict copy on torch<2.5 (sametry/except ImportErrorpattern asis_compilingjust above it).collectors/utils.py,weight_update/weight_sync_schemes.pyandobjectives/common.pyimportBufferfrom there._make_target_paramcheckedisinstance(x, nn.Parameter)after takingx.data, which is never aParameter. It now checks the input. This doesn't change what users see, sinceTensorDictParamsalready registers the target params as buffers, but the branch now does what the comment above it says.test_weight_helpers_keep_buffersintest/test_collectors.pycovers the three helpers (fails onmain, passes with the fix; skipped on torch<2.5, wherenn.Bufferdoesn't exist).Tested on macOS (CPU), torch 2.14.1, tensordict 0.14.3: the new test plus 129 related collector/loss tests, and
test/objectives/test_loss_module.py,test_dqn.py,test_ddpg.py(1491 passed). ufmt and flake8 clean at the pinned pre-commit versions. I couldn't run torch<2.5 locally, so could a maintainer add theci/olddepslabel?I used an AI assistant (Claude Code) to help write this change; I've reviewed and tested it.
Motivation and Context
close #4535
Types of changes
Checklist