Skip to content
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
7 changes: 5 additions & 2 deletions src/Machine/src/Serval.Machine.Shared/Services/BuildJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ public virtual Task RunAsync(
string engineId,
string buildId,
string? buildOptions,
string? model,
CancellationToken cancellationToken
)
{
return RunAsync(engineId, buildId, null, buildOptions, cancellationToken);
return RunAsync(engineId, buildId, null, buildOptions, model, cancellationToken);
}
}

Expand All @@ -40,6 +41,7 @@ public virtual async Task RunAsync(
string buildId,
TData data,
string? buildOptions,
string? model,
CancellationToken cancellationToken
)
{
Expand All @@ -53,7 +55,7 @@ CancellationToken cancellationToken
return;
}

await DoWorkAsync(engineId, buildId, data, buildOptions, cancellationToken);
await DoWorkAsync(engineId, buildId, data, buildOptions, model, cancellationToken);
}
catch (OperationCanceledException e)
{
Expand Down Expand Up @@ -143,6 +145,7 @@ protected abstract Task DoWorkAsync(
string buildId,
TData data,
string? buildOptions,
string? model,
CancellationToken cancellationToken
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public async Task<bool> StartBuildJobAsync(
stage,
data,
buildOptions,
model,
cancellationToken
);
try
Expand All @@ -97,6 +96,7 @@ public async Task<bool> StartBuildJobAsync(
)
),
u =>
{
u.Set(
e => e.CurrentBuild,
new Build
Expand All @@ -112,7 +112,8 @@ public async Task<bool> StartBuildJobAsync(
JobData = jobData,
ExecutionData = new BuildExecutionData(),
}
),
);
},
cancellationToken: cancellationToken
);
if (engine is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public async Task DeleteEngineAsync(string engineId, CancellationToken cancellat
BuildStage stage,
object? data = null,
string? buildOptions = null,
string? model = null,
CancellationToken cancellationToken = default
)
{
Expand All @@ -58,7 +57,6 @@ public async Task DeleteEngineAsync(string engineId, CancellationToken cancellat
_options[engineType].ModelType,
stage,
buildOptions,
model,
cancellationToken
);
string jobId = await _clearMLService.CreateTaskAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ await UpdateTrainJobStatus(
(int)GetMetric(task, SummaryMetric, TrainCorpusSizeVariant),
GetMetric(task, SummaryMetric, ConfidenceVariant),
engine.CurrentBuild.Options,
engine.CurrentBuild.Model,
cancellationToken
);
if (canceling)
Expand Down Expand Up @@ -285,6 +286,7 @@ private async Task<bool> TrainJobCompletedAsync(
int corpusSize,
double confidence,
string? buildOptions,
string? model,
CancellationToken cancellationToken
)
{
Expand All @@ -298,6 +300,7 @@ CancellationToken cancellationToken
BuildStage.Postprocess,
(corpusSize, confidence),
buildOptions,
model,
cancellationToken: cancellationToken
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public interface IBuildJobRunner<TEngine>
BuildStage stage,
object? data = null,
string? buildOptions = null,
string? model = null,
CancellationToken cancellationToken = default
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Task<string> CreateJobScriptAsync(
string modelType,
BuildStage stage,
string? buildOptions = null,
string? model = null,
CancellationToken cancellationToken = default
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Task RunAsync(
BuildStage stage,
string? jobData,
string? buildOptions,
string? model,
CancellationToken cancellationToken
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public Task CreateEngineAsync(
BuildStage stage,
object? data = null,
string? buildOptions = null,
string? model = null,
CancellationToken cancellationToken = default
)
{
Expand Down Expand Up @@ -215,7 +214,7 @@ private void EnqueueRecoveredJob(string engineId, Build build, EngineType engine
if (
_pendingJobs.TryAdd(
build.JobId,
new JobInfo(engineId, build.BuildId, engineType, build.Stage, build.JobData, build.Options)
new JobInfo(engineId, build.BuildId, engineType, build.Stage, build.JobData, build.Options, build.Model)
)
)
{
Expand Down Expand Up @@ -250,7 +249,8 @@ CancellationToken cancellationToken
engine.Type,
build.Stage,
build.JobData,
build.Options
build.Options,
build.Model
)
)
)
Expand Down Expand Up @@ -316,6 +316,7 @@ await factory.RunAsync(
info.Stage,
info.JobData,
info.BuildOptions,
info.Model,
cts.Token
);
}
Expand All @@ -336,6 +337,7 @@ private record JobInfo(
EngineType EngineType,
BuildStage Stage,
string? JobData,
string? BuildOptions
string? BuildOptions,
string? Model
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected override async Task DoWorkAsync(
string buildId,
IReadOnlyList<ParallelCorpusContract> data,
string? buildOptions,
string? model,
CancellationToken cancellationToken
)
{
Expand All @@ -57,6 +58,7 @@ await UpdateBuildExecutionData(
engine.SourceLanguage,
engine.TargetLanguage,
isNonPersistedTranslationEngine,
model ?? "unknown",
data,
cancellationToken
);
Expand All @@ -79,6 +81,7 @@ await UpdateBuildExecutionData(
buildId,
BuildStage.Train,
buildOptions: buildOptions,
model: model,
cancellationToken: cancellationToken
);
if (canceling)
Expand All @@ -92,6 +95,7 @@ protected abstract Task UpdateBuildExecutionData(
string sourceLanguageTag,
string targetLanguageTag,
bool isNonPersistedTranslationEngine,
string modelName,
IReadOnlyList<ParallelCorpusContract> parallelCorpora,
CancellationToken cancellationToken
);
Expand Down Expand Up @@ -134,8 +138,8 @@ protected virtual IReadOnlyList<DiagnosticContract> GetDiagnostics(
bool sourceLanguageHasNativeSupport,
bool targetLanguageHasNativeSupport,
bool isNonPersistedTranslationEngine,
string modelName,
IReadOnlyList<ParallelCorpusContract> parallelCorpora
IReadOnlyList<ParallelCorpusContract> parallelCorpora,
string? modelName = null
)
{
List<DiagnosticContract> diagnostics = [];
Expand Down

This file was deleted.

8 changes: 8 additions & 0 deletions src/Machine/src/Serval.Machine.Translation/Models/Models.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Serval.Machine.Translation.Models;

public static class Models
{
public const string Nllb = "nllb";
public const string Nllb600m = "nllb-600m";
public const string NllbTesting = "nllb-testing";
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public async Task RunAsync(
BuildStage stage,
string? jobData,
string? buildOptions,
string? model,
CancellationToken cancellationToken
)
{
Expand All @@ -38,11 +39,11 @@ CancellationToken cancellationToken
case BuildStage.Preprocess:
var preprocessJob = ActivatorUtilities.CreateInstance<EchoPreprocessBuildJob>(serviceProvider);
var corpora = JsonSerializer.Deserialize<List<ParallelCorpusContract>>(jobData!, SerializerOptions)!;
await preprocessJob.RunAsync(engineId, buildId, corpora, buildOptions, cancellationToken);
await preprocessJob.RunAsync(engineId, buildId, corpora, buildOptions, model, cancellationToken);
break;
case BuildStage.Train:
var trainJob = ActivatorUtilities.CreateInstance<EchoTrainingBuildJob>(serviceProvider);
await trainJob.RunAsync(engineId, buildId, null, buildOptions, cancellationToken);
await trainJob.RunAsync(engineId, buildId, null, buildOptions, model, cancellationToken);
break;
case BuildStage.Postprocess:
var postprocessJob = ActivatorUtilities.CreateInstance<EchoPostprocessBuildJob>(serviceProvider);
Expand All @@ -52,6 +53,7 @@ await postprocessJob.RunAsync(
buildId,
(postData.TrainCount, postData.Confidence),
buildOptions,
model,
cancellationToken
);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protected override async Task DoWorkAsync(
string buildId,
(int, double) data,
string? buildOptions,
string? model,
CancellationToken cancellationToken
)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ protected override async Task UpdateBuildExecutionData(
string sourceLanguageTag,
string targetLanguageTag,
bool isNonPersistedTranslationEngine,
string modelName,
IReadOnlyList<ParallelCorpusContract> parallelCorpora,
CancellationToken cancellationToken
)
{
string modelName =
(await Engines.GetAsync(e => e.EngineId == engineId, cancellationToken))?.CurrentBuild?.Model?.ToString()
?? "Unknown";
IReadOnlyList<DiagnosticContract> diagnostics = GetDiagnostics(
stats.TrainCount,
stats.InferenceCount,
Expand All @@ -48,7 +46,6 @@ CancellationToken cancellationToken
sourceLanguageHasNativeSupport: true,
targetLanguageHasNativeSupport: true,
isNonPersistedTranslationEngine,
modelName,
parallelCorpora
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ protected override async Task DoWorkAsync(
string buildId,
object? data,
string? buildOptions,
string? model,
CancellationToken cancellationToken
)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ await engines.UpdateAsync(
);
}

public async Task StartBuildAsync(
public async Task<StartBuildContract> StartBuildAsync(
string engineId,
string buildId,
IReadOnlyList<ParallelCorpusContract> corpora,
Expand All @@ -84,12 +84,13 @@ public async Task StartBuildAsync(
BuildStage.Preprocess,
corpora,
options,
model,
cancellationToken: cancellationToken
);
// If there is a pending/running build, then no need to start a new one.
if (building)
throw new ConflictException();

return new() { Model = model };
}

public Task<string?> CancelBuildAsync(string engineId, CancellationToken cancellationToken = default) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public async Task<string> CreateJobScriptAsync(
string modelType,
BuildStage stage,
string? buildOptions = null,
string? model = null,
CancellationToken cancellationToken = default
)
{
Expand All @@ -33,19 +32,6 @@ public async Task<string> CreateJobScriptAsync(
string folder = sharedFileUri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
_languageTagService.ConvertToFlores200Code(engine.SourceLanguage, out string srcLang);
_languageTagService.ConvertToFlores200Code(engine.TargetLanguage, out string trgLang);
if (buildOptions != null && model != null)
{
try
{
JsonNode? buildOptionsJsonNode = JsonNode.Parse(buildOptions);
if (buildOptionsJsonNode != null && buildOptionsJsonNode is JsonObject buildOptionsJsonObject)
buildOptionsJsonObject["parent_model_name"] = GetFullModelName(model);
}
catch (Exception e)
{
throw new InvalidOperationException($"Unable to parse field build options : {e.Message}", e);
}
}
return "from machine.jobs.build_nmt_engine import run\n"
+ "args = {\n"
+ $" 'model_type': '{modelType}',\n"
Expand All @@ -68,15 +54,4 @@ public async Task<string> CreateJobScriptAsync(
throw new ArgumentException("Unknown build stage.", nameof(stage));
}
}

private static string GetFullModelName(string model)
{
return model switch
{
Models.Models.Nllb => "facebook/nllb-200-distilled-1.3B",
Models.Models.Nllb600m => "facebook/nllb-200-distilled-600M",
Models.Models.NllbTesting => "hf-internal-testing/tiny-random-nllb",
_ => throw new ArgumentException($"Unknown base model {model}."),
};
}
}
Loading
Loading