Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finds the best run for a given experiment. #75

Merged
merged 3 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion src/MLOps.NET/IMLLifeCycleManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using MLOps.NET.Entities.Entities;
using System;
using System.Threading.Tasks;

namespace MLOps.NET
Expand Down Expand Up @@ -53,5 +54,13 @@ public interface IMLLifeCycleManager
/// <param name="filePath">Absolute or relative path to the model</param>
/// <returns></returns>
Task UploadModelAsync(Guid runId, string filePath);

/// <summary>
/// Gets the best run for an experiment based on a metric for e.g "Accuracy"
/// </summary>
/// <param name="experimentId"></param>
/// <param name="metricName"></param>
/// <returns></returns>
IRun GetBestRun(Guid experimentId, string metricName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a part of IExperiment?
It is not a lifecycle method.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shanranm that's correct, another way is for it to live on the Experiment depending on if you prefer light entities or a more DTO style entity. I think in this case it belongs on the lifecycle context mostly because this will be a method one calls at the end of a training run to determine if this run is good enough to bother uploading an artifact/model. If it's not better than anything previously we may want to save storage space and skip the upload step. I recognize that it's a matter of taste though :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going with lighter entities then this looks good! 👍

}
}
16 changes: 15 additions & 1 deletion src/MLOps.NET/MLLifeCycleManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MLOps.NET.Storage;
using MLOps.NET.Entities.Entities;
using MLOps.NET.Storage;
using System;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -71,6 +72,19 @@ public async Task UploadModelAsync(Guid runId, string filePath)
await ModelRepository.UploadModelAsync(runId, filePath);
}

///<inheritdoc/>
public IRun GetBestRun(Guid experimentId, string metricName)
{
EnsureStorageProviderConfigured();
var allRuns = MetaDataStore.GetRuns(experimentId);
var bestRunId = allRuns.SelectMany(r => r.Metrics)
.Where(m => m.MetricName.ToLowerInvariant() == metricName.ToLowerInvariant())
.OrderByDescending(m => m.Value)
AnoojNair marked this conversation as resolved.
Show resolved Hide resolved
.First().RunId;

return allRuns.FirstOrDefault(r => r.Id == bestRunId);
}

///<inheritdoc/>
private void EnsureStorageProviderConfigured()
{
Expand Down