Don't automatically attempt to load webgl backend
See original GitHub issueTo get help from the community, check out our Google group.
TensorFlow.js version
0.12.3
Browser version
Node.js 10.6.0
Describe the problem or feature request
When I run a simple example with tfjs and tjfs-node in my terminal, I get warnings about tfjs failing to register the webgl backend. But I don’t care about that, I only want the node/cpu backend. Is there a way to make tfjs not attempt to register the webgl backend, or, to not throw those warnings/errors?
Code to reproduce the bug / link to feature request
import * as tf from '@tensorflow/tfjs';
// Node CPU backend
import '@tensorflow/tfjs-node';
...
const sample: tf.Tensor1D = tf.tensor1d(new Array(5));
...
Errors:
console.warn node_modules/@tensorflow/tfjs-core/dist/environment.js:186
Registration of backend webgl failed
console.warn node_modules/@tensorflow/tfjs-core/dist/environment.js:187
Error: WebGL is not supported on this device
at new MathBackendWebGL (/myrepo/node_modules/@tensorflow/tfjs-core/src/kernels/backend_webgl.ts:392:13)
at /myrepo/node_modules/@tensorflow/tfjs-core/src/kernels/backend_webgl.ts:1316:22
at Environment.Object.<anonymous>.Environment.registerBackend (/myrepo/node_modules/@tensorflow/tfjs-core/src/environment.ts:367:23)
at Object.<anonymous> (/myrepo/node_modules/@tensorflow/tfjs-core/src/kernels/backend_webgl.ts:1315:7)
at Runtime._execModule (/myrepo/node_modules/jest-runtime/build/index.js:694:13)
at Runtime.requireModule (/myrepo/node_modules/jest-runtime/build/index.js:376:14)
at Runtime.requireModuleOrMock (/myrepo/node_modules/jest-runtime/build/index.js:463:19)
at Object.<anonymous> (/myrepo/node_modules/@tensorflow/tfjs-core/src/index.ts:21:1)
at Runtime._execModule (/myrepo/node_modules/jest-runtime/build/index.js:694:13)
at Runtime.requireModule (/myrepo/node_modules/jest-runtime/build/index.js:376:14)
at Runtime.requireModuleOrMock (/myrepo/node_modules/jest-runtime/build/index.js:463:19)
at Object.<anonymous> (/myrepo/node_modules/@tensorflow/tfjs/src/index.ts:18:1)
at Runtime._execModule (/myrepo/node_modules/jest-runtime/build/index.js:694:13)
at Runtime.requireModule (/myrepo/node_modules/jest-runtime/build/index.js:376:14)
at Runtime.requireModuleOrMock (/myrepo/node_modules/jest-runtime/build/index.js:463:19)
at Object.<anonymous> (/myrepo/guide/optimizers/CrossEntropy.ts:10:1)
at Runtime._execModule (/myrepo/node_modules/jest-runtime/build/index.js:694:13)
at Runtime.requireModule (/myrepo/node_modules/jest-runtime/build/index.js:376:14)
at Runtime.requireModuleOrMock (/myrepo/node_modules/jest-runtime/build/index.js:463:19)
at Object.<anonymous> (/myrepo/guide/test/CrossEntropyTests.ts:3:1)
at Runtime._execModule (/myrepo/node_modules/jest-runtime/build/index.js:694:13)
at Runtime.requireModule (/myrepo/node_modules/jest-runtime/build/index.js:376:14)
at /myrepo/node_modules/jest-jasmine2/build/index.js:129:13
at Generator.next (<anonymous>)
at step (/myrepo/node_modules/jest-jasmine2/build/index.js:170:30)
at /myrepo/node_modules/jest-jasmine2/build/index.js:189:14
at new Promise (<anonymous>)
at /myrepo/node_modules/jest-jasmine2/build/index.js:167:12
at jasmine2 (/myrepo/node_modules/jest-jasmine2/build/index.js:138:17)
at /myrepo/node_modules/jest-runner/build/run_test.js:148:24
at Generator.next (<anonymous>)
at step (/myrepo/node_modules/jest-runner/build/run_test.js:270:30)
at /myrepo/node_modules/jest-runner/build/run_test.js:281:15
at process._tickCallback (internal/process/next_tick.js:68:7)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (2 by maintainers)
Top Results From Across the Web
TensorflowJS: Initialization of backend webgl failed on Firefox ...
I am new to TensorflowJS. I have used tensorflowJS with web worker and it works perfectly on Chrome with backend webGL ...
Read more >How to Turn on WebGL in Your Browser - Lexia Help Center
What if WebGL isn't enabled in my browser? · Update the browser to the latest version. · Try a different browser or device....
Read more >iOS 15 + WebGL 2 issue - Unity Forum
The problem is with the latest iOS update (15) and WebGL 2, as the title suggests. The iOS 15 update automatically enabled WebGL...
Read more >Building and running a WebGL project - Unity - Manual
When you build a WebGL project, Unity creates a folder with the following files: An index.html file which browsers can navigate to load...
Read more >@tensorflow/tfjs-backend-wasm - npm package | Snyk
If you are loading the WASM backend from your own or other third-party servers, you need to make sure the script is served...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So it turns out this problem is due to
jest
, or the interaction betweenjest
andtfjs
. The problem isjest
, by default, seems to mock a browser-like environment, whichtfjs
detects and thus tries to load browser stuff like the webgl backend. Adding"testEnvironment": "node"
to thejest
config in mypackage.json
resolved these issues. It’s a bit annoying that the default behavior was like this with no obvious clues as to what was going on, but I can’t say this is an issue withtfjs
. Maybe there should be a comment in some readme somewhere about this 😃 Anyway, thanks again for looking into this, it’s appreciated!I got the same issue and for that, I had to add these lines in packages.json:
and this import in jest setup file