Closed kicaj29 closed 5 months ago
If you make sure to dispose of the model at the end of your TestModelLoading
it will resolve the error.
(trainedModel as IDisposable).Dispose()
This error is coming from TorchSharp itself. I'm checking if the latest version of TorchSharp has this fixed. If not I'll raise an issue there, but other than making sure to dispose of your model when you are done with it there isnt much more we can do from this side.
Closing this issue for now, but I'll mention it in the TorchSharp issue when I create it.
This has actually been fixed already in the latest version of TorchSharp. Almost have ML.NET ready to update to use that version.
With the change you showed about my example works fine, thank you. It would be good if the trainedModel
would be implementing IDisposable
directly - then it would be obvious that Dispose
has to be called.
System Information (please complete the following information):
Describe the bug The following code throws exception:
System.InvalidOperationException: Tensor invalid -- empty handle.
whenmlContext.Model.Load
is called second time.To Reproduce Save model by calling
ctx.Model.Save
and next try to load this model twice - one by one usingmlContext.Model.Load
wheremlContext
are separate instances.Expected behavior It is possible to load second time the same model file when previous processing is finished.
Screenshots, Code, Sample Projects
csproj (these are the same version which are used here https://github.com/dotnet/machinelearning/blob/main/eng/Versions.props#L65-L66)
Source code which can be used to reproduce this problem: TextClassificationError.zip
Additional context n/a