Open r4ghu opened 1 month ago
If you specify a progress_callback, it cannot be null, and should be a function.
// default empty function
static async getInstance(progress_callback = ()=>{}) {}
// default console log
static async getInstance(progress_callback = (x)=>console.log(x)) {}
Update - I got this working by explicitly setting the env.backends.onnx.wasm.wasmPaths
before initializing the model. Updated code that worked for me -
class GeneratorSingleton {
static model_id = 'Xenova/t5-small';
static model = null;
static tokenizer = null;
static async getInstance(progress_callback = (x) => console.log(x)) {
if (!this.tokenizer) {
this.tokenizer = AutoTokenizer.from_pretrained(this.model_id);
}
if (!this.model) {
env.backends.onnx.wasm.wasmPaths = 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.19.0-dev.20240521-068bb3d5ee/dist/';
env.backends.onnx.wasm.numThreads = 1;
this.model = AutoModelForSeq2SeqLM.from_pretrained(this.model_id, {
dtype: 'fp32',
device: 'webgpu',
progress_callback,
});
}
progress_callback({ status: 'ready' });
return Promise.all([this.tokenizer, this.model]);
}
}
System Info
v3
Chrome
MacOS
v22.1.0
React + Vite
Environment/Platform
Description
Hi, First of all thank you for the awesome work you are doing with transformers.js. It reduced my entry barrier to develop ML models for web applications and extensions. I am currently working on implementing a T5-small based text generation example and I am able to get it working with the following configuration -
Xenova/t5-small
2.0.0
When I try to modify the code to run with
v3
, I am facing the following issue when device set towebgpu
and dtype asfp32
-I am pretty sure
Xenova/t5-small
will run with transformers.js as I tested its performance using - WebGPU Embedding BenchmarkAny suggestions on how to implement the model loading and inference for T5-Small model will be really helpful. Thank you for your time in this matter.
Reproduction
Code to load the model