Problem consisting of Pyinstaller and Pytorch

username: DavidLin
cooked: <p>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.</p>
<p>I am puzzled, because I run normally under Anaconda5.2 environment (Python3.7)</p>
<p>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)<br>
Here is my simple code:</p>
<pre><code class="lang-auto">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()
</code></pre>
<p>Can u be my superhero???<br>
Plus:My computer configuration<br>
Operation System: Windows Server 2008 R2<br>
CPU：Core i7-10870H@2.20GHz<br>
GPU: NVIDIA RTX 3060<br>
ERROR：<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/9/b/9b480b11be8b3c6a17ac48968978da431abec6c2.png" data-download-href="https://discuss.pytorch.org/uploads/default/9b480b11be8b3c6a17ac48968978da431abec6c2" title="微信图片_20210823201001"><img src="https://discuss.pytorch.org/uploads/default/original/3X/9/b/9b480b11be8b3c6a17ac48968978da431abec6c2.png" alt="微信图片_20210823201001" data-base62-sha1="m9GmjfWC5M14DMPUe4tIlESEAAq" width="690" height="124" data-dominant-color="545860"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">微信图片_20210823201001</span><span class="informations">693×125 5.15 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: gasgallo
cooked: <p>Hi,</p>
<p>did you or anybody else ever solved this issue?</p>