Skip to content

Improvements when specifying a ModelLoader when adding a predictionenginepool to DI. #6618

Open

Description

@danielstegeman

Is your feature request related to a problem? Please describe.
Currently, it is possible to specify a custom model loader when adding a PredictionEnginePool to the servicecollection, as mentioned in this pull request #4393 . This is important in cases where you want to, for example, load a specific version of a model from something like Azure Blob Storage.

First of all, the official documentation makes no mention at all of this possibility. So this needs to be documented.

Secondly, when you want to add a model loader that needs access to the service provider, the AddPredictionEnginePool requires an implementationfactory with a lot of boilerplate, like so:

services.AddPredictionEnginePool<InputModel, OutputModel>(provider =>
        {
            
            IEnumerable<IConfigureOptions<PredictionEnginePoolOptions<InputModel, OutputModel>>>
                configureOptionsList =
                    new List<IConfigureOptions<PredictionEnginePoolOptions<InputModel, OutputModel>>>()
                    {
                        new ConfigureOptions<PredictionEnginePoolOptions<InputModel, OutputModel>>(options=>
                            options.ModelLoader = new AzureModelLoader(provider))
                    };
            
            IEnumerable<IPostConfigureOptions<PredictionEnginePoolOptions<InputModel, OutputModel>>>
                postConfigures =
                    new List<IPostConfigureOptions<PredictionEnginePoolOptions<InputModel, OutputModel>>>();
            
            var optionsfactory =
                new OptionsFactory<PredictionEnginePoolOptions<InputModel, OutputModel>>(
                    configureOptionsList,postConfigures);

            return new PredictionEnginePool<InputModel, OutputModel>(provider,
                provider.GetRequiredService<IOptions<MLOptions>>(), optionsfactory);
        });

It is also possible to add it through AddOptions like this:

services.AddOptions<PredictionEnginePoolOptions<InputModel, OutputModel>>().Configure(options =>
        {
            options.ModelLoader = new ModelLoader();
        });

But this does not allow access to the serviceprovider.

Describe the solution you'd like

  1. Document this feature.
  2. Add a method to configure the PredictionEnginePoolOptions with the serviceprovider as a parameter:
services.AddPredictionEnginePoolOptions<InputModel, OutputModel>((provider, options) =>
        {
            options.ModelLoader = new ModelLoader(provider);
        });

Describe alternatives you've considered
Using the AddOptions method.

Additional context
Add any other context or screenshots about the feature request here.

Activity

  1. ghost added
    untriagedNew issue has not been triaged
    on Apr 7, 2023
  2. michaelgsharp commented on Jan 23, 2024

    @michaelgsharp
    Contributor

    @JakeRadMSFT @zewditu @LittleLittleCloud are any of you familiar with this?

  3. added
    area-IntegrationIntegration with external frameworks, tools, and application platforms
    on Sep 8, 2026
  4. rosebyte commented on Sep 10, 2026

    @rosebyte
    Member

    triage: we will keep it as a feature request

  5. added this to the ML.NET Future milestone on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-IntegrationIntegration with external frameworks, tools, and application platformsenhancementNew feature or requestyellowmaintenance only

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions