pymarl icon indicating copy to clipboard operation
pymarl copied to clipboard

Avoid `AttributeError: 'torch.dtype' object has no attribute 'type'` …

Open GoingMyWay opened this issue 5 years ago • 4 comments

Avoid AttributeError: 'torch.dtype' object has no attribute 'type' error. To make it compatible with new PyTorch versions

GoingMyWay avatar Nov 16 '20 12:11 GoingMyWay

+1, currently the Docker image fails due to this since it always installs the latest version of PyTorch.

AVSurfer123 avatar Dec 13 '20 01:12 AVSurfer123

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))

reubenwong97 avatar Jan 21 '21 04:01 reubenwong97

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.

reubenwong97 avatar May 02 '21 11:05 reubenwong97

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 grad_norm caused this problem.

GoingMyWay avatar May 03 '21 11:05 GoingMyWay