Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPU<-->BigInt: Tensorflow.js - Initialization of backend webgpu failed TypeError: Cannot convert a BigInt value to a number #22029

Closed
josephrocca opened this issue Jan 22, 2024 · 6 comments · Fixed by #27072
Labels
bug Something isn't working correctly webgpu WebGPU API

Comments

@josephrocca
Copy link
Contributor

josephrocca commented Jan 22, 2024

Version: Deno 1.39.4

The code below works in Deno with an earlier tfjs-webgpu-backend version (see import_map.json here), but I raised the tfjs version numbers to 4.16.0 as shown below, and that produces the error logs below. I'm guessing that this is because newer versions of tf.js have started using BigInts, and Deno hasn't implemented some WebGPU<-->BigInt stuff.

I've confirmed that the code below works fine on Chrome (Windows).


deno.json

{
  "importMap": "import_map.json"
}

import_map.json

{
  "imports": {
    "@tensorflow/tfjs-core": "https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core@4.16.0/dist/tf-core.fesm.js",
    "@tensorflow/tfjs-backend-webgpu": "https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgpu@4.16.0/dist/tf-backend-webgpu.fesm.js"
  }
}

main.js

import * as tf from "@tensorflow/tfjs-core";
import "@tensorflow/tfjs-backend-webgpu";

await tf.ready();
tf.randomGamma([2, 2], 1).print();

Error Logs

deno run --unstable --allow-net=cdn.jsdelivr.net main.js
Initialization of backend webgpu failed
TypeError: Cannot convert a BigInt value to a number
    at toNumber (ext:deno_webidl/00_webidl.js:98:11)
    at Array.<anonymous> (ext:deno_webidl/00_webidl.js:255:13)
    at webidl.converters.GPUSize64 (ext:deno_webgpu/01_webgpu.js:5173:42)
    at ext:deno_webidl/00_webidl.js:904:28
    at Array.GPUDeviceDescriptor (ext:deno_webidl/00_webidl.js:788:32)
    at GPUAdapter.requestDevice (ext:deno_webgpu/01_webgpu.js:407:36)
    at Object.factory (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgpu@4.16.0/dist/tf-backend-webgpu.fesm.js:2138:38)
    at async Engine.ready (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core@4.16.0/dist/tf-core.fesm.js:4248:29)
    at async file:///home/joe/Downloads/denotfjs/main.js:4:1
error: Uncaught (in promise) Error: Could not initialize any backends, all backend initializations failed.
        throw new Error(`Could not initialize any backends, all backend initializations ` +
              ^
    at Engine.ready (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core@4.16.0/dist/tf-core.fesm.js:4254:15)
    at async file:///home/joe/Downloads/denotfjs/main.js:4:1
@josephrocca josephrocca changed the title Tensorflow.js - Initialization of backend webgpu failed TypeError: Cannot convert a BigInt value to a number WebGPU<-->BigInt: Tensorflow.js - Initialization of backend webgpu failed TypeError: Cannot convert a BigInt value to a number Jan 23, 2024
@littledivy littledivy added bug Something isn't working correctly webgpu WebGPU API labels Jan 23, 2024
@Mutefish0
Copy link
Contributor

run into the same problem

@petamoriken
Copy link
Contributor

The spec defines GPUSize64 as unsigned long long, which uses ConvertToInt, so it appears that bigint is not allowed. Is this a spec bug?

@mmastrac
Copy link
Contributor

mmastrac commented Feb 12, 2024

@josephrocca Could you print the output of this code from your repl in both Chrome and deno?

const adapter = await navigator.gpu.requestAdapter();
console.log(adapter.limits);

@josephrocca
Copy link
Contributor Author

@mmastrac Sorry for delay - was waiting to get access to the Windows machine again (I have linux, which doesn't support webgpu on chrome). Here are the logs:

Chrome:

maxTextureDimension1D: 16384
maxTextureDimension2D: 16384
maxTextureDimension3D: 2048
maxTextureArrayLayers: 2048
maxBindGroups: 4
maxBindGroupsPlusVertexBuffers: 24
maxBindingsPerBindGroup: 1000
maxDynamicUniformBuffersPerPipelineLayout: 10
maxDynamicStorageBuffersPerPipelineLayout: 8
maxSampledTexturesPerShaderStage: 16
maxSamplersPerShaderStage: 16
maxStorageBuffersPerShaderStage: 10
maxStorageTexturesPerShaderStage: 8
maxUniformBuffersPerShaderStage: 12
maxUniformBufferBindingSize: 65536
maxStorageBufferBindingSize: 2147483644
minUniformBufferOffsetAlignment: 256
minStorageBufferOffsetAlignment: 256
maxVertexBuffers: 8
maxBufferSize: 2147483648
maxVertexAttributes: 16
maxVertexBufferArrayStride: 2048
maxInterStageShaderComponents: 112
maxInterStageShaderVariables: 28
maxColorAttachments: 8
maxColorAttachmentBytesPerSample: 128
maxComputeWorkgroupStorageSize: 32768
maxComputeInvocationsPerWorkgroup: 1024
maxComputeWorkgroupSizeX: 1024
maxComputeWorkgroupSizeY: 1024
maxComputeWorkgroupSizeZ: 64
maxComputeWorkgroupsPerDimension: 65535

Deno:

  maxTextureDimension1D: 16384,
  maxTextureDimension2D: 16384,
  maxTextureDimension3D: 2048,
  maxTextureArrayLayers: 2048,
  maxBindGroups: 8,
  maxBindingsPerBindGroup: 65535,
  maxBufferSize: 2147483647,
  maxDynamicUniformBuffersPerPipelineLayout: 12,
  maxDynamicStorageBuffersPerPipelineLayout: 0,
  maxSampledTexturesPerShaderStage: 16,
  maxSamplersPerShaderStage: 16,
  maxStorageBuffersPerShaderStage: 0,
  maxStorageTexturesPerShaderStage: 0,
  maxUniformBuffersPerShaderStage: 12,
  maxUniformBufferBindingSize: 65536,
  maxStorageBufferBindingSize: 0,
  minUniformBufferOffsetAlignment: 256,
  minStorageBufferOffsetAlignment: 256,
  maxVertexBuffers: 16,
  maxVertexAttributes: 16,
  maxVertexBufferArrayStride: 4294967295,
  maxInterStageShaderComponents: 124,
  maxComputeWorkgroupStorageSize: 0,
  maxComputeInvocationsPerWorkgroup: 0,
  maxComputeWorkgroupSizeX: 0,
  maxComputeWorkgroupSizeY: 0,
  maxComputeWorkgroupSizeZ: 0,
  maxComputeWorkgroupsPerDimension: 0

Edge:

maxTextureDimension1D: 16384
maxTextureDimension2D: 16384
maxTextureDimension3D: 2048
maxTextureArrayLayers: 2048
maxBindGroups: 4
maxBindGroupsPlusVertexBuffers: 24
maxBindingsPerBindGroup: 1000
maxDynamicUniformBuffersPerPipelineLayout: 10
maxDynamicStorageBuffersPerPipelineLayout: 8
maxSampledTexturesPerShaderStage: 16
maxSamplersPerShaderStage: 16
maxStorageBuffersPerShaderStage: 10
maxStorageTexturesPerShaderStage: 8
maxUniformBuffersPerShaderStage: 12
maxUniformBufferBindingSize: 65536
maxStorageBufferBindingSize: 2147483644
minUniformBufferOffsetAlignment: 256
minStorageBufferOffsetAlignment: 256
maxVertexBuffers: 8
maxBufferSize: 2147483648
maxVertexAttributes: 16
maxVertexBufferArrayStride: 2048
maxInterStageShaderComponents: 112
maxInterStageShaderVariables: 28
maxColorAttachments: 8
maxColorAttachmentBytesPerSample: 128
maxComputeWorkgroupStorageSize: 32768
maxComputeInvocationsPerWorkgroup: 1024
maxComputeWorkgroupSizeX: 1024
maxComputeWorkgroupSizeY: 1024
maxComputeWorkgroupSizeZ: 64
maxComputeWorkgroupsPerDimension: 65535

@mattvr
Copy link

mattvr commented Oct 2, 2024

Update: This error is now fixed in the latest version of tfjs


Tensorflow.js now seems to fail in a different way. GPUAdapter.requestAdapterInfo is called by tfjs, but this method is deprecated and not implemented by Deno.

Repro

I ran the original example, but with latest Deno & npm specifiers npm:@tensorflow/tfjs-core and npm:@tensorflow/tfjs-backend-webgpu.

(Note: this reproduces with Deno v2.0.0-rc.9 or 1.46.3 and latest tfjs using either npm: or jsdelivr)

$ deno run mod.ts
Initialization of backend webgpu failed
TypeError: adapter.requestAdapterInfo is not a function
    at [...]/deno/npm/registry.npmjs.org/@tensorflow/tfjs-backend-webgpu/4.21.0/dist/tf-backend-webgpu.node.js:2147:50
    at step ([...]/deno/npm/registry.npmjs.org/@tensorflow/tfjs-backend-webgpu/4.21.0/dist/tf-backend-webgpu.node.js:144:27)
    at Object.next ([...]/deno/npm/registry.npmjs.org/@tensorflow/tfjs-backend-webgpu/4.21.0/dist/tf-backend-webgpu.node.js:93:53)
    at fulfilled ([...]deno/npm/registry.npmjs.org/@tensorflow/tfjs-backend-webgpu/4.21.0/dist/tf-backend-webgpu.node.js:74:28)
error: Uncaught (in promise) Error: Could not initialize any backends, all backend initializations failed.
    at Engine.<anonymous> ([...]/deno/npm/registry.npmjs.org/@tensorflow/tfjs-core/4.21.0/dist/tf-core.node.js:4301:35)
    at step ([...]/deno/npm/registry.npmjs.org/@tensorflow/tfjs-core/4.21.0/dist/tf-core.node.js:138:27)

@fs-eire
Copy link

fs-eire commented Oct 11, 2024

The following code failed with error Cannot convert a BigInt value to a number on 2 of my Windows11 machines.

adapter.requestDevice({
  requiredLimits : {
    maxBufferSize: adapter.limits.maxBufferSize
  }
});

value of adapter.limits.maxBufferSize is 18446744073709551615n.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly webgpu WebGPU API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants