Skip to content

isWebGPUSupported() crashes under Node #8066

@reillyeon

Description

@reillyeon

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Debian 11.6
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: N/A
  • TensorFlow.js installed from (npm or script link): npm
  • TensorFlow.js version (use command below): 4.13.0
  • Browser version: N/A
  • Tensorflow.js Converter Version: N/A

Describe the current behavior
Under Node.js the globalThis object does not have a navigator property, since isWebGPUSupported() tries to access a property on globalThis.navigator an exception is thrown. I believe that this regressed in #8001.

Describe the expected behavior
isWebGPUSupported() should return false in non-browser contexts like Node (unless a Node WebGPU is available as suggested in #7595).

Standalone code to reproduce the issue

Create an empty npm project, install @tensorflow/tjfs-backend-webgpu and then try to invoke import('@tensorflow/tjfs-backend-webgpu') on the Node REPL.

Other info / logs

$ node
Welcome to Node.js v18.17.1.
Type ".help" for more information.
> await import('@tensorflow/tfjs-backend-webgpu')
Uncaught TypeError: Cannot read properties of undefined (reading 'gpu')
    at isWebGPUSupported (/home/reillyg/tmp/node_modules/@tensorflow/tfjs-backend-webgpu/dist/tf-backend-webgpu.node.js:1208:35)
    at Object.<anonymous> (/home/reillyg/tmp/node_modules/@tensorflow/tfjs-backend-webgpu/dist/tf-backend-webgpu.node.js:2117:5)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions