tracel-ai / burn

Burn is a new comprehensive dynamic Deep Learning Framework built using Rust with extreme flexibility, compute efficiency and portability as its primary goals.
https://burn.dev
Apache License 2.0
7.7k stars 370 forks source link

MNIST Inference Web example not working #1190

Open thekevinscott opened 5 months ago

thekevinscott commented 5 months ago

Describe the bug The MNIST Inference web example is not working. It appears to be trying to load pkg/mnist_inference_web.js but no such file exists.

To Reproduce

cd examples/mnist-inference-web/
./build-for-web.sh wgpu
./run-server.sh

Expected behavior I expect the example to work.

Screenshots

Screenshot 2024-01-30 at 6 38 07 AM

Desktop (please complete the following information):

thekevinscott commented 5 months ago
./build-for-web.sh ndarray

appears to work, but introduces new errors into the console:

Screenshot 2024-01-30 at 6 40 48 AM
mnist_inference_web.js:315 panicked at /Users/thekevinscott/code/burn/burn-core/src/record/memory.rs:39:85:
called `Result::unwrap()` on an `Err` value: Utf8 { inner: Utf8Error { valid_up_to: 38, error_len: Some(1) } }

Stack:

Error
    at imports.wbg.__wbg_new_abda76e883ba8a5f (http://localhost:8000/pkg/mnist_inference_web.js:299:21)
    at http://localhost:8000/pkg/mnist_inference_web_bg.wasm:wasm-function[187]:0x4c6cb
    at http://localhost:8000/pkg/mnist_inference_web_bg.wasm:wasm-function[237]:0x51717
    at http://localhost:8000/pkg/mnist_inference_web_bg.wasm:wasm-function[206]:0x4d414
    at http://localhost:8000/pkg/mnist_inference_web_bg.wasm:wasm-function[107]:0x39ce6
    at http://localhost:8000/pkg/mnist_inference_web_bg.wasm:wasm-function[125]:0x477a5
    at http://localhost:8000/pkg/mnist_inference_web_bg.wasm:wasm-function[265]:0x51bbb
    at __wbg_adapter_18 (http://localhost:8000/pkg/mnist_inference_web.js:75:10)
    at real (http://localhost:8000/pkg/mnist_inference_web.js:60:20)

Uncaught RuntimeError: unreachable
    at mnist_inference_web_bg.wasm:0x4c7de
    at mnist_inference_web_bg.wasm:0x51717
    at mnist_inference_web_bg.wasm:0x4d414
    at mnist_inference_web_bg.wasm:0x39ce6
    at mnist_inference_web_bg.wasm:0x477a5
    at mnist_inference_web_bg.wasm:0x51bbb
    at __wbg_adapter_18 (mnist_inference_web.js:75:10)
    at real (mnist_inference_web.js:60:20)

Uncaught Error: recursive use of an object detected which would lead to unsafe aliasing in rust
    at imports.wbg.__wbindgen_throw (mnist_inference_web.js:321:15)
    at mnist_inference_web_bg.wasm:0x5229a
    at mnist_inference_web_bg.wasm:0x522b6
    at mnist_inference_web_bg.wasm:0x4516a
    at mnist_inference_web_bg.wasm:0x477a5
    at mnist_inference_web_bg.wasm:0x51bbb
    at __wbg_adapter_18 (mnist_inference_web.js:75:10)
    at real (mnist_inference_web.js:60:20)
ericcarmi commented 5 months ago

I saw the same thing with ndarray, I was able to fix it by re-creating the model in the mnist example and copying model.bin to this example. Maybe something to do with the different cpu architecture the models are created on?

I cannot get wgpu to work, but I see a different error, and also different errors in different browsers. I enabled the features for webgpu and webassembly in Chrome and Brave, but wondering if there are some non-obvious options that also need to be enabled.

error in chrome: panicked at 'calledOption::unwrap()on aNonevalue', /Users/eric/Downloads/burn/burn-wgpu/src/compute/base.rs:120

error in brave: panicked at 'An home directory should exist', burn-compute/src/tune/tune_cache.rs:25

The home directory definitely exists, so I don't know what is going on there, especially since the ndarray example works. I tried enabling the Shared GPUImageDecodeCache browser flag, along with rasterization, but still see the same error.

nathanielsimard commented 4 months ago

@ericcarmi Maybe we need to update the record. With the bin recorder, versions can be problematic. Testing with wgpu isn't trivial since not all platform support WebGPU.

antimora commented 4 months ago

We need to review to see if the model changed. If the model does not match the record, you'll have a mismatch. I propose we store a string representation of the record as part of the metadata.

jacobdineen commented 3 months ago

Yeah, that was it. Retraining the model worked w/ ndarray backend image

Unable to get the wgpu backend working on chrome following these steps: https://github.com/tensorflow/tfjs/issues/8065#issuecomment-1808785524

image

iSuslov commented 2 months ago

@ericcarmi Maybe we need to update the record. With the bin recorder, versions can be problematic. Testing with wgpu isn't trivial since not all platform support WebGPU.

Isn't a headless chrome + puppeter a solution? https://developer.chrome.com/blog/supercharge-web-ai-testing Seems like a good start.

ActuallyHappening commented 1 month ago

Example doesn't compile currently, since the import location and signature of init_async (for the Wgpu backend) changed

nathanielsimard commented 1 month ago

I created a PR to fix some issues with the wasm examples: #1824