Skip to content

Adding qualcomm recipes #10036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: gh/tarun292/6/base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions backends/qualcomm/recipes/TARGETS
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@fbcode_macros//build_defs:python_library.bzl", "python_library")

python_library(
name = "recipes",
srcs = ["recipes.py"],
deps = [
"//caffe2:torch",
"//executorch/exir:lib",
"//executorch/backends/qualcomm/quantizer:quantizer",
"//executorch/examples/qualcomm:utils"
]
)
71 changes: 71 additions & 0 deletions backends/qualcomm/recipes/recipes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.

# pyre-strict
from typing import Optional

from executorch import exir
from executorch.backends.qualcomm.quantizer.quantizer import QuantDtype

from executorch.examples.qualcomm.utils import make_quantizer
from executorch.exir import EdgeCompileConfig, ExecutorchBackendConfig, ExportRecipe
from executorch.exir.passes import MemoryPlanningPass
from torch.ao.quantization.quantizer import Quantizer

def get_qualcomm_htp_et_recipe(
name: str,
soc_model: str = "SM8650",
qnn_version: str = "2.25",
quant_dtype: Optional[QuantDtype] = None,
shared_buffer=False,
skip_node_id_set: set[int] = set(),
skip_node_op_set: set[str] = set(),
) -> ExportRecipe:
from executorch.backends.qualcomm.partition.qnn_partitioner import QnnPartitioner
from executorch.backends.qualcomm.serialization.qc_schema import QcomChipset

from executorch.backends.qualcomm.utils.utils import (
_transform,
generate_htp_compiler_spec,
generate_qnn_executorch_compiler_spec,
)

if quant_dtype:
qnn_quantizer: Quantizer = make_quantizer(quant_dtype=quant_dtype)
else:
qnn_quantizer = make_quantizer()

qnn_partitioner = QnnPartitioner(
generate_qnn_executorch_compiler_spec(
soc_model=getattr(QcomChipset, soc_model),
backend_options=generate_htp_compiler_spec(
use_fp16=False if quant_dtype else True
),
),
skip_node_id_set=skip_node_id_set,
skip_node_op_set=skip_node_op_set,
)

executorch_config = ExecutorchBackendConfig(
# For shared buffer, user must pass the memory address
# which is allocated by RPC memory to executor runner.
# Therefore, won't want to pre-allocate
# by memory manager in runtime.
memory_planning_pass=MemoryPlanningPass(
alloc_graph_input=not shared_buffer,
alloc_graph_output=not shared_buffer,
),
)

return ExportRecipe(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we run this recipe in some models and showed it works properly?

name,
quantizer=qnn_quantizer,
partitioners=[qnn_partitioner],
pre_edge_transform_passes=_transform,
edge_compile_config=EdgeCompileConfig(
_check_ir_validity=False,
_skip_dim_order=True,
),
edge_transform_passes=[],
transform_check_ir_validity=True,
executorch_backend_config=executorch_config,
)
1 change: 1 addition & 0 deletions extension/llm/export/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ runtime.python_library(
"//executorch/backends/apple/mps:partitioner",
"//executorch/backends/qualcomm/partition:partition",
"//executorch/backends/qualcomm/quantizer:quantizer",
"//executorch/backends/qualcomm/recipes:recipes",
"//executorch/backends/transforms:duplicate_dynamic_quant_chain",
"//executorch/backends/vulkan/partitioner:vulkan_partitioner",
"//executorch/backends/vulkan/quantizer:vulkan_quantizer",
Expand Down
Loading