From b704557813bd58b32f481f2934a81e6702d4f0b3 Mon Sep 17 00:00:00 2001 From: Min Guo Date: Thu, 22 Oct 2026 14:53:19 -0700 Subject: [PATCH] Fix `llama_qnn` Buck target import failures Summary: `//executorch/examples/qualcomm/oss_scripts/llama:llama_qnn` currently fails at import time for every model, before any argument is parsed, with `ModuleNotFoundError: No module named 'executorch.examples.models.gemma4'` and then `... granite_speech`. The Buck targets drifted from the sources synced from upstream: the Gemma4 enablement (#20979) added an unconditional `executorch.examples.models.gemma4` import with no owning target for `gemma4/__init__.py`, Granite-Speech added `model/audio_encoder.py` plus a `granite_speech` import, and QAD (#21036) added `quantize/qat.py`, `dataset/{constants,targets}.py` and the `train/` package, none of which are in any target. This adds a `gemma4` library owning `gemma4/__init__.py`, a new `train` library (including its `train/config/*.yaml` resources), the missing sources in `static_llama`, `dataset` and `quantize`, and the `gemma4` and `granite_speech` deps on `llama_lib`. The `fbcode/` and `xplat/` copies are kept byte-identical. Known limitation, not addressed here: under Buck `QNN_SDK_ROOT` is a placeholder, so `is_qnn_sdk_version_less_than("2.35")` cannot detect the SDK version and masked softmax is disabled during export even though the pinned SDK (2.50) supports it. Authored with Claude Code. Differential Revision: D127006045 --- examples/models/gemma4/BUCK | 9 ++++++ .../qualcomm/oss_scripts/llama/targets.bzl | 30 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/examples/models/gemma4/BUCK b/examples/models/gemma4/BUCK index 19f0ff90c93..9790b60acf1 100644 --- a/examples/models/gemma4/BUCK +++ b/examples/models/gemma4/BUCK @@ -8,6 +8,15 @@ non_fbcode_target(_kind = define_common_targets,) fbcode_target(_kind = define_common_targets,) +fbcode_target(_kind = runtime.python_library, + name = "gemma4", + srcs = ["__init__.py"], + _is_external_target = True, + base_module = "executorch.examples.models.gemma4", + deps = [":text_decoder"], + visibility = ["PUBLIC"], +) + # Text decoder module fbcode_target(_kind = runtime.python_library, name = "text_decoder", diff --git a/examples/qualcomm/oss_scripts/llama/targets.bzl b/examples/qualcomm/oss_scripts/llama/targets.bzl index d52bdcfbc8a..54036076988 100644 --- a/examples/qualcomm/oss_scripts/llama/targets.bzl +++ b/examples/qualcomm/oss_scripts/llama/targets.bzl @@ -74,6 +74,7 @@ def define_common_targets(is_fbcode = False): srcs = [ "model/__init__.py", "model/apply_rope.py", + "model/audio_encoder.py", "model/embedding.py", "model/feed_forward.py", "model/layernorm.py", @@ -82,6 +83,7 @@ def define_common_targets(is_fbcode = False): ], deps = [ "//caffe2:torch", + "//executorch/examples/qualcomm:utils", "//executorch/examples/models/llama:transformer_modules", "fbsource//third-party/pypi/transformers:transformers", ], @@ -174,10 +176,12 @@ def define_common_targets(is_fbcode = False): "dataset/builders.py", "dataset/collators.py", "dataset/config.py", + "dataset/constants.py", "dataset/datasets.py", "dataset/loaders.py", "dataset/preprocessors.py", "dataset/schema.py", + "dataset/targets.py", ], deps = [ ":decoder_constants", @@ -196,17 +200,41 @@ def define_common_targets(is_fbcode = False): srcs = [ "quantize/__init__.py", "quantize/ptq.py", + "quantize/qat.py", "quantize/strategy.py", ], deps = [ ":decoder_constants", ":inference", + ":train", ":utils", "//caffe2:torch", "//executorch/backends/qualcomm/_passes:passes", ], ) + runtime.python_library( + name = "train", + srcs = [ + "train/__init__.py", + "train/config/__init__.py", + "train/config/config.py", + "train/loss.py", + "train/trainer.py", + "train/utils.py", + ], + resources = [ + "train/config/lr_config.yaml", + "train/config/qad.yaml", + ], + deps = [ + ":dataset", + "//caffe2:torch", + "fbsource//third-party/pypi/pyyaml:pyyaml", + "fbsource//third-party/pypi/tqdm:tqdm", + ], + ) + runtime.python_library( name = "mix_precision_analyzer", srcs = [ @@ -298,8 +326,10 @@ def define_common_targets(is_fbcode = False): "//executorch/examples/models/codegen:codegen", "//executorch/examples/models/gemma:gemma", "//executorch/examples/models/gemma2:gemma2", + "//executorch/examples/models/gemma4:gemma4", "//executorch/examples/models/glm:glm", "//executorch/examples/models/granite:granite", + "//executorch/examples/models/granite_speech:granite_speech", "//executorch/examples/models/internvl3:internvl3", "//executorch/examples/models/smolvlm:smolvlm", "//executorch/examples/models/llama:hf_download",