Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tfjs-backend-wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
},
"browser": {
"fs": false,
"path": false
"path": false,
"worker_threads": false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have this change upstream, without specifying these sinks bundlers get confused and will throw errors even for client-side packages. Right now I have to manually patch this for my deployments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give us more info on this? When you say manually patch, do you mean you need to add these to your bundler configuration explicitly (i.e. these are not picked up automatically). What kind of set up are you using?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see the issue by just using the WASM webpack starter. Update the tfjs version to 2.3 and try running the dev server. You'll see in the console that it fails on finding both worker_threads and perf_hooks.

By patch, I mean adding worker_threads and perf_hooks to the tfjs-wasm package.json. It doesn't seem to work if you add it to the root package.json.

"perf_hooks": false
},
"peerDependencies": {
"@tensorflow/tfjs-core": "link:../tfjs-core"
Expand Down
4 changes: 2 additions & 2 deletions tfjs-backend-wasm/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ function config({plugins = [], output = {}, tsCompilerOptions = {}}) {
output: {
banner: PREAMBLE,
sourcemap: true,
globals: {'@tensorflow/tfjs-core': 'tf', 'fs': 'fs', 'path': 'path'},
globals: {'@tensorflow/tfjs-core': 'tf', 'fs': 'fs', 'path': 'path', 'worker_threads': 'worker_threads', 'perf_hooks': 'perf_hooks'},
...output,
},
external: ['crypto', '@tensorflow/tfjs-core', 'fs', 'path'],
external: ['crypto', '@tensorflow/tfjs-core', 'fs', 'path', 'worker_threads', 'perf_hooks'],
onwarn: warning => {
let {code} = warning;
if (code === 'CIRCULAR_DEPENDENCY' || code === 'CIRCULAR' ||
Expand Down
6 changes: 6 additions & 0 deletions tfjs-backend-wasm/src/flags_wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ ENV.registerFlag(
*/
// From: https://github.com/GoogleChromeLabs/wasm-feature-detect
ENV.registerFlag('WASM_HAS_MULTITHREAD_SUPPORT', async () => {
// TODO(annxingyuan): Enable node support once this is resolved:
// https://github.com/tensorflow/tfjs/issues/3830
if (ENV.get('IS_NODE')) {
return false;
}

try {
// Test for transferability of SABs (needed for Firefox)
// https://groups.google.com/forum/#!msg/mozilla.dev.platform/IHkBZlHETpA/dwsMNchWEQAJ
Expand Down