Add WebGPU sigmoid operator#20504
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20504
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below:
|
|
Hi @iamorlando! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
@pytorchbot label "release notes: ops & kernels" |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
There was a problem hiding this comment.
Pull request overview
Adds WebGPU backend runtime support for aten.sigmoid.default, expanding the set of transformer/LLM-oriented ops that can execute via the existing Vulkan-delegate serialization consumed by the WebGPU runtime.
Changes:
- Adds an fp32 WGSL sigmoid compute shader plus a generated embedded WGSL header.
- Registers a new C++ WebGPU runtime implementation for
aten.sigmoid.defaultand wires it into the WebGPU CMake build. - Extends WebGPU Python test infrastructure (allowlist + op-test registry/cases) and updates WebGPU docs/support matrices to include sigmoid.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| backends/webgpu/TODO.md | Updates current state / next-steps notes to reflect broader op coverage including sigmoid. |
| backends/webgpu/test/tester.py | Adds aten.sigmoid.default to the VulkanPartitioner allowlist used by WebGPU tests/export harness. |
| backends/webgpu/test/TARGETS | Adds a Buck python_unittest target for the new sigmoid export smoke tests. |
| backends/webgpu/test/ops/sigmoid/test_sigmoid.py | New export-level smoke tests for sigmoid (including chained sigmoid) plus deterministic input generators used by op-test cases. |
| backends/webgpu/test/ops/sigmoid/init.py | New package marker for sigmoid test module. |
| backends/webgpu/test/op_tests/test_schema.py | Extends schema assertions to require registered sigmoid op-test suites/cases and golden dtype expectations. |
| backends/webgpu/test/op_tests/test_generator.py | Ensures sigmoid cases are included in the “every case delegates” contract check. |
| backends/webgpu/test/op_tests/generate_op_tests.py | Updates generator CLI docstring to include sigmoid in --ops examples. |
| backends/webgpu/test/op_tests/cases.py | Registers a new sigmoid op-test suite with multiple shape/range/chained cases. |
| backends/webgpu/runtime/ops/sigmoid/sigmoid.wgsl | New fp32 sigmoid kernel WGSL. |
| backends/webgpu/runtime/ops/sigmoid/Sigmoid.cpp | New runtime operator implementation + dispatch setup for aten.sigmoid.default. |
| backends/webgpu/runtime/ops/sigmoid/sigmoid_wgsl.h | Generated embedded WGSL header for the sigmoid shader + workgroup constants. |
| backends/webgpu/README.md | Updates status/progress and the operator support matrix to list sigmoid (and related already-landed ops). |
| backends/webgpu/CMakeLists.txt | Adds runtime/ops/sigmoid/Sigmoid.cpp to the WebGPU backend build sources. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Adds WebGPU runtime support for
aten.sigmoid.defaultto expand the Llama-oriented operator coverage in the WebGPU backend.This includes:
This also aligns the WebGPU test allowlist with the already-registered
aten.mul.Tensorruntime op and addsmulexport/op-test coverage, including broadcast cases. The op-test generator now uses the WebGPU allowlist so registered cases must delegate through the supported WebGPU path.The op follows the existing WebGPU runtime path: models are lowered through the existing
VulkanBackenddelegate serialization, and the WebGPU runtime consumes that delegate graph.Test plan
.venv/bin/python backends/webgpu/scripts/gen_wgsl_headers.py --checkgit diff HEAD --checkPYTHONPYCACHEPREFIX=/tmp/executorch_pycache .venv/bin/python -m py_compile backends/webgpu/test/tester.py backends/webgpu/test/op_tests/cases.py backends/webgpu/test/op_tests/generate_op_tests.py backends/webgpu/test/op_tests/test_generator.py backends/webgpu/test/op_tests/test_schema.py backends/webgpu/test/ops/sigmoid/test_sigmoid.py backends/webgpu/test/ops/mul/test_mul.pyPATH=/Users/orlando/Documents/dev/executorch/.venv/bin:$PATH .venv/bin/lintrunner --data-path /tmp/executorch_lintrunner --skip MYPY <changed files>(no lint issues)PYTHONPATH=/Users/orlando/Documents/dev PYTHONPYCACHEPREFIX=/tmp/executorch_pycache .venv/bin/python -m pytest backends/webgpu/test/ops/add/test_add.py backends/webgpu/test/ops/mul/test_mul.py backends/webgpu/test/ops/sigmoid/test_sigmoid.py backends/webgpu/test/op_tests/test_schema.py backends/webgpu/test/op_tests/test_generator.py -vv(33 passed)PYTHONPATH=/Users/orlando/Documents/dev PYTHONPYCACHEPREFIX=/tmp/executorch_pycache .venv/bin/python -m executorch.backends.webgpu.test.op_tests.generate_op_tests --output /tmp/webgpu_op_tests_mul_fix_rebased(generated 33 cases: 5 add, 8 mul, 5 sigmoid, 15 rms_norm)cmake-out-webgpu-optest-macos2/backends/webgpu/webgpu_op_test --manifest /tmp/webgpu_op_tests_mul_fix_rebased/manifest.json(34 passed, including 8OpTest_mulcases and manifest reconciliation)mulcoverage follow-up:webgpu_scratch_buffer_test,webgpu_op_test_util_test, andwebgpu_op_test/tmp/build/backends/webgpu/webgpu_scratch_buffer_test(passed)/tmp/build/backends/webgpu/webgpu_op_test_util_test(3 passed)/tmp/build/backends/webgpu/webgpu_op_test --manifest /artifacts/manifest.json(25 passed, including 5OpTest_sigmoidcases)torch.sigmoid(x)Python model to ExecuTorch.ptewebgpu_backendandemdawnwebgpu[-8, -4, -1, 0, 1, 4, 8, 12, -12]backends=["VulkanBackend"],numInstructions=1requestAdapter=1,requestDevice=1,createShaderModule=1,createComputePipeline=1,dispatchWorkgroups=1,queueSubmit=1maxAbsError=2.9103830456733704e-11