Add recursion guard and tidy tests #220
Merged
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
This PR adds a new decorator
_recursion_guard
which catches recursion errors in methods that don't currently support auto-nesting and adds a more instructive error message.I've removed skips from a number of methods that are in fact working. I've also removed some skips from tests which were failing for reasons that should be fixed rather than because they were testing for unsupported behaviour. Reasons for failures are listed below. I did this because otherwise I think we could trick ourselves into thinking that #201 is ready to be merged into main prematurely.
Reasons for failing tests
The following tests fail because
assert_allclose_td
does not support auto-nested valuestest_from_empty
test_masking
test_getitem_ellipsis
test_getitem_range
The following tests fail because we can't instantiate a TensorDict from a Python
dict
with auto-nested valuestest_broadcast
test_equal_dict
test_nested_dict_init
Finally
test_nestedtensor_stack
is failing becauseLazyStackedTensorDict.contiguous
is broken. I think a few other methods forLazyStackedTensorDict
could be broken but not caught by the tests. The issues here largely stem from the fact that values are computed lazily, and hence use ofid
to check for repeated values is brittle.