in florence2-webgpu/src/worker.js [47:79]
async function load() {
self.postMessage({
status: "loading",
data: "Loading model...",
});
// Load the pipeline and save it for future use.
const [model, tokenizer, processor] = await Florence2Singleton.getInstance(
(x) => {
// We also add a progress callback to the pipeline so that we can
// track model loading.
self.postMessage(x);
},
);
self.postMessage({
status: "loading",
data: "Compiling shaders and warming up model...",
});
// Dummy text and vision inputs
const text_inputs = tokenizer("a");
const pixel_values = full([1, 3, 768, 768], 0.0);
// Run model with dummy input to compile shaders
await model.generate({
...text_inputs,
pixel_values,
max_new_tokens: 1,
});
self.postMessage({ status: "ready" });
}