Repository navigation
Qualcomm AI Engine Direct - Gemma4 Text model enablement - #20979
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20979
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 21633d2 with merge base fb5eedc ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@psiddh Hi, We chose a standalone implementation because Gemma4's architecture differs substantially from the current Once more Gemma 4-like architectures (e.g., YOCO or per-layer embedding variants) are supported, perhaps around 4-5 models, it may make sense to revisit the design and refactor them into a unified architecture (static llama path). cc: @shewu-quic @winskuo-quic @haowhsu-quic @chenweng-quic @abhinaykukkadapu |
|
@pytorchbot label "release notes: qualcomm" |
|
There are merge conflicts, can you pls resolve. |
507a79d to
8aaf378
Compare
|
@psiddh Hi, it looks like those failures are not related to this PR. The failures seem to be caused by the branch being based on an older commit. like: |
| if hasattr(self._tokenizer, "bos_id"): | ||
| return self._tokenizer.bos_id |
There was a problem hiding this comment.
@psiddh Looks like the smollm2_135m SQNR CI regression was caused by changing prefix_token_id from eot_token_id to bos_id, which changes the calibration inputs.
This change is actually correct. According to lm_eval, the prefix token should be the tokenizer's BOS token when available, falling back to EOS/EOT otherwise.
I think we need to change the SQNR threshold.
Reference:
|
@claude review this PR. |
|
Claude finished @digantdesai's task in 4m 20s —— View job Claude PR Review — Gemma4 Text model enablementReviewed the full diff against Below are findings ordered by importance. 🔴 Blocking / high-priority1. Branch is stale — this PR deletes unrelated operator tests. These were added to 2. Result<TensorInfo> k_out = method_meta->output_tensor_meta(1 + layer);
Result<TensorInfo> v_out = method_meta->output_tensor_meta(1 + metadata_.num_layers + layer);This assumes every decoder emits outputs in exactly 🟡 Should address3. len(users := list(node.users)) > 0
and "args_" in node.name
and users[0].meta["val"].size()[-2:] in self.kv_cache_shapeThis relaxed the previous 4. Embedding-quantize transform relocated — also affects all models. The 5. get_weight_mapping: Optional[Callable] = False,Default should be 🟢 Minor / nits6. 7. Misleading comment in 8. 9. Good catches worth keeping: the SummaryThe Gemma4 model code itself is solid and well-isolated. The two things that most need attention before merge: (1) re-rebase to stop deleting unrelated operator tests (this is failing CI), and (2) confirm the Review generated with Claude Code (Opus 4.8). |
|
@DannyYuyang-quic Can you look at the review comments ? |
Summary: - Add a Gemma4 model compatible with static llama
8bd910c to
21633d2
Compare
Response to Review Comments: 1. Branch is stale — this PR deletes unrelated operator tests.Rebasing onto latest main so the 2. kv_manager.cpp now hard-assumes output tensor ordering for ALL models.To address concerns about incorrect KV-cache ordering, I added a defensive check that validates the 3. _tag_ios placeholder condition change affects all models.Moving the embedding quantization transform into the quantize flow is more consistent with the overall quantization flow. 4. Embedding-quantize transform relocated:Move Embedding-quantize transform into 5~8:Addressed the review comments by updating documentation/comments and removing unused or unnecessary changes. |
| ET_CHECK_MSG( | ||
| k_head_dim == v_head_dim, |
There was a problem hiding this comment.
defensive check that validates the head_dim obtained from both the K-cache and V-cache is the same.
Since the cache shapes are:
- output k cache: [1, n_kv, head_dim, ar_len]
- output v cache: [1, n_kv, ar_len, head_dim]
the head_dim inferred from each tensor should match. This provides a sanity check that the selected K/V cache tensors are consistent with the expected shape.
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. cc @cbilgin @psiddh Differential Revision: D127006045 Pull Request resolved: #24100
Summary
Gemma4 Text model enablement
Test plan