Skip to content

Added EfficientSAM Wasm demo #49

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

Merged
merged 3 commits into from
Aug 19, 2025
Merged

Added EfficientSAM Wasm demo #49

merged 3 commits into from
Aug 19, 2025

Conversation

Conarnar
Copy link
Contributor

@Conarnar Conarnar commented Aug 7, 2025

Summary

Added instructions on how to build a demo webpage that takes allows users to upload a copy of efficient_sam.pte along with an image to select a point and segment the image.

Test plan

Following the steps in the README.md:

cd executorch-examples/efficient_sam/wasm

# Build the demo
bash build.sh

# Run the demo
python3 -m http.server --directory build/

Then, go to http://localhost:8000/demo.html and upload efficient_sam.pte and an image to segment different parts of the image.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 7, 2025
@Conarnar Conarnar force-pushed the wasm-2 branch 4 times, most recently from b86b666 to f19b81b Compare August 8, 2025 17:49
Copy link
Contributor

@lucylq lucylq left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

add_executable(executorch_wasm_demo_lib)
target_link_libraries(executorch_wasm_demo_lib PRIVATE executorch_wasm executorch_backends)
target_link_options(executorch_wasm_demo_lib PRIVATE -sALLOW_MEMORY_GROWTH
-sSTACK_SIZE=262144)
Copy link
Contributor

Choose a reason for hiding this comment

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

noob q: why 262144?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default was 65536, but it runs out of memory. Doubling it to 131072 still isn't enough, but 262144 ended up being enough.

Copy link

@digantdesai digantdesai left a comment

Choose a reason for hiding this comment

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

I guess XNNPACK is next?

console.log("Running model...");
const output = module.forward([imageTensor, pointTensor, labelTensor]);
const endTime = performance.now();
console.log(((endTime - startTime)/1000).toFixed(2) + "s");

Choose a reason for hiding this comment

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

How does this compare to w/o wasm on the same machine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With optimized kernels and XNNPACK
6.51 seconds with Wasm
1.95 seconds without Wasm on executor_runner


CMAKE_OUT=build

emcmake cmake . -DEXECUTORCH_BUILD_WASM=ON \

Choose a reason for hiding this comment

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

No XNNPACK yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Requires pytorch/executorch#13234
Looks like that's been merged so I can add that in now

)

prog = export(model, example_inputs)
edge = to_edge_transform_and_lower(prog, partitioner=[XnnpackPartitioner()])
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, LGTM!

@lucylq lucylq merged commit 729a450 into meta-pytorch:main Aug 19, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants