Skip to content

Add WASM backend #1497

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

Closed
nebrelbug opened this issue Apr 5, 2019 · 30 comments · Fixed by #2500 or #2520
Closed

Add WASM backend #1497

nebrelbug opened this issue Apr 5, 2019 · 30 comments · Fixed by #2500 or #2520
Assignees
Labels
comp:wasm type:feature New feature or request

Comments

@nebrelbug
Copy link

TensorFlow.js version

1.0.4

Browser version

Chrome 73

Describe the problem or feature request

Has there been any further discussion about using WASM to optimize performance? I noticed there was discussion in #36, but it was decided to wait and eventually tfjs-node was created.

Possible Benefits of WASM

  • Run in any WASM environment
  • Maybe higher speed than WebGL if users have slow graphics?
@dsmilkov
Copy link
Contributor

dsmilkov commented Apr 5, 2019

Hi, thanks for filing this issue. A WASM backend is on our roadmap for this quarter. We can use this issue for updates.

@dsmilkov dsmilkov changed the title Improve Performance with WASM Add WASM backend Apr 5, 2019
@no-1ne
Copy link

no-1ne commented Apr 7, 2019

Folks at intel have been making webml/webnn and recently made some amazing strides of hitting 31fps running coco SSD models.

intel/webml-polyfill#650 (comment)

They are implementing it natively mimicking the android NN API and for the changes to reach end user, they have to be merged into chromium source code.

Where as WASM backend would be awesome and I hope it can hit as much performance as they are able to

@no-1ne
Copy link

no-1ne commented May 27, 2019

Hi folks update on this, curious to see the performance compared to tflite and tensorflow

@dsmilkov
Copy link
Contributor

dsmilkov commented May 29, 2019

Thanks for the reference. We are closely following the amazing work that Intel has done, led by @huningxin. Our wasm backend will most likely not be able to reach that level of performance since we won't be able to access hardware acceleration beyond SIMD 128bit, but it will provide other benefits, such as:

  • acceleration for lower-end mobile devices that don't have webgl float support.
  • acceleration on higher-end devices through SIMD and threading.
  • consistent performance on cpu, agnostic of the JIT compilation.
  • open an avenue for adding iterative linear algebra primitives such as SVD, eigenvectors, matrix inversion, that cannot be done efficiently on the GPU.

We will start developing our WASM backend in the open, on GitHub, very soon. Stay tuned!

@huningxin
Copy link

Thanks for the update @dsmilkov . As you know, webml-polyfill currently reuses tfjs-core WebGL kernels for GPU implementation and compiles tf-lite kernels to WASM for CPU implementation. It's a great news that tfjs will have a WASM backend soon. It would simplify the webml-polyfill and benefit the webnn spec development. Highly looking forward to that.

@chirva-ivan
Copy link

Hey, guys. Are there any updates on this issue?

@dsmilkov
Copy link
Contributor

We just started by adding the framework (skeleton) code around it: tensorflow/tfjs-core#1863 We will be slowly ramping up on this.

@camsjams
Copy link

camsjams commented Sep 5, 2019

While fully understanding that this a new and still experimental backend, are you planning on publishing the alpha/beta builds to npm?

@dsmilkov dsmilkov assigned nsthorat and unassigned nkreeger Sep 6, 2019
@dsmilkov
Copy link
Contributor

dsmilkov commented Sep 6, 2019

We are still very early in the process so publishing something to npm is not useful at this time. I'll ping this issue when we have more updates.

@bhack
Copy link

bhack commented Sep 20, 2019

For out of browser WASI I just opened tensorflow/mlir#140 in the MLIR repo.

@rthadur
Copy link
Contributor

rthadur commented Oct 15, 2019

This has been done and should be available in latest releases.Thank you.

@rthadur rthadur closed this as completed Oct 15, 2019
@tiziano88
Copy link

Great news! Which release has now Wasm support? And are there any instructions about it? Looking forward to trying it out.

@nsthorat nsthorat reopened this Oct 15, 2019
@nsthorat
Copy link
Contributor

This is actually still in progress we’ll update this when we’re ready to release :)

@Annaero
Copy link

Annaero commented Nov 8, 2019

This is actually still in progress we’ll update this when we’re ready to release :)

Hello, do you have any updates?

@dsmilkov
Copy link
Contributor

dsmilkov commented Dec 5, 2019

Hi all,

We are excited to share that we just released our first alpha release of the WASM backend.
See the README.md in the tfjs-backend-wasm folder for how to use it. At this point we have about ~30 kernels - see all_kernels.ts for the list.

We would love to get your feedback, testing, and help as we are polishing towards a general release!

Thanks!

@dsmilkov dsmilkov closed this as completed Dec 5, 2019
@dsmilkov
Copy link
Contributor

dsmilkov commented Dec 5, 2019

Closing this issue since it's a general issue tracking our WASM release. Feel free to file separate issues if you run into problems.

@whatevergeek
Copy link

Thanks @dsmilkov
This is great news.

@bhack
Copy link

bhack commented Dec 5, 2019

@dsmilkov Are you involved as team in https://bytecodealliance.org/?

@camsjams
Copy link

camsjams commented Dec 5, 2019

There appears to be a directory called wasm-out missing in the published npm version, I get an error:

Module not found: Error: Can't resolve '../wasm-out/tfjs-backend-wasm' in '/var/www/node_modules/@tensorflow/tfjs-backend-wasm/dist'

Here is a screenshot of installed items:
image

@dsmilkov
Copy link
Contributor

dsmilkov commented Dec 5, 2019

Thanks for finding that out. We just released 1.4.0-alpha2 with the fix. Let us know how it goes.

@camsjams
Copy link

camsjams commented Dec 6, 2019

It looks to be working so far in the sense that our application hasn't crashed or thrown errors. I will you know how it goes 👍

@no-1ne
Copy link

no-1ne commented Dec 6, 2019

Great new congrats on alpha,

Cameron, pls do share the performance improvements you notice during your experiments with wasm backend.

@chirva-ivan
Copy link

Did everything following the example from README and got an error. Do I need some special build of tfjs-core? Any Ideas?

Screenshot from 2019-12-06 15-30-44

@nsthorat
Copy link
Contributor

nsthorat commented Dec 6, 2019

@chirva-ivan which browser are you using? If you open the initialization error what does it say?

@chirva-ivan
Copy link

chirva-ivan commented Dec 6, 2019

@nsthorat using Chrome 78

Screenshot from 2019-12-06 18-26-16

@nsthorat
Copy link
Contributor

nsthorat commented Dec 6, 2019

@chirva-ivan is it possible for you to stand up a demo for us to look at?

@dsmilkov
Copy link
Contributor

dsmilkov commented Dec 6, 2019

Are you using Parcel? Can you share a small project/build script that we can reproduce? Thanks!

@yashints
Copy link

yashints commented Dec 9, 2019

@dsmilkov Here is a codesandbox with above error:

https://codesandbox.io/s/naughty-montalcini-s0gjk

dsmilkov added a commit that referenced this issue Dec 9, 2019
Make the WASM backend work in node. Also:

- Enable node tests in CI
- Reduce log outputs when running tests in core.
- Fix #1497 (comment) (tfjs_backend_wasm.default is not a fuction)
- Remove pre-install script which causes yarn of a third-party project that uses the wasm backend to spin indefinitely.

FEATURE
@yashints
Copy link

@dsmilkov I am still getting the error in the browser, was the fix just for node?

@dsmilkov
Copy link
Contributor

dsmilkov commented Dec 14, 2019

I just sent #2559 for review where I document how to use the WASM backend with bundlers and also added starter projects for webpack and parcel. See update readme from the PR.

Note also that you have to depend on the latest alpha 1.4.0-alpha3, and potentially we might need to release alpha4 since we made some updates to the browser field in package.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment