Skip to content

feat: added webgpu tensorflow example#624

Merged
ericgregory merged 1 commit intowasmCloud:mainfrom
MendyBerger:tfjs-example
May 7, 2026
Merged

feat: added webgpu tensorflow example#624
ericgregory merged 1 commit intowasmCloud:mainfrom
MendyBerger:tfjs-example

Conversation

@MendyBerger
Copy link
Copy Markdown
Contributor

@MendyBerger MendyBerger commented Apr 16, 2026

Adds a TensorFlow.js example running on top of wasi:webgpu

Needed before merging:

Other external PRs that would allow removing some hacks here:

Other comments

  • location.search is polyfiled to an empty string because tf assumes that's it's available.
  • navigator.gpu is first set to empty an object at initialization so that the check if webgpu is available succeeds, and is later at runtime overridden with the real gpu object from wasi-gfx-js

@MendyBerger MendyBerger requested review from a team as code owners April 16, 2026 14:40
@MendyBerger MendyBerger marked this pull request as draft April 16, 2026 14:42
@vados-cosmonic
Copy link
Copy Markdown
Contributor

Hey @MendyBerger just double checking, but this is still in draft on purpose right?

@MendyBerger
Copy link
Copy Markdown
Contributor Author

Yes, still need a few small changes. Will try to resolve soon

@MendyBerger MendyBerger force-pushed the tfjs-example branch 3 times, most recently from 0fbeb6f to 6d4ecfa Compare April 29, 2026 18:05
@MendyBerger MendyBerger marked this pull request as ready for review April 29, 2026 18:10
Comment thread examples/components/webgpu-tensorflow/package.json Outdated
Comment thread examples/components/webgpu-tensorflow/generated/types/wit.d.ts Outdated
Comment thread examples/components/webgpu-tensorflow/project-generate.toml Outdated
Comment thread examples/components/webgpu-tensorflow/service/polyfill.js
Comment thread examples/components/webgpu-tensorflow/.wash/config.yaml Outdated
Comment thread examples/components/webgpu-tensorflow/README.md Outdated
Comment thread examples/components/webgpu-tensorflow/README.md Outdated
Comment thread examples/components/webgpu-tensorflow/README.md Outdated
Comment thread examples/components/webgpu-tensorflow/README.md Outdated
Copy link
Copy Markdown
Contributor

@ericgregory ericgregory left a comment

Choose a reason for hiding this comment

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

Follow-up README suggestions after local testing.

Comment thread examples/components/webgpu-tensorflow/README.md Outdated
Comment thread examples/components/webgpu-tensorflow/README.md Outdated
- Starts a local wasmCloud host that can run your WebAssembly component
- Builds this project (including necessary `npm` script targets)
- Deploys the component locally
- Watches your code for changes and re-deploys when necessary
Copy link
Copy Markdown
Contributor

@ericgregory ericgregory May 1, 2026

Choose a reason for hiding this comment

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

Consider adding a short Overview / How it works section between the Quickstart and the request instructions that tells the wasmCloud-specific story this example is built to demonstrate, including implementation details like what wasi_webgpu: true in .wash/config.yaml does.


## Adding Capabilities

To learn how to extend this example with additional capabilities, see the [Adding Capabilities](https://wasmcloud.com/docs/tour/adding-capabilities?lang=typescript) section of the wasmCloud documentation.
Copy link
Copy Markdown
Contributor

@ericgregory ericgregory May 1, 2026

Choose a reason for hiding this comment

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

Consider adding a Known limitations section before the "Adding Capabilities" link covering the rough edges a copy-paster will hit. Suggested content:

  • Math.random is currently constant. polyfil.js overrides globalThis.Math.random to return 0.5 as a temporary shim until wizer initializes wasi:random. We should probably flag this.
  • WIT fetching uses wit-deps instead of wash wit fetch. Mentioned above, but we should probably flag this explicitly.
  • Resulting component.wasm is large. Might be worth noting and explaining why.

Comment thread examples/components/webgpu-tensorflow/src/component.ts Outdated
Comment thread examples/components/webgpu-tensorflow/src/component.ts Outdated
@MendyBerger
Copy link
Copy Markdown
Contributor Author

@ericgregory really sorry to do such a large refactor after review. I did try to incorporate the changes you requested though.

This won't work without wasmCloud/wasmCloud#5122

@MendyBerger MendyBerger requested a review from ericgregory May 5, 2026 20:31
@ericgregory
Copy link
Copy Markdown
Contributor

@MendyBerger No worries, and this looks great! I only see a few small things after the refactor:

  1. We should be as clear as possible in the readme about the wash version requirement - once the release with the fix exists, we'll want to point to that rather than wash 2.0 more generally, and we might want a quick "if you see X error, you need wash ≥ N/build off main" hint until then.
  2. Are the nested component/wit/deps/ and service/wit/deps/ intended to be tracked? if not, could change the gitignore pattern to **/wit/deps/.
  3. Signoff to pass DCO

Signed-off-by: Mendy Berger <12537668+MendyBerger@users.noreply.github.com>
@ericgregory ericgregory merged commit c5a1603 into wasmCloud:main May 7, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants