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

ExternalException: Unsupported TypeMeta in ATen: nullptr (uninitialized) (please report this error) #1449

Open
EDGlittilelamb opened this issue Feb 16, 2025 · 2 comments
Labels
question Further information is requested

Comments

@EDGlittilelamb
Copy link

I was trying to apply a LSTM model to my game in unity.
LSTMModel = new LSTMModel(6, 512, 8); LSTMModel.load("Assets/Scripts/Brain/model_state_dict.pth");
It first raised a error that ArgumentException: Mismatched state_dict sizes: expected 14, but found 80 entries. Then I printed out the size of this model in vs code using python, and the size of the model was 14. It is the same size in C#.

I had no choice but to set the parameter inside the function <torch.load> to false
LSTMModel.load("Assets/Scripts/Brain/model_state_dict.pth",false);

Unfortunately, it raised another error that ExternalException: Unsupported TypeMeta in ATen: nullptr (uninitialized) (please report this error).

I'm grateful for any replies.

unity version:2021.3.43f1c1
TorchSharp: 0.105

@ozanMSFT ozanMSFT added the question Further information is requested label Feb 18, 2025
@ozanMSFT
Copy link
Contributor

Hey @EDGlittilelamb ;

From the given context; it seems like a problem regarding loading a model or model itself.

Could you please try to reproduce the issue with PyTorch and share your code for loading in Python?

Also, may I ask about your Operating System?

@EDGlittilelamb
Copy link
Author

Hey @EDGlittilelamb ;

From the given context; it seems like a problem regarding loading a model or model itself.

Could you please try to reproduce the issue with PyTorch and share your code for loading in Python?

Also, may I ask about your Operating System?

Thank you for replying! I have solved this problem. It is my fault that using this function
torch.save(model.state_dict(), 'model.pth')
to save my model in python. Model saved in this way can not be loaded by using the function 'torch.load()' in C#.

Instead, I save my model by
net = torch.jit.trace(model,torch.randn(1,1,6,dtype=torch.float32))
torch.jit.save(net,"./model.pth")
and load it by
jit.ScriptModule net; net = jit.load("Assets/Scripts/Brain/Brain.pth");

It works!

However, it still exists some problem in my project.
"Unloading broken assembly Assets/Packages/SkiaSharp.2.88.6/interactive-extensions/dotnet/SkiaSharp.DotNet.Interactive.dll, this assembly can cause crashes in the runtime
"
Because this error does not influence my project temporarily, I turn a blind eye to it.

My Operating System is windows.
TorchSharp version is 0.101.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants