question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't automatically attempt to load webgl backend

See original GitHub issue

To 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
DABHcommented, Jul 30, 2018

So it turns out this problem is due to jest, or the interaction between jest and tfjs. The problem is jest, by default, seems to mock a browser-like environment, which tfjs detects and thus tries to load browser stuff like the webgl backend. Adding "testEnvironment": "node" to the jest config in my package.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 with tfjs. Maybe there should be a comment in some readme somewhere about this 😃 Anyway, thanks again for looking into this, it’s appreciated!

0reactions
gildniycommented, Apr 6, 2022

I got the same issue and for that, I had to add these lines in packages.json:

"@tensorflow/tfjs-node": "^3.15.0",
"@tensorflow/tfjs-node-gpu": "^3.15.0",

and this import in jest setup file

import '@tensorflow/tfjs-node'
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found