Problem consisting of Pyinstaller and Pytorch

Hi guys, I recently ran into a problem. My project requires me to use pyinstaller to package the code file using the pytorch library into an exe file, but when the package is successful, an error “Key already registered with the same priority C10” is generated.

I am puzzled, because I run normally under Anaconda5.2 environment (Python3.7)

So I wrote a very simple torch code, but the same situation still occurs (the operation fails after packaging(Pyinstaller), and the error “Key already registered with the same priority C10” is reported)
Here is my simple code:

import torch
import torch.nn as nn
from torch.autograd import Variable
import matplotlib.pyplot as plt
import torch.nn.functional as F

x = torch.unsqueeze(torch.linspace(-1, 1, 100), dim=1)
y = x.pow(2) + torch.randn(x.size()) * 0.1
x, y = Variable(x), Variable(y)

# plt.scatter(x.data.numpy(), y.data.numpy())
# plt.show()

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.fc1 = nn.Linear(1, 8)
        self.fc2 = nn.Linear(8, 4)
        self.fc3 = nn.Linear(4, 1)
        self.opti = torch.optim.Adam(self.parameters(), lr=0.01)
        self.loss_fun = torch.nn.MSELoss()
        
        self.loss_append = []

    def forward(self, x):
        x = self.fc1(x)
        x = F.relu(x)
        x = self.fc2(x)
        x = F.relu(x)
        x = self.fc3(x)
        return x

    def learn(self, x, y):
        out = self.forward(x)
        loss = self.loss_fun(out, y)
        print('当前误差:', loss.data.item())
        self.loss_append.append(loss.data.item())
        self.opti.zero_grad()
        loss.backward()
        self.opti.step()
def main():
    update_net = Net() 
    soft_net = Net()
    for i in range(500):
        update_net.learn(x, y)
        for w_b in soft_net.state_dict().keys():
            eval('soft_net.' + w_b + '.data.mul_(1 - 0.01)')
            eval('soft_net.' + w_b + '.data.add_(0.01 * (update_net.' + w_b + '.data))')

    print("successful")
# plt.plot(x.data.numpy(), update_net.forward(x).data.numpy(), color='red')
# plt.plot(x.data.numpy(), soft_net.forward(x).data.numpy(), color='blue')
# plt.scatter(x.data.numpy(), y.data.numpy(), color='black')
# plt.show()
if __name__ == '__main__':
    main()

Can u be my superhero???
Plus:My computer configuration
Operation System: Windows Server 2008 R2
CPU:Core i7-10870H@2.20GHz
GPU: NVIDIA RTX 3060
ERROR:

1 Like

Hi,

did you or anybody else ever solved this issue?