Skip to content

Commit 5ed466e

Browse files
authored
Fix embedding lowering crash when QNN_SDK_ROOT is unset (#21051)
Summary: D110960687 (#20686) rewrote `Embedding.define_node` to select between the optimized and legacy pcq-embedding lowerings based on `is_qnn_sdk_version_less_than("2.48")`. That helper resolves the SDK version via `get_sdk_build_id`, which builds a path from `os.environ["QNN_SDK_ROOT"]`. `define_node` runs during AOT partitioning (`is_node_supported`), and AOT-only environments do not necessarily have `QNN_SDK_ROOT` set. In that case `os.path.join(os.environ.get("QNN_SDK_ROOT", None), ...)` raised `TypeError: expected str, bytes or os.PathLike object, not NoneType`, breaking every QNN lowering that contains an embedding — including the internal `test_dummy_llama_qnn_16a4w_aot_and_runtime`. Fall back to the legacy embedding lowering (valid on all QNN versions) when `QNN_SDK_ROOT` is unavailable, so the version-gated optimization is only taken when the SDK version can actually be determined. Also make `get_sdk_build_id` raise a clear `EnvironmentError` instead of a cryptic `TypeError` when the environment variable is missing. This diff was authored with Claude Code. Differential Revision: D112944232
1 parent 0fc1f61 commit 5ed466e

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

backends/qualcomm/builders/op_embedding.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
6+
import os
67
from typing import Dict
78

89
import executorch.backends.qualcomm.python.PyQnnManagerAdaptor as PyQnnManager
@@ -242,6 +243,10 @@ def define_node(
242243
node: torch.fx.Node,
243244
nodes_to_wrappers: Dict[torch.fx.Node, PyQnnManager.TensorWrapper],
244245
) -> PyQnnManager.PyQnnOpWrapper:
245-
if is_qnn_sdk_version_less_than("2.48"):
246+
# The optimized pattern requires QNN 2.48+. Resolving the SDK version
247+
# relies on QNN_SDK_ROOT; when it is unavailable (e.g. AOT-only
248+
# environments) fall back to the legacy lowering, which is valid on all
249+
# QNN versions.
250+
if not os.environ.get("QNN_SDK_ROOT") or is_qnn_sdk_version_less_than("2.48"):
246251
return self.define_node_legacy(node, nodes_to_wrappers)
247252
return self.define_node_optimize(node, nodes_to_wrappers)

backends/qualcomm/utils/check_qnn_version.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ def _get_qnn_host_lib_dir_name() -> str:
2626

2727

2828
def get_sdk_build_id():
29+
qnn_sdk_root = os.environ.get("QNN_SDK_ROOT")
30+
if not qnn_sdk_root:
31+
raise EnvironmentError(
32+
"QNN_SDK_ROOT must be set to query the QNN SDK build id."
33+
)
2934
htp_library_path = os.path.join(
30-
os.environ.get("QNN_SDK_ROOT", None),
35+
qnn_sdk_root,
3136
"lib",
3237
_get_qnn_host_lib_dir_name(),
3338
get_qnn_lib_name("QnnHtp"),

0 commit comments

Comments
 (0)