Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyTorch: Missing node relationships #939

Closed
zdaiot opened this issue Aug 3, 2022 · 4 comments
Closed

PyTorch: Missing node relationships #939

zdaiot opened this issue Aug 3, 2022 · 4 comments

Comments

@zdaiot
Copy link

zdaiot commented Aug 3, 2022

Hello, I recently found that the latest version opens the pth model directly, and I can't see the node connection relationship.
But some of the old versions are fine, so I want to go back to tag 4.x, but I can't find the corresponding tag information. Do you have any information about tag?

@lutzroeder lutzroeder changed the title Question about tag PyTorch: Missing node relationships Aug 3, 2022
@lutzroeder
Copy link
Owner

@zdaiot can you share a sample file to illustrate the issue and regression?

git log --oneline --grep="Update to 4." to find commits for previous versions.

@zdaiot
Copy link
Author

zdaiot commented Aug 4, 2022

@lutzroeder
Thanks a lot~

Example:

import torch.nn as nn
import torch.nn.functional as F
import torch
 
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 
 
class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(in_channels=1, out_channels=10, kernel_size=5)
        self.conv2 = nn.Conv2d(10, 20, 5)
        self.conv3 = nn.Conv2d(20, 40, 3)
        self.mp = nn.MaxPool2d(2)
        self.mp1 = nn.MaxPool2d(2)
        self.fc1 = nn.Linear(2560, 512)
        self.fc2 = nn.Linear(512, 10)
 
    def forward(self, x):
        in_size = x.size(0)
        x = F.relu(self.mp(self.conv1(x)))
        x = F.relu(self.mp(self.conv2(x)))
        x = F.relu(self.mp1(self.conv3(x)))
        x = x.view(in_size, -1)
        x = self.fc1(x)
        x = self.fc2(x)
        return F.log_softmax(x, dim=1)
 
 
model = Net().to(device)
torch.save(model, './model_para_new.pth')
torch.save(model, './model_para_old.pth', _use_new_zipfile_serialization=False)

Whether it is model_para_new or model_para_old, the previous version can get connected nodes, but the new version can only get nodes.

You can get the model file from the following compressed file

model.zip

Thanks again~

@zdaiot
Copy link
Author

zdaiot commented Aug 4, 2022

Hello, I found that although the old version can show the connection relationship, it seems to be wrong.

In addition, when using torch.save (model,'. / model_para_old.pth', _ use_new_zipfile_serialization=False) to save the whole model, the definition source code of the model is stored in the model file. Can we use this to analyze the relationship between nodes?

@lutzroeder
Copy link
Owner

Duplicate of #720

@lutzroeder lutzroeder marked this as a duplicate of #720 Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants