I try to create a simple Mlp model without train, and then use torch.save to save the model parameters (they are random values which can be checked by print(param_tensor,‘\t’,model.state_dict()[param_tensor])), so in fact, I only save a lots of random values, and it is not a tuned parameters?
PS: I also try to open the saved data mlp-simple1.pth by vim, but it only shows a bunch of garbled characters.
z00443407@llvm:~/source/test/simple_mlp$ cat save_model1.py
import torch
from torch import nn
import torch_mlir
name : str
class MlpModel(torch.nn.Module):
def __init__(self):
super(MlpModel, self).__init__()
self.net = nn.Sequential(nn.Flatten(),
nn.Linear(784, 256),
nn.ReLU(),
nn.Linear(256, 10))
def forward(self, x):
return self.net(x)
# 保存模型
model = MlpModel()
def save_model():
path = "./mlp-simple1.pth"
for param_tensor in model.state_dict():
print(param_tensor,'\t',model.state_dict()[param_tensor].size())
# print(param_tensor,'\t',model.state_dict()[param_tensor]) # Random value
torch.save(model.state_dict(), path)
save_model()