dotnet / dotnet/machinelearning

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

Open
#6,618 2 comments 0 reactions 0 assignees View on GitHub
area-Integration enhancement
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

**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(provider =>
{

IEnumerable>>
configureOptionsList =
new List>>()
{
new ConfigureOptions>(options=>
options.ModelLoader = new AzureModelLoader(provider))
};

IEnumerable>>
postConfigures =
new List>>();

var optionsfactory =
new OptionsFactory>(
configureOptionsList,postConfigures);

return new PredictionEnginePool(provider,
provider.GetRequiredService>(), optionsfactory);
});
```
It is also possible to add it through `AddOptions` like this:
```
services.AddOptions>().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((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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.