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

[Performance] Minor efficiency improvements #703

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions tensordict/_td.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,14 @@ def __eq__(self, other: object) -> T | bool:
keys1 = set(self.keys())
keys2 = set(other.keys())
if len(keys1.difference(keys2)) or len(keys1) != len(keys2):
keys1 = sorted(
keys1,
key=lambda key: "".join(key) if isinstance(key, tuple) else key,
)
keys2 = sorted(
keys2,
key=lambda key: "".join(key) if isinstance(key, tuple) else key,
)
raise KeyError(f"keys in tensordicts mismatch, got {keys1} and {keys2}")
d = {}
for key, item1 in self.items():
Expand Down
5 changes: 3 additions & 2 deletions tensordict/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5368,8 +5368,9 @@ def _register_tensor_class(cls):


def _is_tensor_collection(datatype):
out = _TENSOR_COLLECTION_MEMO.get(datatype, None)
if out is None:
try:
out = _TENSOR_COLLECTION_MEMO[datatype]
except KeyError:
if issubclass(datatype, TensorDictBase):
out = True
elif _is_tensorclass(datatype):
Expand Down
Loading