When we are building ai model using pytorch, we may get this error: AttributeError: module ‘torch’ has no attribute ‘permute’. In this tutorial, we will introduce you how to fix it.
For example:
import torch import torch.nn as nn batch_size, length, dim = 32, 5, 200 inputs = torch.randn(batch_size, length, dim) inputs = torch.permute(inputs, (1, 0, 2))
Run this code, we will see:
In higher pytorch version, torch.permute() is created. You can read:
https://pytorch.org/docs/stable/generated/torch.permute.html
How to fix this error?
Method 1: update your pytorch to high version
Method 2: use tensor.permute()
For example:
inputs = inputs.permute((1, 0, 2))
Run this code, we find this error is fixed.