[BugFix] Convert Mapping values for TensorDict fields in tensor-only tensorclasses - #1753
Conversation
|
Hi @peterdsharpe! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Description
This PR converts arbitrary
collections.abc.Mappingvalues assigned toTensorDict-annotated fields on
tensor_only=Truetensorclasses.The annotation-aware conversion applies consistently during construction,
attribute assignment,
.set(), andfrom_dataclass. It also:AnyorNonTensorDataunchanged;Motivation and Context
Closes #1752.
Non-
dictMapping implementations were previously wrapped asNonTensorDataeven when the destination field was annotated as
TensorDict. The fix isscoped using resolved field annotations so that it does not globally reinterpret
mappings intended to remain non-tensor data.
Test plan
Regression tests cover:
dictandUserDictinputs;.set();from_dataclass;AnyandNonTensorDatamapping fields remaining non-tensor.Local validation:
pytest test/tensorclass/test_tensorclass.py -k "TestTensorOnly":16 passed
pytest test/tensorclass/test_tensorclass.py -k "not multiprocessing":160 passed, 1 skipped, 1 deselected
pytest test/tensorclass/test_compatibility.py test/tensorclass/test_typedtensordict.py:174 passed, 14 skipped
git diff --checkpassTypes of changes
Checklist