Skip to content

Introduce platform-config in CompileSpec for MediaTek backend #10464

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 2 commits into
base: main
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
27 changes: 25 additions & 2 deletions backends/mediatek/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from executorch.exir.backend.compile_spec_schema import CompileSpec

SKIP_COMPILE_SPEC_KEYS = {"ImportForever"}
REQUIRED_COMPILE_SPEC_KEYS = {"platform-config"}
SUPPORTED_PLATFORM_CONFIGS = {"mt6989", "mt6991"}


def assert_default_dim_order(edge_graph_module: torch.fx.GraphModule) -> None:
Expand Down Expand Up @@ -47,6 +49,28 @@ def preprocess(
cls, edge_program: ExportedProgram, module_compile_spec: List[CompileSpec]
) -> PreprocessResult:

# Validate CompileSpec settings
compile_spec_keys = [spec.key for spec in module_compile_spec]
if len(compile_spec_keys) != len(set(compile_spec_keys)):
raise RuntimeError(
"Unsupported duplicated keys in the CompileSpec settings."
)
if not REQUIRED_COMPILE_SPEC_KEYS.issubset(set(compile_spec_keys)):
raise RuntimeError(
"Following keys are required in the CompileSpec settings: {}."
"".format(REQUIRED_COMPILE_SPEC_KEYS)
)
platform = [
spec.value.decode("utf-8")
for spec in module_compile_spec
if spec.key == "platform-config"
][0]
if platform not in SUPPORTED_PLATFORM_CONFIGS:
raise ValueError(
"Unsupported value of platform-config CompileSpec. Given {} but expected to be one "
"of {}.".format(platform, SUPPORTED_PLATFORM_CONFIGS)
)

# Make sure all inputs are contiguous_format or NCHW or default dim order
assert_default_dim_order(edge_program.graph_module)

Expand All @@ -64,8 +88,7 @@ def preprocess(
if name_to_node_mappings[name].meta["val"].dtype == torch.float32
]

# This default compile options are only for mt6989 SOC
compile_options = ["--arch=mdla5.1,edpa1.0", "--relax-fp32", "--opt=3"]
compile_options = ["--relax-fp32", "--opt=3"]
for spec in module_compile_spec:
if spec.key in SKIP_COMPILE_SPEC_KEYS:
continue
Expand Down
3 changes: 2 additions & 1 deletion examples/mediatek/aot_utils/oss_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
NeuropilotQuantizer,
Precision,
)
from executorch.exir.backend.backend_details import CompileSpec
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e


Expand Down Expand Up @@ -48,7 +49,7 @@ def build_executorch_binary(
edge_compile_config = exir.EdgeCompileConfig(_check_ir_validity=False)
# skipped op names are used for deeplabV3 model
neuro_partitioner = NeuropilotPartitioner(
[],
[CompileSpec("platform-config", b"mt6989")],
op_names_to_skip={
"aten_convolution_default_106",
"aten_convolution_default_107",
Expand Down
7 changes: 4 additions & 3 deletions examples/mediatek/model_export_scripts/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,11 @@ def export_to_et_ir(

print("Delegating Edge Program to Neuropilot Backend")
compile_spec = [
CompileSpec("gno", struct.pack("3s", b"LTS")),
CompileSpec("gno-exp", struct.pack("0s", b"")),
CompileSpec("gno-non-4d-tiling", struct.pack("0s", b"")),
CompileSpec("gno", b"LTS"),
CompileSpec("gno-exp", b""),
CompileSpec("gno-non-4d-tiling", b""),
CompileSpec("ImportForever", struct.pack("?", True)),
CompileSpec("platform-config", b"mt6989"),
]
partitioner = NeuropilotPartitioner(compile_spec)
delegated_program = edge_program.to_backend(partitioner)
Expand Down
Loading