in src/nodes/client/background-removal.ts [34:73]
static async getInstance(
modelId: string,
quantized: boolean,
device: DevicesType,
progress_callback?: ProgressCallbackFunction
) {
const revision = modelId.split("@")[1] || "main";
modelId = modelId.split("@")[0];
const key = `${modelId}${
quantized ? "_quantized" : ""
}_${device}_${revision}`;
if (!(key in this.instance)) {
console.info(
"Creating model instance. Model not loaded yet, modelId:",
modelId,
"Device",
device
);
const model = AutoModel.from_pretrained(modelId, {
// Do not require config.json to be present in the repository
quantized: device === Devices.webgpu ? false : quantized,
device: device,
revision: revision,
});
const processor = await AutoProcessor.from_pretrained(modelId, {
revision: revision,
});
this.instance[key] = Promise.all([model, processor]);
// TODO: use progress callback
} else {
console.info(
"Model instance already created for modelId:",
modelId,
"Device",
device
);
}
return this.instance[key];
}