From b9da4cf92d9dc49d599816c451c6ba643ebfb2d0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 23:38:58 +0000 Subject: [PATCH 1/2] Initial plan From 7d047049db2211113cf63c1f8a725b1ad5149762 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 23:43:35 +0000 Subject: [PATCH 2/2] Improve error handling when custom_ops_aot_lib is not found for native runners Make the custom_ops import optional in native runners since it is not needed for pybindings inference. Also improve the assertion error message in custom_ops.py to give actionable guidance when the library is missing. Fixes the error when running Qwen 3.5 examples without building with EXECUTORCH_BUILD_KERNELS_LLM_AOT=ON. Agent-Logs-Url: https://github.com/pytorch/executorch/sessions/6d0bbec5-f0cd-4307-9d9e-3703e499b4ab Co-authored-by: kirklandsign <107070759+kirklandsign@users.noreply.github.com> --- examples/models/llama/runner/native.py | 5 ++++- examples/models/llama3_2_vision/runner/native.py | 5 ++++- extension/llm/custom_ops/custom_ops.py | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/models/llama/runner/native.py b/examples/models/llama/runner/native.py index 6d5d4730844..089f775557d 100644 --- a/examples/models/llama/runner/native.py +++ b/examples/models/llama/runner/native.py @@ -23,7 +23,10 @@ from executorch.examples.models.llama.runner.generation import LlamaRunner # Note: import this after portable_lib -from executorch.extension.llm.custom_ops import custom_ops # noqa # usort: skip +try: + from executorch.extension.llm.custom_ops import custom_ops # noqa # usort: skip +except Exception: + pass # Not needed for pybindings inference. from executorch.kernels import quantized # noqa diff --git a/examples/models/llama3_2_vision/runner/native.py b/examples/models/llama3_2_vision/runner/native.py index 2b4d709f9b4..683bd6ba3a7 100644 --- a/examples/models/llama3_2_vision/runner/native.py +++ b/examples/models/llama3_2_vision/runner/native.py @@ -26,7 +26,10 @@ from executorch.extension.pybindings import portable_lib # noqa # usort: skip # Note: import this after portable_lib -from executorch.extension.llm.custom_ops import custom_ops # noqa # usort: skip +try: + from executorch.extension.llm.custom_ops import custom_ops # noqa # usort: skip +except Exception: + pass # Not needed for pybindings inference. from executorch.kernels import quantized # noqa diff --git a/extension/llm/custom_ops/custom_ops.py b/extension/llm/custom_ops/custom_ops.py index 9aacded4b4c..3f647c0207f 100644 --- a/extension/llm/custom_ops/custom_ops.py +++ b/extension/llm/custom_ops/custom_ops.py @@ -41,7 +41,12 @@ libs = list(package_path.glob("**/*custom_ops_aot_lib.*")) - assert len(libs) == 1, f"Expected 1 library but got {len(libs)}" + assert len(libs) == 1, ( + f"Expected 1 custom_ops_aot_lib library but got {len(libs)} " + f"(searched in {package_path}). " + "If building from source, re-build with " + "-DEXECUTORCH_BUILD_KERNELS_LLM_AOT=ON or use the pybind cmake preset." + ) logging.info(f"Loading custom ops library: {libs[0]}") torch.ops.load_library(libs[0]) op = torch.ops.llama.sdpa_with_kv_cache.default