Repository navigation
[BugFix] Keep AsyncBatchedCollector's env_index a tensor with tensordict 0.17 - #4637
Merged
Merged
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4637
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit 0ca7025 with merge base 6479319 ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
bsprenger
approved these changes
Nov 7, 2026
bsprenger
left a comment
Collaborator
There was a problem hiding this comment.
Looks great, thanks for fixing, and sorry for the delay in reviewing! Can you rebase + rerun CI before we merge?
…ict 0.17 Thread workers wrote an int over the NonTensorData env_index that the AsyncEnvPool sets on each result. tensordict casts that int to a tensor today with a FutureWarning, and keeps it non-tensor from 0.17. Store a long tensor of the slot's batch size, as the chunked process workers do.
peterdsharpe
force-pushed
the
async-env-index-tensor
branch
from
November 7, 2026 03:31
39144dd to
0ca7025
Compare
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.
Problem
In
AsyncBatchedCollector's thread worker (_env_loop),pool.async_step_and_maybe_reset_recvreturns aTensorDictwhere"env_index"is aNonTensorData(env_index)marker set by the pool, and the worker overwrites it with a Pythonint:In
tensordict0.15-0.16, writing a Pythonintover an existingNonTensorDataentry converts it to a 0-D tensor and emits aFutureWarning. Starting intensordict0.17,setpreserves the existing entry kind and keeps"env_index"asNonTensorData, which breaks downstream consumers that expect an integer tensor (such asReplayBufferEnsemblerouting and.unique()).Fix
Write an explicit
torch.longtensor matchingcur_td.batch_sizeandcur_td.device, the same way the chunked process-worker path in_process_env_loopalready does:For an unbatched env slot this produces the same 0-D
int64tensor as today without triggering the deprecation warning.Tests
Added
TestAsyncBatchedCollector::test_thread_worker_env_index_is_long_tensorintest/test_inference_server.py, which runs a threadedAsyncBatchedCollectorwith theFutureWarningturned into an error and checks that"env_index"is atorch.longtensor.Related: #4551, #4576, and #4638.