From c9d1b8a29297188b6a9f3cb4c97ecf70f68dbcc6 Mon Sep 17 00:00:00 2001 From: Jacky Jiang Date: Fri, 24 Jan 2025 18:29:08 +1100 Subject: [PATCH 1/2] tokenizer: only use padding for multiple inputs are received --- src/libs/EmbeddingEncoder.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/libs/EmbeddingEncoder.ts b/src/libs/EmbeddingEncoder.ts index 4683868..c953692 100644 --- a/src/libs/EmbeddingEncoder.ts +++ b/src/libs/EmbeddingEncoder.ts @@ -209,7 +209,7 @@ class EmbeddingEncoder { // Run tokenization const model_inputs = this.tokenizer(texts, { - padding: true, + padding: typeof texts !== "string", truncation: true, max_length: typeof max_length !== "undefined" && max_length > 0 @@ -334,6 +334,8 @@ class EmbeddingEncoder { `Model \`${model}\` is not supported. Supported models: ${this.supportModels.join(", ")}` ); } + const modelOpts = this.getModelByName(model); + const { max_length } = modelOpts; opts = { ...opts, ...(typeof opts.padding !== "boolean" ? { padding: true } : {}), @@ -343,8 +345,12 @@ class EmbeddingEncoder { }; return this.tokenizer(texts, { - padding: true, - truncation: true + padding: typeof texts !== "string", + truncation: true, + max_length: + typeof max_length !== "undefined" && max_length > 0 + ? max_length + : DEFAULT_MAX_LENGTH }); } } From 1f70046131d355534e108a94b1ce1e4f891d8d34 Mon Sep 17 00:00:00 2001 From: Jacky Jiang Date: Fri, 24 Jan 2025 18:30:54 +1100 Subject: [PATCH 2/2] set workerTaskTimeout in package.json start script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 77abac5..267a089 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "prebuild": "rimraf dist", "build": "tsc", "watch": "tsc -w", - "start": "npm run build && fastify start -T 60000 -l info dist/app.js", + "start": "npm run build && fastify start -T 60000 -l info dist/app.js -- --workerTaskTimeout 10000", "download-default-model": "node ./dist/loadDefaultModel.js", "dev": "npm run build && concurrently -k -p \"[{name}]\" -n \"TypeScript,App\" -c \"yellow.bold,cyan.bold\" \"npm:watch\" \"npm:dev:start\"", "dev:start": "fastify start --ignore-watch=.ts$ -w -l info -P dist/app.js",