AttributeError: module 'torch' has no attribute 'permute'

I tried to run the code below for training a sequence tagging model (didn’t list all of the code because it works fine). But I get the following error:
AttributeError: module 'torch' has no attribute 'permute'
torch is definitely installed, otherwise other operations made with torch wouldn’t work, too. The code works on Windows 10, conda environment, pip installed torch. But not on Ubuntu 16.04, conda environment, pip installed torch. Any clue how that could be?

import sys, os
from pathlib import Path
import torch
import torch.autograd as autograd
import torch.nn as nn
import torch.optim as optim
from torch.nn.utils.rnn import pad_packed_sequence, pack_padded_sequence, pad_sequence
from torch.utils.data import DataLoader, random_split
import torch.nn.functional as F
import re
from tqdm import tqdm, trange
import fasttext
import fasttext.util


# Preprocessing of data and initialising models not listed...
for epoch in trange(epochs, desc="Epoch"):
    for step, batch in enumerate(train_loader):

        docs = batch[0][0].to(device)
        tags = batch[1].to(device)
        
        model.zero_grad()
        
        doc_forward = docs
        doc_backward = torch.clone(doc_forward)
        doc_backward = torch.flip(doc_backward, [1])

        tag_scores = model(doc_forward, doc_backward)
        tag_scores = torch.permute(tag_scores, (0, 2, 1))

        loss = loss_function(tag_scores, tags)
        loss.backward()
        optimizer.step()
1 Like

tag_scores = tag_scores.permute((0, 2, 1))

1 Like