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

Percent complete #52

Closed
wants to merge 5 commits into from
Closed
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
25 changes: 23 additions & 2 deletions src/SIL.Machine.AspNetCore/Services/ClearMLNmtEngineBuildJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ CancellationToken cancellationToken
{
clearMLTaskId = clearMLTask.Id;
}

ProgressStatus previousStatus = new();
int lastIteration = 0;
while (true)
{
Expand Down Expand Up @@ -109,10 +109,31 @@ or ClearMLTaskStatus.Completed
switch (clearMLTask.Status)
{
case ClearMLTaskStatus.InProgress:
float inferencePercentComplete = await _clearMLService.GetInferencePercentCompleteAsync(
clearMLTaskId
);
ProgressStatus currentStatus =
new(
clearMLTask.LastIteration,
(
inferencePercentComplete > 0.0f
? 90.0f
: 90.0f * (clearMLTask.LastIteration / (float)_options.CurrentValue.MaxSteps)
)
+ 10.0f * (inferencePercentComplete / 100.0f)
);
if (!previousStatus.Equals(currentStatus))
{
await _platformService.UpdateBuildStatusAsync(buildId, currentStatus);
previousStatus = currentStatus;
}
lastIteration = clearMLTask.LastIteration;
break;
case ClearMLTaskStatus.Completed:
currentStatus = new(clearMLTask.LastIteration, 100.0);
if (lastIteration != clearMLTask.LastIteration)
{
await _platformService.UpdateBuildStatusAsync(buildId, clearMLTask.LastIteration);
await _platformService.UpdateBuildStatusAsync(buildId, currentStatus);
lastIteration = clearMLTask.LastIteration;
}
break;
Expand Down
33 changes: 33 additions & 0 deletions src/SIL.Machine.AspNetCore/Services/ClearMLService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,39 @@ public async Task<IReadOnlyDictionary<string, double>> GetTaskMetricsAsync(
return results;
}

private async Task<string?> GetTaskMetricAsync(
string taskId,
string metricName,
string variantName,
CancellationToken cancellationToken = default
)
{
var body = new JsonObject { ["id"] = taskId };
JsonObject? result = await CallAsync("tasks", "get_by_id_ex", body, cancellationToken);
var tasks = (JsonArray?)result?["data"]?["tasks"];
if (tasks is null || tasks.Count == 0)
return null;
JsonObject task = (JsonObject)tasks[0]!;
//ClearML represents metrics and values of a hash (using MD5) map of an array of
//hash(metric_name) each with a subarray of hash(variant_name) each with a metric
//object containing the value.
string metricNameHash,
variantNameHash;
using (var md5 = MD5.Create())
{
metricNameHash = Convert.ToHexString(md5.ComputeHash(Encoding.ASCII.GetBytes(metricName))).ToLower();
variantNameHash = Convert.ToHexString(md5.ComputeHash(Encoding.ASCII.GetBytes(variantName))).ToLower();
}
return (string?)task?["last_metrics"]?[metricNameHash]?[variantNameHash]?["value"];
}

public async Task<float> GetInferencePercentCompleteAsync(string id, CancellationToken cancellationToken = default)
{
return float.Parse(
await GetTaskMetricAsync(id, "inference_percent_complete", "inference_percent_complete") ?? "0.0"
);
}

private async Task<ClearMLTask?> GetTaskAsync(JsonObject body, CancellationToken cancellationToken = default)
{
body["only_fields"] = new JsonArray(
Expand Down
1 change: 1 addition & 0 deletions src/SIL.Machine.AspNetCore/Services/IClearMLService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Task<IReadOnlyDictionary<string, double>> GetTaskMetricsAsync(
string id,
CancellationToken cancellationToken = default
);
Task<float> GetInferencePercentCompleteAsync(string id, CancellationToken cancellationToken = default);
}
1 change: 1 addition & 0 deletions src/sentencepiece4cbuild/_deps/sentencepiece-src
Submodule sentencepiece-src added at d8711f
Loading