2020 setup_common_args_and_variables ,
2121 SimpleADB ,
2222)
23-
2423from executorch .examples .qualcomm .oss_scripts .llm_utils .qnn_decoder_model_manager import (
2524 get_qnn_llm_edge_manager ,
26- HUGGING_FACE_REPO_IDS ,
2725)
2826from executorch .examples .qualcomm .utils import make_output_dir
2927
3533
3634PTE_FILENAME = "hf_causal_lm_qnn"
3735
38- # Map the HF decoder_model keys (HUGGING_FACE_REPO_IDS) to the version strings
39- # the shared qnn_llama_runner understands (see runner.cpp Runner()).
40- DECODER_MODEL_VERSION = {
41- "llama3_2-1b" : "llama3" ,
42- "qwen2_5-0_5b" : "qwen2_5" ,
43- "qwen2_5-1_5b_instruct" : "qwen2_5" ,
44- "qwen2_5-0_5b_instruct" : "qwen2_5" ,
45- "qwen3-0_6b" : "qwen3" ,
46- "smollm2_135m" : "smollm2_135m" ,
47- "granite-3_3-2b" : "granite" ,
48- }
49-
5036
51- def compile (args : argparse .Namespace , qnn_config : QnnConfig ): # noqa: C901
37+ def compile (
38+ args : argparse .Namespace , qnn_config : QnnConfig , pte_name : str
39+ ): # noqa: C901
5240
5341 # ensure the working directory exist.
5442 os .makedirs (args .artifact , exist_ok = True )
5543
56- manager = get_qnn_llm_edge_manager (args .decoder_model , args .max_seq_len )
44+ manager = get_qnn_llm_edge_manager (args .decoder_model_id , args .max_seq_len )
5745
5846 fixed_point_type = {}
5947 if not args .use_fp16 :
@@ -71,14 +59,11 @@ def compile(args: argparse.Namespace, qnn_config: QnnConfig): # noqa: C901
7159 else :
7260 raise ValueError ("Only support uint16 logits output for quantized hf llm." )
7361
74- model_id = HUGGING_FACE_REPO_IDS [args .decoder_model ]
75- tokenizer = AutoTokenizer .from_pretrained (model_id )
62+ tokenizer = AutoTokenizer .from_pretrained (args .decoder_model_id )
7663 tokenizer_json_path = tokenizer .save_pretrained (args .artifact )[- 1 ]
7764
7865 manager .pt2e_quantize (
7966 fixed_point_type ,
80- args .calibration_tasks ,
81- args .calibration_limit ,
8267 args .prompt ,
8368 tokenizer_json_path ,
8469 qnn_config .backend ,
@@ -97,15 +82,15 @@ def compile(args: argparse.Namespace, qnn_config: QnnConfig): # noqa: C901
9782 "scale" : logits_quant_attrs ["scale" ],
9883 "zero_point" : logits_quant_attrs ["zero_point" ],
9984 },
100- open (f"{ args .artifact } /{ PTE_FILENAME } _quant_attrs.txt" , "w" ),
85+ open (f"{ args .artifact } /{ pte_name } _quant_attrs.txt" , "w" ),
10186 )
10287
103- manager .to_executorch (args .artifact , PTE_FILENAME )
88+ manager .to_executorch (args .artifact , pte_name )
10489
10590
106- def inference (args : argparse , qnn_config : QnnConfig ):
107- workspace = f"/data/local/tmp/{ getpass .getuser ()} /executorch/{ PTE_FILENAME } "
108- pte_path = f"{ args .artifact } /{ PTE_FILENAME } .pte"
91+ def inference (args : argparse , qnn_config : QnnConfig , pte_name : str ):
92+ workspace = f"/data/local/tmp/{ getpass .getuser ()} /executorch/{ pte_name } "
93+ pte_path = f"{ args .artifact } /{ pte_name } .pte"
10994 # collect output data
11095 output_data_folder = f"{ args .artifact } /outputs"
11196 make_output_dir (output_data_folder )
@@ -121,12 +106,10 @@ def post_process():
121106 text = text [len (prefix ) :]
122107 outputs .append (args .prompt + text )
123108
124- model_id = HUGGING_FACE_REPO_IDS [args .decoder_model ]
125- tokenizer = AutoTokenizer .from_pretrained (model_id )
109+ tokenizer = AutoTokenizer .from_pretrained (args .decoder_model_id )
126110 tokenizer_json_path = tokenizer .save_pretrained (args .artifact )[- 1 ]
127111 seq_len = args .max_seq_len
128112 runner_bin = "examples/qualcomm/oss_scripts/llama/qnn_llama_runner"
129- decoder_model_version = DECODER_MODEL_VERSION [args .decoder_model ]
130113
131114 # The base (non-instruct) HF models were not trained on the runner's chat
132115 # template. Tokenize the raw prompt here (matching the Python calibration
@@ -146,7 +129,6 @@ def post_process():
146129 f"export LD_LIBRARY_PATH={ qnn_sdk } /lib/{ target } /:{ args .build_folder } /lib &&" ,
147130 f"{ args .build_folder } /{ runner_bin } " ,
148131 f"--tokenized_prompt { tokenized_prompt_path } " ,
149- f"--decoder_model_version { decoder_model_version } " ,
150132 "--eval_mode 0" ,
151133 f"--tokenizer_path { tokenizer_json_path } " ,
152134 f"--model_path { pte_path } " ,
@@ -168,10 +150,9 @@ def post_process():
168150 f"cd { workspace } &&" ,
169151 "./qnn_llama_runner" ,
170152 "--tokenized_prompt tokenized_prompt.raw" ,
171- f"--decoder_model_version { decoder_model_version } " ,
172153 "--eval_mode 0" ,
173154 "--tokenizer_path tokenizer.json" ,
174- f"--model_path { PTE_FILENAME } .pte" ,
155+ f"--model_path { pte_name } .pte" ,
175156 f"--seq_len { seq_len } " ,
176157 "--temperature 0" ,
177158 "--output_path outputs/result.txt" ,
@@ -207,12 +188,12 @@ def main(args):
207188 qnn_config = QnnConfig .load_config (args .config_file if args .config_file else args )
208189
209190 if args .compile_only :
210- compile (args , qnn_config )
191+ compile (args , qnn_config , PTE_FILENAME )
211192 elif args .pre_gen_pte :
212- inference (args , qnn_config )
193+ inference (args , qnn_config , PTE_FILENAME )
213194 else :
214- compile (args , qnn_config )
215- inference (args , qnn_config )
195+ compile (args , qnn_config , PTE_FILENAME )
196+ inference (args , qnn_config , PTE_FILENAME )
216197
217198
218199if __name__ == "__main__" :
@@ -242,10 +223,9 @@ def main(args):
242223 )
243224
244225 parser .add_argument (
245- "--decoder_model" ,
246- choices = list (HUGGING_FACE_REPO_IDS .keys ()),
247- help = f"The Hugging Face decoder model to export. Available options are: { list (HUGGING_FACE_REPO_IDS .keys ())} " ,
248- required = True ,
226+ "--decoder_model_id" ,
227+ help = "The Hugging Face ID to export, e.g., 'NousResearch/Llama-3.2-1B'" ,
228+ default = "NousResearch/Llama-3.2-1B" ,
249229 )
250230
251231 parser .add_argument (
@@ -254,31 +234,9 @@ def main(args):
254234 default = 128 ,
255235 type = int ,
256236 )
257- parser .add_argument (
258- "--calibration_tasks" ,
259- nargs = "+" ,
260- type = str ,
261- default = None ,
262- help = "Tasks for GPTQ calibration from lm_eval. Currently unsupported." ,
263- )
264- parser .add_argument (
265- "--calibration_limit" ,
266- type = int ,
267- default = None ,
268- help = "number of samples used for calibration from lm_eval. Currently unsupported." ,
269- )
270237
271238 try :
272239 args = parser .parse_args ()
273-
274- if args .calibration_tasks is not None or args .calibration_limit is not None :
275- parser .error (
276- "--calibration_tasks/--calibration_limit are not supported yet. "
277- "Calibration uses --prompt instead."
278- )
279-
280- if args .artifact is None :
281- args .artifact = args .decoder_model
282240 main (args )
283241 except Exception as e :
284242 if args .ip and args .port != - 1 :
0 commit comments