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
6 changes: 3 additions & 3 deletions packages/sdk/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"@qvac/registry-client": "^0.4.1",
"@qvac/transcription-parakeet": "^0.3.1",
"@qvac/transcription-whispercpp": "^0.6.1",
"@qvac/translation-nmtcpp": "^1.0.1",
"@qvac/translation-nmtcpp": "^2.0.1",
"@qvac/tts-onnx": "^0.8.2",
"fast-safe-stringify": "2.1.1",
"which-runtime": "^1.3.2",
Expand Down
56 changes: 20 additions & 36 deletions packages/sdk/server/bare/plugins/nmtcpp-translation/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nmtAddonLogging from "@qvac/translation-nmtcpp/addonLogging";
import TranslationNmtcpp, {
type TranslationNmtcppConfig,
type Loader,
type TranslationNmtcppFiles,
} from "@qvac/translation-nmtcpp";
import {
definePlugin,
Expand All @@ -19,10 +19,7 @@ import {
type ResolveResult,
} from "@/schemas";
import { createStreamLogger, registerAddonLogger } from "@/logging";
import { parseModelPath } from "@/server/utils";
import FilesystemDL from "@qvac/dl-filesystem";
import { ModelLoadFailedError } from "@/utils/errors-server";
import { asLoader } from "@/server/bare/utils/loader-adapter";
import { translate } from "@/server/bare/ops/translate";
import { attachModelExecutionMs } from "@/profiling/model-execution";

Expand Down Expand Up @@ -72,8 +69,6 @@ function createNmtModel(
pivotSrcVocabPath?: string,
pivotDstVocabPath?: string,
) {
const { dirPath, basePath } = parseModelPath(modelPath);
const loader = new FilesystemDL({ dirPath });
const logger = createStreamLogger(modelId, ModelType.nmtcppTranslation);
registerAddonLogger(modelId, ModelType.nmtcppTranslation, logger);

Expand All @@ -92,17 +87,13 @@ function createNmtModel(
topp,
} = nmtConfig;

const args = {
loader: asLoader<Loader>(loader),
logger,
modelName: basePath,
diskPath: dirPath,
opts: { stats: true },
params: {
mode,
srcLang: from,
dstLang: to,
},
const files: TranslationNmtcppFiles = {
model: modelPath,
...(srcVocabPath && { srcVocab: srcVocabPath }),
...(dstVocabPath && { dstVocab: dstVocabPath }),
...(pivotModelPath && { pivotModel: pivotModelPath }),
...(pivotSrcVocabPath && { pivotSrcVocab: pivotSrcVocabPath }),
...(pivotDstVocabPath && { pivotDstVocab: pivotDstVocabPath }),
};

const generationParams = {
Expand All @@ -117,38 +108,31 @@ function createNmtModel(
};

const config: TranslationNmtcppConfig = {
modelType: TranslationNmtcpp.ModelTypes[engine],
modelType: TranslationNmtcpp.ModelTypes[engine as keyof typeof TranslationNmtcpp.ModelTypes],
...generationParams,
...(nmtConfig.engine === "Bergamot" && {
...(srcVocabPath && { srcVocabPath }),
...(dstVocabPath && { dstVocabPath }),
...(nmtConfig.normalize !== undefined && {
normalize: nmtConfig.normalize,
}),
// Add pivot model configuration if present
...(nmtConfig.pivotModel && {
bergamotPivotModel: (() => {
pivotConfig: (() => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {modelSrc, dstVocabSrc, srcVocabSrc, ...config} = nmtConfig.pivotModel
const { dirPath, basePath } = parseModelPath(pivotModelPath!);
return {
loader: asLoader<Loader>(new FilesystemDL({ dirPath })),
modelName: basePath,
diskPath: dirPath,
config: {
...config,
srcVocabPath: pivotSrcVocabPath,
dstVocabPath: pivotDstVocabPath
}
};
const { modelSrc, dstVocabSrc, srcVocabSrc, ...pivotGenConfig } = nmtConfig.pivotModel;
return pivotGenConfig;
})(),
}),
}),
};

const model = new TranslationNmtcpp(args, config);
const model = new TranslationNmtcpp({
files,
params: { mode, srcLang: from, dstLang: to },
config,
logger,
opts: { stats: true },
});

return { model, loader };
return { model, loader: null };
}

export const nmtPlugin = definePlugin({
Expand Down
Loading