Repository navigation
[BugFix] Keep AsyncBatchedCollector's env_index a tensor with tensordict 0.17 - #4637
Open
peterdsharpe wants to merge 1 commit into
Open
peterdsharpe wants to merge 1 commit into
peterdsharpe wants to merge 1 commit into
Conversation
…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.
🔗 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. ❌ 2 New FailuresAs of commit 39144dd with merge base 380dd55 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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.
With tensordict 0.17,
AsyncBatchedCollectorthread workers yield batches whoseenv_indexis non-tensor data instead of a long tensor. Anything that routes or groups transitions by that index then breaks: in a run simulating 0.17's behavior, 5TestAsyncBatchedCollectortests fail, becauseReplayBufferEnsembleneeds integer member ids and.unique()does not work on a non-tensor entry. TorchRL pinstensordict<0.16, so no released TorchRL is affected, but this has to land before the pin is lifted.The fix stores
env_indexin the thread worker loop as a long tensor of the result's batch size, on the result's device, the same way the chunked process workers already do.Details
In
_env_loop, each result comes fromAsyncEnvPool.async_step_and_maybe_reset_recv, which for the queue exchange marks it withNonTensorData(data=env_index). The loop then wrote the intenv_idover that entry. tensordict 0.15 and 0.16 cast an int written over aNonTensorDataentry to a 0-d tensor and emit aFutureWarning; from 0.17 the int staysNonTensorData, like the entry it replaces.Now the loop writes
torch.full(cur_td.batch_size, env_id, dtype=torch.long, device=cur_td.device). For an unbatched slot this is the same 0-d int64 tensor the cast gives today, so on current tensordict the only change is that the warning goes away. A pool slot with a non-empty batch size now gets one index per row; today the cast raises in that case.The other two places that set
env_indexare fine. Thechunk_size == 1process loop writes the int on a key that is not set yet, which already gives a tensor and is not affected by the 0.17 change. The chunked path already usestorch.full(..., dtype=torch.long).Tests
I added
TestAsyncBatchedCollector::test_thread_worker_env_index_is_long_tensor. It turns the tensordictFutureWarninginto an error and checks that a thread-worker batch'senv_indexis a long tensor with values in{0, 1}. Without the filter the test would pass on current tensordict, since tensordict casts the int; the filter is what catches the old write.Run on a 24-core desktop (CPU, torch 2.14.1, Python 3.12, tensordict main):
pytest test/test_inference_server.py -k test_thread_worker_env_index_is_long_tensor: fails without the fix (the worker thread raises theFutureWarning, and the collector reportsRuntimeError: A collector worker thread raised an exception.), passes with it.pytest test/test_inference_server.py -k TestAsyncBatchedCollector -n 4: 106 passed, 6 skipped.I also ran this branch together with #4638 against a copy of tensordict main patched to do what 0.17 announces (the removals raise, the new defaults apply):
test_collectors.py,test_inference_server.py,test_dt.py,test_exploration.pyandtest/llmgive the same results as on unpatched tensordict main, and none of the removed APIs is reached.Related: #4551 (tensordict 0.16) and #4576 (tensordict 0.17).