transformers.js icon indicating copy to clipboard operation
transformers.js copied to clipboard

Error: no available backend found. ERR: [wasm] RangeError: Out of memory

Open jpcoder2 opened this issue 1 year ago • 11 comments

System Info

@huggingface/transformers 3.0.0-alpha.19, Mobile Safari, iOS 17.6.1

Environment/Platform

  • [X] Website/web-app
  • [ ] Browser extension
  • [ ] Server-side (e.g., Node.js, Deno, Bun)
  • [ ] Desktop app (e.g., Electron)
  • [ ] Other (e.g., VSCode extension)

Description

Getting the error "Error: no available backend found. ERR: [wasm] RangeError: Out of memory" in mobile Safari when trying to load model Xenova/clip-vit-base-patch16. This same model loads (albeit a bit unstable) under transformers.js v2. This code does work on desktop Chrome on MacOS.

Reproduction

pipeline("zero-shot-image-classification", "Xenova/clip-vit-base-patch16")

jpcoder2 avatar Oct 01 '24 02:10 jpcoder2

May or may not be related, but https://huggingface.co/spaces/webml-community/segment-anything-webgpu doesn't seem to work on mobile Safari either, but looks like it's using an older version of v3. Just wondering if v3 just generally doesn't work on iOS.

jpcoder2 avatar Oct 01 '24 02:10 jpcoder2

WebGPU isn't officially supported by Safari yet. Maybe you can try with its technical preview: https://webkit.org/blog/14879/webgpu-now-available-for-testing-in-safari-technology-preview/.

gyagp avatar Oct 01 '24 03:10 gyagp

I just tried that on Mobile Safari. Didn't seem to change anything. Same error.

So, with V3, are you saying WebGPU is the only engine available and it will not fall back to a CPU version if WebGPU is not available?

jpcoder2 avatar Oct 01 '24 04:10 jpcoder2

CPU is available in V3. auto-fallback has recently become an option, you have to set it to that though.

Set device to wasm in the inference settings.

flatsiedatsie avatar Oct 02 '24 04:10 flatsiedatsie

So setting "device" to "wasm" will make the transformers.js code try WebGPU first and then if that fails it will fall back to CPU or are you saying that my code would need to create the fallback code?

jpcoder2 avatar Oct 02 '24 14:10 jpcoder2

I tried this but am still getting the "Out of memory" error. Since the error includes "wasm" in it, I'm guessing it was already doing the auto fall back to "wasm". Did something change in the wasm engine that would cause this since it was working in v2?

jpcoder2 avatar Oct 02 '24 15:10 jpcoder2

Try "auto". Wasm sets it to cpu only.

flatsiedatsie avatar Oct 02 '24 16:10 flatsiedatsie

But on iOS will that fix the Out of memory problem since CPU is all that would be available?

jpcoder2 avatar Oct 02 '24 16:10 jpcoder2

After changing it to "auto" it doesn't seem to try and load the "wasm" version at all. Not even getting the out of memory error now so not really sure what it is doing, but not working either.

jpcoder2 avatar Oct 02 '24 16:10 jpcoder2

How is "auto" different than just not setting "device" to anything?

jpcoder2 avatar Oct 02 '24 16:10 jpcoder2

Looks like this may be an iOS Safari issue and only be fixed in iOS 18 which just came out so makes using v3 hard for me at the moment until that is more widely available. Odd though that this worked in iOS 17 with transformer.js V2.

https://github.com/microsoft/onnxruntime/issues/22086

jpcoder2 avatar Oct 02 '24 22:10 jpcoder2