Skip to content

Commit 17e1487

Browse files
authored
Qualcomm AI Engine Direct - Enable more HF LLM Model (#20587)
### Summary Enable more hf llm models that is also tested on Optimum-ExecuTorch. Specs used: SM8750, QNN2.37, 16a8w, context_len=128 | Model (`--decoder_model`) | Token/Sec | Use `--enable_spinquant_r3`? | Sample Prompt | |---|:---:|---|---| | `llama3_2-1b` | 29 | ✅ **Yes** | "Simply put, the theory of relativity states that" | | `qwen2_5-0_5b` | 130 | ✅ **Yes** | "My favourite condiment is " | | `qwen3-0_6b` | 70 | ✅ **Yes** | "Give me a short introduction to large language model." | | `smollm2_135m` | 254 | ❌ **No** | "My favourite condiment is " | | `granite-3_3-2b` | 17 | ❌ **No** | "Take a current environmental issue and work backward to devise an innovative prevention strategy" | Sample Script `python examples/qualcomm/oss_scripts/hf_causal_lm.py --ptq 16a8w --prompt "My favourite condiment is " --soc_model SM8750 --device $DEVICE_ID --build_folder build-android/ --decoder_model qwen2_5-0_5b --enable_spinquant_r3` ### Test plan `python backends/qualcomm/tests/test_qnn_delegate.py TestExampleLLMScript.test_hf_causal_lm --device $DEVICE_ID --soc_model SM8750 --build_folder build-android --executorch_root . --artifact_dir ./hf_qwen`
1 parent fa49f8f commit 17e1487

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

backends/qualcomm/tests/test_qnn_delegate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8723,18 +8723,18 @@ def test_attention_sink(self):
87238723
msg["wiki_ppl"], self.llm_specs[model_name].wikitext_ppl
87248724
)
87258725

8726-
def test_qwen2_5(self):
8727-
# This is not testing static llm flow.
8726+
def test_hf_causal_lm(self):
8727+
# This is the Hugging Face transformers flow, not the static llm flow.
87288728
if not self.required_envs([]):
87298729
self.skipTest("missing required envs")
87308730
prompt = "My favourite condiment is "
87318731
cmds = [
87328732
"python",
8733-
f"{self.executorch_root}/examples/qualcomm/oss_scripts/qwen2_5/qwen2_5.py",
8733+
f"{self.executorch_root}/examples/qualcomm/oss_scripts/hf_causal_lm.py",
87348734
"--prompt",
87358735
prompt,
87368736
"--decoder_model",
8737-
"qwen2.5_0.5B",
8737+
"qwen2_5-0_5b",
87388738
"--ptq",
87398739
"16a8w",
87408740
"--enable_spinquant_r3",

examples/qualcomm/oss_scripts/qwen2_5/qwen2_5.py renamed to examples/qualcomm/oss_scripts/hf_causal_lm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
logging.basicConfig(level=logging.INFO, format=FORMAT)
3434
logging.getLogger().setLevel(logging.INFO)
3535

36-
PTE_FILENAME = "qwen_qnn_q16"
36+
PTE_FILENAME = "hf_causal_lm_qnn"
3737

3838

3939
def compile(args: argparse.Namespace, qnn_config: QnnConfig): # noqa: C901
@@ -195,7 +195,7 @@ def main(args):
195195
"-a",
196196
"--artifact",
197197
help="path for storing generated artifacts by this example.",
198-
default="qwen2_5",
198+
default="hf_causal_lm",
199199
type=str,
200200
)
201201

@@ -216,8 +216,8 @@ def main(args):
216216

217217
parser.add_argument(
218218
"--decoder_model",
219-
choices=["qwen2.5_0.5B", "qwen2.5_0.5B_instruct", "qwen2.5_1.5B_instruct"],
220-
help="The Qwen model to export. Current available options are: [qwen2.5_0.5B, qwen2.5_0.5B_instruct, qwen2.5_1.5B_instruct]",
219+
choices=list(HUGGING_FACE_REPO_IDS.keys()),
220+
help=f"The Hugging Face decoder model to export. Available options are: {list(HUGGING_FACE_REPO_IDS.keys())}",
221221
required=True,
222222
)
223223

examples/qualcomm/oss_scripts/llm_utils/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Tutorial to run [eval_decoder_model_qnn.py](./eval_decoder_model_qnn.py)
22
This script, [`eval_decoder_model_qnn.py`](./eval_decoder_model_qnn.py), is designed to evaluate large language models (LLMs) from transformers that have been compiled into ExecuTorch Portable Executable (PTE) format for execution on Qualcomm devices. It leverages the `lm-evaluation-harness` library to perform various NLP evaluation tasks.
33

4-
> ⚠️ **Important:** Note that this script runs PTE files generated specifically for Hugging Face Transformers, such as [qwen2_5.py](../qwen2_5/qwen2_5.py), rather than [the static LLaMA version](../llama/llama.py).
4+
> ⚠️ **Important:** Note that this script runs PTE files generated specifically for Hugging Face Transformers, such as [hf_causal_lm.py](../hf_causal_lm.py), rather than [the static LLaMA version](../llama/llama.py).
55
66
### Features:
77

examples/qualcomm/oss_scripts/llm_utils/qnn_decoder_model_manager.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@
4444
logging.basicConfig(level=logging.INFO, format=FORMAT)
4545

4646
HUGGING_FACE_REPO_IDS = {
47-
"qwen2.5_0.5B": "Qwen/Qwen2.5-0.5B",
48-
"qwen2.5_1.5B_instruct": "Qwen/Qwen2.5-1.5B-Instruct",
49-
"qwen2.5_0.5B_instruct": "Qwen/Qwen2.5-0.5B-Instruct",
47+
"llama3_2-1b": "NousResearch/Llama-3.2-1B",
48+
"qwen2_5-0_5b": "Qwen/Qwen2.5-0.5B",
49+
"qwen2_5-1_5b_instruct": "Qwen/Qwen2.5-1.5B-Instruct",
50+
"qwen2_5-0_5b_instruct": "Qwen/Qwen2.5-0.5B-Instruct",
51+
"qwen3-0_6b": "Qwen/Qwen3-0.6B",
52+
"smollm2_135m": "HuggingFaceTB/SmolLM2-135M",
53+
"granite-3_3-2b": "ibm-granite/granite-3.3-2b-instruct",
5054
}
5155

5256

@@ -64,6 +68,7 @@ def get_qnn_llm_edge_manager(model_name, max_seq_len=128, enable_spinquant_r3=Tr
6468
config.ar_len = 1 # kv mode
6569
config.max_batch_size = batch_size
6670
config.enable_spinquant_r3 = enable_spinquant_r3
71+
config.use_cache = True
6772

6873
# Some config has head_dim provided that is different from equation below(e.g., qwen3)
6974
if not hasattr(config, "head_dim"):

0 commit comments

Comments
 (0)