I am working on getting a local server set up that can serve pages that will have access to tensorflow.js and the webGPU backend.
I have run into an issue where if I serve my files on localhost (127.0.0.1) I am able to load the webGPU backend and everything runs as expected.
However, when I try serving the exact same files at my local IP address like 192.168.x.x (so I can access the host from other devices), I get a “Error: Backend name ‘webgpu’ not found in registry” error when trying to set the backend to webGPU.
I tried serving it using purely node with the http module, http-server, and express and am running into the same error.
Anyone have any ideas of what could cause this to happen? Are there specific headers that need to be set in order to support the webGPU backend? What could cause this to break when all I have done is change the IP address where the file is served
await import(`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.17.0/dist/tf.min.js`);
await import(`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgpu/dist/tf-backend-webgpu.js`);
await tf.ready();
await tf.setBackend("webgpu"); // <--Error: Backend name 'webgpu' not found in registry
console.log(tf.getBackend());
I believe it happens because you're not serving your files over HTTPS. See https://developer.chrome.com/docs/web-platform/webgpu/troubleshooting-tips#the_gpu_adapter_is_null
WebGPU is accessible only to secure contexts. If you serve your code over an insecure protocol (for example,
http:
,file:
), either use the securehttps:
protocol or address this during the development of your web app in one of the following ways:
- Serve your code locally on
http://localhost
orhttp://127.0.0.1
with either of these commands:npx http-server
orpython3 -m http.server
.- Add the origin to the "Insecure origins treated as secure" list of
chrome://flags/#unsafely-treat-insecure-origin-as-secure
and restart Chrome.- Install Node.js and run
npx servez --ssl
to serve your folder over https with a fake certificate. You'll still get a warning in Chrome you can bypass by clicking "Advanced" then "Proceed to...".- Expose your local web server to the Internet with ngrok.