Skip to content

Commit e5b996a

Browse files
committed
Adding qualcomm recipes
Differential Revision: [D72410492](https://our.internmc.facebook.com/intern/diff/D72410492/) [ghstack-poisoned]
1 parent 910ac24 commit e5b996a

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

backends/qualcomm/recipes/TARGETS

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@fbcode_macros//build_defs:python_library.bzl", "python_library")
2+
3+
python_library(
4+
name = "recipes",
5+
srcs = ["recipes.py"],
6+
deps = [
7+
"//caffe2:torch",
8+
"//executorch/exir:lib",
9+
"//executorch/backends/qualcomm/quantizer:quantizer",
10+
"//executorch/examples/qualcomm:utils"
11+
]
12+
)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
3+
# pyre-strict
4+
from typing import Optional
5+
6+
from executorch import exir
7+
from executorch.backends.qualcomm.quantizer.quantizer import QuantDtype
8+
9+
from executorch.examples.qualcomm.utils import make_quantizer
10+
from executorch.exir import EdgeCompileConfig, ExecutorchBackendConfig, ExportRecipe
11+
from executorch.exir.passes import MemoryPlanningPass
12+
from torch.ao.quantization.quantizer import Quantizer
13+
14+
def get_qualcomm_htp_et_recipe(
15+
name: str,
16+
soc_model: str = "SM8650",
17+
qnn_version: str = "2.25",
18+
quant_dtype: Optional[QuantDtype] = None,
19+
shared_buffer=False,
20+
skip_node_id_set: set[int] = set(),
21+
skip_node_op_set: set[str] = set(),
22+
) -> ExportRecipe:
23+
from executorch.backends.qualcomm.partition.qnn_partitioner import QnnPartitioner
24+
from executorch.backends.qualcomm.serialization.qc_schema import QcomChipset
25+
26+
from executorch.backends.qualcomm.utils.utils import (
27+
_transform,
28+
generate_htp_compiler_spec,
29+
generate_qnn_executorch_compiler_spec,
30+
)
31+
32+
if quant_dtype:
33+
qnn_quantizer: Quantizer = make_quantizer(quant_dtype=quant_dtype)
34+
else:
35+
qnn_quantizer = make_quantizer()
36+
37+
qnn_partitioner = QnnPartitioner(
38+
generate_qnn_executorch_compiler_spec(
39+
soc_model=getattr(QcomChipset, soc_model),
40+
backend_options=generate_htp_compiler_spec(
41+
use_fp16=False if quant_dtype else True
42+
),
43+
),
44+
skip_node_id_set=skip_node_id_set,
45+
skip_node_op_set=skip_node_op_set,
46+
)
47+
48+
executorch_config = ExecutorchBackendConfig(
49+
# For shared buffer, user must pass the memory address
50+
# which is allocated by RPC memory to executor runner.
51+
# Therefore, won't want to pre-allocate
52+
# by memory manager in runtime.
53+
memory_planning_pass=MemoryPlanningPass(
54+
alloc_graph_input=not shared_buffer,
55+
alloc_graph_output=not shared_buffer,
56+
),
57+
)
58+
59+
return ExportRecipe(
60+
name,
61+
quantizer=qnn_quantizer,
62+
partitioners=[qnn_partitioner],
63+
pre_edge_transform_passes=_transform,
64+
edge_compile_config=EdgeCompileConfig(
65+
_check_ir_validity=False,
66+
_skip_dim_order=True,
67+
),
68+
edge_transform_passes=[],
69+
transform_check_ir_validity=True,
70+
executorch_backend_config=executorch_config,
71+
)

extension/llm/export/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ runtime.python_library(
3131
"//executorch/backends/apple/mps:partitioner",
3232
"//executorch/backends/qualcomm/partition:partition",
3333
"//executorch/backends/qualcomm/quantizer:quantizer",
34+
"//executorch/backends/qualcomm/recipes:recipes",
3435
"//executorch/backends/transforms:duplicate_dynamic_quant_chain",
3536
"//executorch/backends/vulkan/partitioner:vulkan_partitioner",
3637
"//executorch/backends/vulkan/quantizer:vulkan_quantizer",

0 commit comments

Comments
 (0)