CMake support for quantized MoE optimized build - #22547
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22547
Note: Links to docs will display an error until the docs builds have been completed. ❌ You can merge normally! (1 Unrelated Failure), 1 Unclassified FailureAs of commit fa78d43 with merge base 1cfcdf8 ( UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review this PR. |
This PR needs a
|
|
Claude finished @digantdesai's task in 4m 4s —— View job PR Review: CMake support for quantized MoE optimized buildReviewed the full diff ( Correctness / behavior
Minor
Nice touch validating the packed blob size against the derived
|
There was a problem hiding this comment.
🟡 Changes recommended
There are newly misleading/incorrect comments in the optimized MoE build wiring and runtime dispatch documentation that should be updated to match the new universal-only behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR adds/adjusts build-time wiring for the llama::quantized_moe_ffn custom op so that an optimized torchao-based implementation can be enabled in CMake (in addition to existing Buck wiring), while keeping a portable reference fallback as the default.
Changes:
- Introduces a CMake option
EXECUTORCH_BUILD_KERNELS_LLM_QUANTIZED_MOE_OPTIMIZEDthat gates linking/compiling the optimized torchao linear operator (and optionally builds a minimal torchao linear static library when the full torchao kernel build isn’t enabled). - Renames the compile-time feature gate from
ENABLE_QUANTIZED_MOE_FFNtoEXECUTORCH_QUANTIZED_MOE_USE_TORCHAOacross code and build files, and tightens the optimized runtime path to require the universal packed-weights format. - Updates Llama export/runtime documentation strings to reference the new optimized-build control surface.
File summaries
| File | Description |
|---|---|
| extension/llm/custom_ops/test_op_moe.cpp | Updates test comment to reflect the new optimized-path feature macro name. |
| extension/llm/custom_ops/targets.bzl | Renames the arm64 preprocessor flag used to enable the torchao optimized path in Buck builds. |
| extension/llm/custom_ops/op_moe.cpp | Switches to EXECUTORCH_QUANTIZED_MOE_USE_TORCHAO, adds an explicit universal ukernel config path, and tightens packed-weights validation for the optimized implementation. |
| extension/llm/custom_ops/CMakeLists.txt | Adds EXECUTORCH_BUILD_KERNELS_LLM_QUANTIZED_MOE_OPTIMIZED option and CMake-side linking/compile-def wiring for the optimized MoE kernel. |
| examples/models/llama/README.md | Updates runtime-build instructions to reference the new CMake option. |
| examples/models/llama/export_llama_lib.py | Updates CLI help text to describe optimized vs reference runtime behavior without referencing the old macro name. |
Review details
Suppressed comments (1)
extension/llm/custom_ops/op_moe.cpp:326
- The comment here says the torchao path validates against a selected format “(universal or kleidi)”, but the new torchao path in this file explicitly requires the universal packed-weights type and rejects non-universal headers. This comment is now misleading and should be updated to match the actual behavior.
// Reference path only: it unpacks the universal layout, so validate the blob
// holds the header plus the universal packed weight-data bytes for the
// claimed dims before any path dereferences it. The torchao path validates
// against its own selected format (universal or kleidi) inside
// torchao_linear.
- Files reviewed: 6/6 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @@ -63,7 +63,7 @@ def _get_quantized_moe_preproc_flags(): | |||
| return select({ | |||
| "DEFAULT": [], | |||
| "ovr_config//cpu:arm64": [ | |||
| "-DENABLE_QUANTIZED_MOE_FFN", | |||
| "-DEXECUTORCH_QUANTIZED_MOE_USE_TORCHAO", | |||
52a053f to
fa78d43
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The reference (non-torchao) path still doesn’t validate the packed-weights header type, which can lead to misinterpreting non-universal blobs instead of failing loudly, and there is also misleading test commentary to correct.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
| // Reference path only: it unpacks the universal layout, so validate the blob | ||
| // holds the header plus the universal packed weight-data bytes for the | ||
| // claimed dims before any path dereferences it. The torchao path validates | ||
| // against its own selected format (universal or kleidi) inside | ||
| // torchao_linear. | ||
| // the same required universal format inside torchao_linear. | ||
| constexpr int kNr = 8, kKr = 16, kSr = 2; |
| // Use empty packed buffers; the kernel will fail loudly if it tries to | ||
| // dereference them. With ENABLE_QUANTIZED_MOE_FFN unset (CI x86 build | ||
| // without torchao linkage) the kernel ET_CHECK_MSGs out before doing | ||
| // dereference them. With EXECUTORCH_QUANTIZED_MOE_USE_TORCHAO unset (CI x86 | ||
| // build without torchao linkage) the kernel ET_CHECK_MSGs out before doing | ||
| // any real work, which is what we want this test to verify. |
|
@claude review this PR. |
|
Claude finished @digantdesai's task in 2m 28s —— View job PR Review: CMake support for quantized MoE optimized buildRe-reviewed the current tip ( Two things from the latest Copilot pass are legitimate and still open, plus one behavioral change worth an explicit confirmation. Correctness
Minor
Overall this is a clean, well-scoped change. The two items worth acting on before merge are #1 (loud-failure symmetry in the reference path) and #2 (confirm the Buck kernel-threading path is intentional); #3 is a quick doc fix.
|
|
@digantdesai has imported this pull request. If you are a Meta employee, you can view this in D118853081. |
For MoE custom op