Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Deprecation] Softly deprecate extra-tensors wrt out_keys #1215

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tensordict/nn/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,21 @@ def _write_to_tensordict(
tensordict_out = TensorDict()
else:
tensordict_out = tensordict
for _out_key, _tensor in _zip_strict(out_keys, tensors):
if len(tensors) > len(out_keys):
incipit = "There are more tensors than out_keys. "
elif len(out_keys) > len(tensors):
incipit = "There are more out_keys than tensors. "
else:
incipit = None
if incipit is not None:
warnings.warn(
incipit + "This is currently "
"allowed but it will be deprecated in v0.9. To silence this warning, "
"make sure the number of out_keys matches the number of outputs of the "
"network.",
category=DeprecationWarning,
)
for _out_key, _tensor in zip(out_keys, tensors):
if _out_key != "_":
tensordict_out.set(_out_key, TensorDict.from_any(_tensor))
return tensordict_out
Expand Down
Loading