LayersModel#predict() results in all zeros when using WebGPU backend in Deno
See original GitHub issueSystem information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): No
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS Monterey 12.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): https://cdn.skypack.dev/@tensorflow/tfjs
- TensorFlow.js version (use command below): 3.20.0
- Browser version: Deno (built from source at commit 2929ec9f)
- Tensorflow.js Converter Version: N/A
Describe the current behavior
I came from https://github.com/tensorflow/tfjs/issues/6746 and made https://github.com/denoland/deno/pull/15853 to have deno compatible with the WebGPU backend. Model predictions sometimes resulting in an all-zeros tensor, the problem does not exist with a CPU backend.
Describe the expected behavior
Output tensors should contain non-zero numbers.
Standalone code to reproduce the issue
import * as tf from "https://cdn.skypack.dev/@tensorflow/tfjs?dts";
import "https://cdn.skypack.dev/@tensorflow/tfjs-backend-webgpu";
await tf.ready();
const model = tf.sequential();
model.add(tf.layers.dense({ units: 1, inputShape: [1] });
const output = await model.predict(tf.tensor([1])).array();
console.log(output); // prints [[0]]
Other info / logs I am on an Apple M1 laptop.
Backstory and tracking issues:
- Deno uses
deno_webgpu
fromgfx-rs/wgpu
, which in turn usesgfx-rs/naga
for all shader related things. - gfx-rs/wgpu#2994
- gfx-rs/naga#2072
- gfx-rs/naga#2071
- gfx-rs/naga#1829
- Turns out Naga is lexical scoping instead of functional/modulo scoping and they are changing that in gfx-rs/naga#2065
Issue Analytics
- State:
- Created a year ago
- Comments:17 (6 by maintainers)
Top Results From Across the Web
denosaurs/netsaur: Powerful machine learning ... - GitHub
Powerful machine learning, accelerated by WebGPU. Contribute to denosaurs/netsaur development by creating an account on GitHub. ... Use the Native Backend.
Read more >Deno 1.8 Release Notes
Deno 1.8 adds experimental support for the WebGPU API, adds support for importing private modules, stabilizes import maps, revamps coverage ...
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
@vicary Done with https://github.com/tensorflow/tfjs/pull/6918, for shader compiler issues 1 and 2 mentioned above we intend not to fix in TFJS but track them on naga project(https://github.com/gfx-rs/naga/issues/2071 and https://github.com/gfx-rs/naga/issues/2080).
BTW, I indeed try to fix 1 and 2 in TFJS(https://github.com/tensorflow/tfjs/compare/master...haoyunfeix:tfjs:test_6842?expand=1) and glad to see WebGPU on deno could get the same result as CPU backend. I posted all resources(updated webgpu build and test code) here in case you are interested in.
upload.zip
Sure. My temporary fix as below, to move
main
implantation into_start
entry point: Before:After:
You could see that the other
_start
outside function likegetCoordsFromIndex
andgetAByOutputIndex
can compile and works well, so maybe we shouldn’t call a function namedmain
? I’ll take a double check.