Always dispose of pipeline for embeddings after use (#1048)
Browse files
src/lib/server/embeddingEndpoints/transformersjs/embeddingEndpoints.ts
CHANGED
@@ -18,12 +18,7 @@ class TransformersJSModelsSingleton {
|
|
18 |
|
19 |
if (modelPipelineInstance) {
|
20 |
const [, modelPipeline] = modelPipelineInstance;
|
21 |
-
|
22 |
-
// 80% chance to return the pipeline
|
23 |
-
if (Math.random() > 0.2) {
|
24 |
-
return modelPipeline;
|
25 |
-
}
|
26 |
-
// else we dispose of the pipeline to clear memory
|
27 |
await (await modelPipeline).dispose();
|
28 |
this.instances = this.instances.filter(([name]) => name !== modelName);
|
29 |
}
|
|
|
18 |
|
19 |
if (modelPipelineInstance) {
|
20 |
const [, modelPipeline] = modelPipelineInstance;
|
21 |
+
// dispose of the previous pipeline to clear memory
|
|
|
|
|
|
|
|
|
|
|
22 |
await (await modelPipeline).dispose();
|
23 |
this.instances = this.instances.filter(([name]) => name !== modelName);
|
24 |
}
|