Avoid AttributeError: 'torch.dtype' object has no attribute 'type' …#89
Avoid AttributeError: 'torch.dtype' object has no attribute 'type' …#89GoingMyWay wants to merge 3 commits intooxwhirl:masterfrom
AttributeError: 'torch.dtype' object has no attribute 'type' …#89Conversation
…error avoid `AttributeError: 'torch.dtype' object has no attribute 'type'` error
|
+1, currently the Docker image fails due to this since it always installs the latest version of PyTorch. |
|
Hello, I ran into this issue as well, should have come by your PR sooner. Not sure how performance compares, or which is best practice, but I edited the below in the logging file: # defined a new method in the logging class
def average_list(self, k, window):
array = []
for stat in self.stats[k][-window:]:
item = stat[1]
if T.is_tensor(item):
item = item.cpu().numpy()
array.append(item)
return np.mean(array)
# edited the line throwing the errors
item = "{:.4f}".format(self.average_list(k, window)) |
```Python In [7]: import numpy as np In [8]: np.prod((1, 2, 3, 4)) Out[8]: 24 In [9]: type(np.prod((1, 2, 3, 4))) Out[9]: numpy.int64 In [10]: type(int(np.prod((1, 2, 3, 4)))) Out[10]: int In [11]: import numbers In [12]: isinstance(np.prod((1, 2, 3, 4)), numbers.Integral) Out[12]: True In [13]: isinstance(np.prod((1, 2, 3, 4)), int) Out[13]: False ```
|
Hi, I would like to mention that I tested the fix by @GoingMyWay because mine felt hacky, but it didn't work, still crashed when logging the stats. Reverted back to my fix. |
Can you check which item in the stats caused this problem. Actually, for old Pytorch versions, the |
src/components/episode_buffer.py:103: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor). v = th.tensor(v, dtype=dtype, device=self.device)
Avoid
AttributeError: 'torch.dtype' object has no attribute 'type'error. To make it compatible with new PyTorch versions