Skip to content

Commit fc89e8b

Browse files
author
shubhagr-quic
authored
QNN Compilation command changes (#327)
1. Changes in libraries used during Context binary generation. 2. Changed convertor spelling to converter to align with qairt-converter string. --------- Signed-off-by: Shubham Agrawal <[email protected]>
1 parent 6796f9e commit fc89e8b

File tree

5 files changed

+29
-32
lines changed

5 files changed

+29
-32
lines changed

QEfficient/compile/qnn_compiler.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def parse_qnn_config(self):
102102
self.qnn_config = {}
103103
# Copy key-value pairs to the class object
104104
for key, value in config_data.items():
105-
if key == QnnConstants.CONVERTOR_ARGS_EXTENSION_STR:
106-
self.check_extension_arg(key, value, QnnConstants.IMMUTABLE_CONVERTOR_ARGS)
105+
if key == QnnConstants.CONVERTER_ARGS_EXTENSION_STR:
106+
self.check_extension_arg(key, value, QnnConstants.IMMUTABLE_CONVERTER_ARGS)
107107
if key == QnnConstants.CONTEXT_BIN_ARGS_EXTENSION_STR:
108108
self.check_extension_arg(key, value, QnnConstants.IMMUTABLE_CONTEXT_BIN_GEN_ARGS)
109109
self.qnn_config[key] = value
@@ -191,20 +191,20 @@ def create_qnn_compiler_config_json(self) -> str:
191191
def compile(self) -> str:
192192
"""
193193
Compiles the given ``ONNX`` model during object creation using QNN compiler and saves the compiled ``qpc`` package at ``qnn_binary_dir``.
194-
- Creates convertor command and convert onnx model to model.dlc using qairt-convertor
194+
- Creates converter command and convert onnx model to model.dlc using qairt-converter
195195
- command line arguments and qnn_config.json (if provided) are used to create qnn_compiler_config.json for context-binary-generator
196-
- model.dlc from convertor stage is passed into context-binary-generator command to create programqpc.bin.
196+
- model.dlc from converter stage is passed into context-binary-generator command to create programqpc.bin.
197197
198198
Returns:
199199
:str: Path to compiled ``qpc`` package.
200200
"""
201201
if not (
202202
self.qnn_config
203-
and (QnnConstants.SKIP_QNN_CONVERTOR_STEP_STR in self.qnn_config)
204-
and self.qnn_config[QnnConstants.SKIP_QNN_CONVERTOR_STEP_STR]
203+
and (QnnConstants.SKIP_QNN_CONVERTER_STEP_STR in self.qnn_config)
204+
and self.qnn_config[QnnConstants.SKIP_QNN_CONVERTER_STEP_STR]
205205
):
206206
converter_cmd = self.converter()
207-
execute_command("convertor", converter_cmd, self.qpc_base_path)
207+
execute_command("converter", converter_cmd, self.qpc_base_path)
208208

209209
if not os.path.isfile(self.dlc_model_path):
210210
raise FileNotFoundError(
@@ -225,7 +225,7 @@ def compile(self) -> str:
225225

226226
def converter(self) -> str:
227227
"""
228-
Creates QNN convertor command using provided options.
228+
Creates QNN converter command using provided options.
229229
230230
IMMUTABLE parameters which can not be overridden by the user using qnn_config.json:
231231
:input_network (str): Generated ``ONNX`` Model Path.
@@ -235,10 +235,10 @@ def converter(self) -> str:
235235
:float_bitwidth (int): Converts the graph to the specified float bitwidth, either 32 or 16(Default).
236236
:preserve_io_datatype(flag): Passed by default.
237237
238-
CONVERTOR_ARGS_EXTENSION passed in qnn_config.json is appended to the command created.
238+
CONVERTER_ARGS_EXTENSION passed in qnn_config.json is appended to the command created.
239239
240240
Returns:
241-
:str: QNN Convertor command.
241+
:str: QNN Converter command.
242242
"""
243243
converter_tool = QnnConstants.QAIRT_CONVERTER.format(self.qnn_sdk_path, self.qnn_target)
244244

@@ -250,10 +250,10 @@ def converter(self) -> str:
250250
f"--float_bitwidth {QnnConstants.FLOAT_BITWIDTH} "
251251
)
252252
# Add default arguments.
253-
cmd += QnnConstants.CONVERTOR_DEFAULT_ARGS
253+
cmd += QnnConstants.CONVERTER_DEFAULT_ARGS
254254

255-
if self.qnn_config and QnnConstants.CONVERTOR_ARGS_EXTENSION_STR in self.qnn_config:
256-
cmd += self.qnn_config[QnnConstants.CONVERTOR_ARGS_EXTENSION_STR]
255+
if self.qnn_config and QnnConstants.CONVERTER_ARGS_EXTENSION_STR in self.qnn_config:
256+
cmd += self.qnn_config[QnnConstants.CONVERTER_ARGS_EXTENSION_STR]
257257

258258
return cmd
259259

@@ -266,7 +266,7 @@ def generate_context_binary(self) -> str:
266266
:backend_binary (str): Generated QPC binary file name, which is provided programqpc.bin
267267
:output_dir (str): Path to store generated Binaries (qnn_binary_dir).
268268
:model (str): Path to the <qnn_model_name.so> file containing a QNN network.
269-
:dlc_path (str): Path to DLC file generated by QNN-Convertor.
269+
:dlc_path (str): Path to DLC file generated by QNN-Converter.
270270
:config_file(str): Path to created qnn_compiler_config.json containing qnn_compile_backend.json & shared_library_path.
271271
272272
Configurable parameters:
@@ -279,15 +279,13 @@ def generate_context_binary(self) -> str:
279279
"""
280280
binary_gen_tool = QnnConstants.QNN_CONTEXT_BIN.format(self.qnn_sdk_path, self.qnn_target)
281281
backend_lib = QnnConstants.QNN_CONTEXT_LIB_BACKEND.format(self.qnn_sdk_path, self.qnn_target)
282-
model_lib = QnnConstants.QNN_CONTEXT_LIB_MODEL.format(self.qnn_sdk_path, self.qnn_target)
283282
config_file_path = self.create_qnn_compiler_config_json()
284283

285284
cmd = (
286285
f"{binary_gen_tool} --binary_file {QnnConstants.CONTEXT_BIN_NAME} "
287286
f"--backend_binary {QnnConstants.CONTEXT_BIN_QPC_NAME} "
288287
f"--output_dir {self.qnn_binary_dir} "
289288
f"--backend {backend_lib} "
290-
f"--model {model_lib} "
291289
f"--dlc_path {self.dlc_model_path} "
292290
f"--config_file {config_file_path} "
293291
)
@@ -343,7 +341,7 @@ def compile(
343341
) -> str:
344342
"""
345343
Compiles the given ``ONNX`` model using QNN compiler and saves the compiled ``qpc`` package at ``qnn_binary_dir``.
346-
Generates model.dlc during convertor stage, qnn_compile_backend.json for backend parameters of context-binary-generator.
344+
Generates model.dlc during converter stage, qnn_compile_backend.json for backend parameters of context-binary-generator.
347345
Generates tensor-slicing configuration if multiple devices are passed in ``device_group``.
348346
349347
``Mandatory`` Args:
@@ -375,7 +373,7 @@ def compile(
375373

376374
os.makedirs(qpc_base_path, exist_ok=True)
377375

378-
# Created custom_io_config.yaml file for QNN-Convertor stage.
376+
# Created custom_io_config.yaml file for QNN-Converter stage.
379377
# TODO To make custom_io_config.yaml configurable as not all models need it.
380378
custom_io_file_path = os.path.join(qpc_base_path, "custom_io_config.yaml")
381379

QEfficient/compile/qnn_config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"convertor_args_extension": "",
2+
"converter_args_extension": "",
33
"context_binary_generator_args_extension": "--log_level debug",
44
"qnn_compilation_backend":
55
{
@@ -8,5 +8,5 @@
88
"compiler_printPerfMetrics": false,
99
"compiler_stat_level": 10
1010
},
11-
"SKIP_QNN_CONVERTOR_STEP": false
11+
"SKIP_QNN_CONVERTER_STEP": false
1212
}

QEfficient/utils/constants.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ class QnnConstants:
9999
QNN_CONTEXT_BIN = "{}/bin/{}/qnn-context-binary-generator"
100100

101101
# QNN Libraries required for compilation
102-
QNN_CONTEXT_LIB_BACKEND = "{}/lib/{}/libQnnAicCC.so"
103-
QNN_CONTEXT_LIB_MODEL = "{}/lib/{}/libQnnModelDlc.so"
102+
QNN_CONTEXT_LIB_BACKEND = "{}/lib/{}/libQnnAic.so"
104103
QNN_CONTEXT_LIB_NET_RUN_EXTENSIONS = "{}/lib/{}/libQnnAicNetRunExtensions.so"
105104

106105
# QNN Compilation target names
@@ -112,10 +111,10 @@ class QnnConstants:
112111
# TARGET System Architecture
113112
TARGET = "x86_64-linux-clang" # TODO add support in infer to be override
114113

115-
# Convertor Arguments
114+
# Converter Arguments
116115
FLOAT_BITWIDTH = 16
117116
FLOAT_BIAS_BITWIDTH = 32
118-
CONVERTOR_DEFAULT_ARGS = "--preserve_io_datatype --onnx_skip_simplification "
117+
CONVERTER_DEFAULT_ARGS = "--preserve_io_datatype --onnx_skip_simplification "
119118

120119
# Context-Binary-Generator Arguments
121120
LOG_LEVEL = "error"
@@ -135,12 +134,12 @@ class QnnConstants:
135134
GRAPH_NAMES = [f"{MODEL_NAME}_configuration_1", f"{MODEL_NAME}_configuration_2"]
136135

137136
# qnn_config JSON file supported Keys
138-
CONVERTOR_ARGS_EXTENSION_STR = "convertor_args_extension"
137+
CONVERTER_ARGS_EXTENSION_STR = "converter_args_extension"
139138
CONTEXT_BIN_ARGS_EXTENSION_STR = "context_binary_generator_args_extension"
140139
QNN_COMPILATION_BACKEND_STR = "qnn_compilation_backend"
141-
SKIP_QNN_CONVERTOR_STEP_STR = "SKIP_QNN_CONVERTOR_STEP"
140+
SKIP_QNN_CONVERTER_STEP_STR = "SKIP_QNN_CONVERTER_STEP"
142141

143-
IMMUTABLE_CONVERTOR_ARGS = [
142+
IMMUTABLE_CONVERTER_ARGS = [
144143
"--input_network ",
145144
"--output_path ",
146145
"--config ",

QEfficient/utils/generate_qnn_network_specialization_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from onnx import helper
1414

1515
"""
16-
The network specilization file is generated by loading the onnx graph and fecthing the graph inputs and outputs.
16+
The network specialization file is generated by loading the onnx graph and fetching the graph inputs and outputs.
1717
"""
1818

1919

@@ -28,7 +28,7 @@ def fetch_nodes_info(
2828
kv_cache_batch_size: Optional[int] = None,
2929
) -> None:
3030
"""
31-
Generates network specialization config custom IO file for convertor stage in QNN compilation.
31+
Generates network specialization config custom IO file for converter stage in QNN compilation.
3232
Reads onnx graph and creates a custom IO configuration file according to the passed parameters and
3333
save it as a yaml file provided in file_path argument.
3434
@@ -187,7 +187,7 @@ def generate_data_format_config(
187187
188188
``Optional`` Args:
189189
:data_format (str): Tensor format for KV nodes. ``Defaults to QNN_TENSOR_DATA_FORMAT_MX.``
190-
:model_dlc_name (str): DLC Name generated by the convertor stage in QNN Compilation. ``Defaults to model.``
190+
:model_dlc_name (str): DLC Name generated by the converter stage in QNN Compilation. ``Defaults to model.``
191191
:file_path (str): File path to save the generated data format config. ``Defaults to qnn_data_format_config.json.``
192192
"""
193193

tests/transformers/models/test_prefix_caching.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ def test_simple_prefix_caching(model_name):
4040
def test_simple_prefix_caching_qnn(model_name):
4141
qeff_model = QEFFAutoModelForCausalLM.from_pretrained(model_name, continuous_batching=True)
4242
qnn_config = {
43-
"convertor_args_extension": "",
43+
"converter_args_extension": "",
4444
"context_binary_generator_args_extension": "--log_level debug",
4545
"qnn_compilation_backend": {
4646
"compiler_enable_depth_first": True,
4747
"compiler_printDDRStats": False,
4848
"compiler_printPerfMetrics": False,
4949
},
50-
"SKIP_QNN_CONVERTOR_STEP": False,
50+
"SKIP_QNN_CONVERTER_STEP": False,
5151
}
5252
qnn_config_json_path = os.path.join(os.getcwd(), "qnn_config.json")
5353
create_json(qnn_config_json_path, qnn_config)

0 commit comments

Comments
 (0)