Skip to content

PredictionEngineBase Dispose() also calls ITransformer.Dispose() #5945

@TyboVanderstraeten

Description

@TyboVanderstraeten

System Information (please complete the following information):

  • OS & Version: [e.g. Windows 10]
  • ML.NET Version: [e.g. ML.NET v1.6]
  • .NET Version: [e.g. .NET 5.0]

Describe the bug
In the PredictionEngineBase Dispose(), a call to ITransformer.Dispose() is made, making it impossible to use a cached model to perform predictions when creating the predictionengine in a using-statement. See line 142 -> https://github.com/dotnet/machinelearning/blob/main/src/Microsoft.ML.Data/Prediction/PredictionEngine.cs

To Reproduce
Steps to reproduce the behavior:

  1. Load your model into a global variable (simulate a cache).
  2. Create a method where you create a predictionEngine in a using-statement and call Predict()
  3. The second time you call that method, an AccessViolationException will be thrown due to the 'cached' model being disposed as well upon disposing the predictionEngine.

Expected behavior
The ITransformer.Dispose() is not being called inside the Dispose() of PredictionEngineBase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions