tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.35k stars 1.92k forks source link

setThreadsCount does not change the number of used threads #6081

Closed Poufy closed 1 year ago

Poufy commented 2 years ago

I have used the function like so without any issues before setting my backend to wasm just as described in the README.

importScripts("https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js");
importScripts("https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.13.0")
importScripts("https://cdn.jsdelivr.net/npm/@tensorflow-models/blazeface")
tf.wasm.setWasmPaths('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.13.0/dist/');
tf.wasm.setThreadsCount(2);

However, after I set the backend to wasm and print the number of threads it still appears to be 1, which I am assuming to be the default.

tf.setBackend('wasm');
await tf.ready();
console.log("Num threads wasm is using", tf.wasm.getThreadsCount()); // outputs 1

Any idea what could be the result of this?

foolishortalent commented 2 years ago

I encountered a similar problem. When I set the number of threads to 1, the print result of the number of threads is 1, but when I set the number of threads to be greater than or equal to 2, the print result of the number of threads is always 2 (In fact, I have 4 logical cores). I think it seems to set the wrong upper limit of the number of threads.

tfjs3.13.0, chrome98, win10

Poufy commented 2 years ago

I noticed that wasm threads were not supported in my browser. So I enabled the SharedArrayBuffer and managed to toggle the support on. I see my threads count as 5, but I cannot seem to change it. I tried higher and lower values but it does not change.

gaikwadrahul8 commented 1 year ago

Hi, @Poufy

Apologize for the delayed response and we're re-visiting our older issues and checking whether those issues got resolved or not as of now so May I know are you still looking for the solution or your issue got resolved ?

If issue still persists after trying with latest version of TFJs please let us know with error log and code snippet to replicate the same issue from our end ?

Could you please confirm if this issue is resolved for you ? Please feel free to close the issue if it is resolved ? Thank you!

github-actions[bot] commented 1 year ago

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

github-actions[bot] commented 1 year ago

This issue was closed due to lack of activity after being marked stale for past 7 days.

google-ml-butler[bot] commented 1 year ago

Are you satisfied with the resolution of your issue? Yes No