Merge pull request #2495 from Risenafis/fix-change-model

Fix transformers model changes
This commit is contained in:
Cohee 2024-07-08 22:16:10 +03:00 committed by GitHub
commit db4fe14011
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 1 deletions

View File

@ -94,7 +94,11 @@ function getModelForTask(task) {
*/
async function getPipeline(task, forceModel = '') {
if (tasks[task].pipeline) {
return tasks[task].pipeline;
if (forceModel === '' || tasks[task].currentModel === forceModel) {
return tasks[task].pipeline;
}
console.log('Disposing transformers.js pipeline for for task', task, 'with model', tasks[task].currentModel);
await tasks[task].pipeline.dispose();
}
const cache_dir = path.join(process.cwd(), 'cache');
@ -103,6 +107,7 @@ async function getPipeline(task, forceModel = '') {
console.log('Initializing transformers.js pipeline for task', task, 'with model', model);
const instance = await pipeline(task, model, { cache_dir, quantized: tasks[task].quantized ?? true, local_files_only: localOnly });
tasks[task].pipeline = instance;
tasks[task].currentModel = model;
return instance;
}