tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.48k stars 1.93k forks source link

WASM backend fails on recent versions of Edge/Chromimum #6752

Closed vladmandic closed 2 years ago

vladmandic commented 2 years ago

WASM backend fails on recent versions of Edge/Chromimum

Tested with

I don't know when issue first occured (it used to work), but now it fails on both release and canary versions

No issues with Chrome 106.0.5241.2 or Firefox 103.0.2

Actual issue is when attempting to set backend using tf.setBackend('wasm') it silently fails and uses first available backend.

Investigation

Attempting to use await tf.env().getAsync('WASM_HAS_MULTITHREAD_SUPPORT');
Returns false on Edge, but returns true on Chrome!

Attempting to use await tf.env().getAsync('WASM_HAS_SIMD_SUPPORT');
Results in exception error on Edge, but returns true on Chrome!

Uncaught (in promise) ReferenceError: WebAssembly is not defined
    at Object.evaluationFn (tfjs.esm.js:66241:27)
    at Environment.evaluateFlag (tfjs.esm.js:5450:40)
    at Environment.getAsync (tfjs.esm.js:5411:39)

And since tfjs-backend-wasm uses both flags on its init, it fails

Actual evalulation functions in src/tfjs-backend-wasm/src/flags_wasm.ts have try/catch block around WASM_HAS_SIMD_SUPPORT, but no exception handling around WASM_HAS_MULTITHREAD_SUPPORT - first thing is to add such a block

Proposed PR is in #6753

This results in at least sane behavior - TFJS reports warning message Aborted(no native wasm support detected) and continues working using next available backend

Actual root cause

There is a workaround - disable Use enhanced security for this site in Edge,
Then both flags return true and WASM backend works just fine

Per this Microsoft article, this feature

  1. Disables just-in-time (JIT) JavaScript compilation
  2. Enables OS protections such as Hardware-enforced Stack Protection and Arbitrary Code Guard (ACG).

And Enhanced Security feature is now enabled by default for any newly visited sites,
but allows full functionality if site is re-visited multiple times (don't know exactly how many visits are needed)

Bigger issue is that Microsoft pretty much disabled WebAssembly namespace if enhanced security is enabled - thats a really bad decision from MS, but not much I can do about that

I suggest that TFJS team opens a dialog with Edge team as this has pretty big consequences

Environment

vladmandic commented 2 years ago

any updates? this is a week old without anyone taking a look and the same with the PR #6753 that goes with it.

pyu10055 commented 2 years ago

@vladmandic We have reached out to the chrome WASM team trying to find out more about the best way to raise this issue with Edge team. cc @tlively

vladmandic commented 2 years ago

In case you're wondering on impact, even Microsoft's own VSCode for Web fails...

image
vladmandic commented 2 years ago

closing the issue as pr that detects wasm support has been merged. bigger issue on will edge keep blocking wasm on unverified sites remains, but that is beyond the scope of this issue.

google-ml-butler[bot] commented 2 years ago

Are you satisfied with the resolution of your issue? Yes No