Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Microsoft.Extensions.ML/PredictionEnginePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Microsoft.Extensions.Options;
using Microsoft.ML;
Expand All @@ -21,7 +22,7 @@ public class PredictionEnginePool<TData, TPrediction>
private readonly IOptionsFactory<PredictionEnginePoolOptions<TData, TPrediction>> _predictionEngineOptions;
private readonly IServiceProvider _serviceProvider;
private readonly PoolLoader<TData,TPrediction> _defaultEnginePool;
private readonly Dictionary<string, PoolLoader<TData, TPrediction>> _namedPools;
private readonly ConcurrentDictionary<string, PoolLoader<TData, TPrediction>> _namedPools;

public PredictionEnginePool(IServiceProvider serviceProvider,
IOptions<MLOptions> mlContextOptions,
Expand All @@ -38,7 +39,7 @@ public PredictionEnginePool(IServiceProvider serviceProvider,
_defaultEnginePool = new PoolLoader<TData, TPrediction>(_serviceProvider, defaultOptions);
}

_namedPools = new Dictionary<string, PoolLoader<TData, TPrediction>>();
_namedPools = new ConcurrentDictionary<string, PoolLoader<TData, TPrediction>>();
}

/// <summary>
Expand Down Expand Up @@ -100,7 +101,7 @@ public PredictionEngine<TData, TPrediction> GetPredictionEngine(string modelName
//Here we are in the world of named models where the model hasn't been built yet.
var options = _predictionEngineOptions.Create(modelName);
var pool = new PoolLoader<TData, TPrediction>(_serviceProvider, options);
_namedPools.Add(modelName, pool);
_namedPools.TryAdd(modelName, pool);
Comment thread
sharwell marked this conversation as resolved.
Outdated
Comment thread
sharwell marked this conversation as resolved.
Outdated
return pool.PredictionEnginePool.Get();
}

Expand Down