Skip to content

Commit

Permalink
[Refactor] Graceful as_tensor (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens authored Nov 2, 2023
1 parent c3caa76 commit 09b327c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
15 changes: 8 additions & 7 deletions tensordict/tensordict.py
Original file line number Diff line number Diff line change
Expand Up @@ -1811,13 +1811,14 @@ def as_tensor(self):
and will raise an exception in all other cases.
"""
try:
return self._fast_apply(lambda x: x.as_tensor())
except AttributeError as err:
raise AttributeError(
f"{self.__class__.__name__} does not have an 'as_tensor' method "
f"because at least one of its tensors does not support this method."
) from err

def as_tensor(x):
try:
return x.as_tensor()
except AttributeError:
return x

return self._fast_apply(as_tensor)

def update(
self,
Expand Down
1 change: 0 additions & 1 deletion tensordict/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,6 @@ def _is_shared(tensor: torch.Tensor) -> bool:
elif isinstance(tensor, KeyedJaggedTensor):
return False
else:
print(type(tensor))
return tensor.is_shared()


Expand Down

1 comment on commit 09b327c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'CPU Benchmark Results'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 09b327c Previous: c3caa76 Ratio
benchmarks/common/memmap_benchmarks_test.py::test_memmaptd_index_op 150.58894890862786 iter/sec (stddev: 0.0024012234844872273) 327.22066713262046 iter/sec (stddev: 0.00002575423655114622) 2.17

This comment was automatically generated by workflow using github-action-benchmark.

CC: @vmoens

Please sign in to comment.