Skip to content

Commit ad92fd5

Browse files
authored
Merge branch 'main' into jathu/default-processor
2 parents 12d05f4 + 879235b commit ad92fd5

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

backends/mediatek/preprocess.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from executorch.exir.backend.compile_spec_schema import CompileSpec
2121

2222
SKIP_COMPILE_SPEC_KEYS = {"ImportForever"}
23+
REQUIRED_COMPILE_SPEC_KEYS = {"platform-config"}
24+
SUPPORTED_PLATFORM_CONFIGS = {"mt6989", "mt6991"}
2325

2426

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

52+
# Validate CompileSpec settings
53+
compile_spec_keys = [spec.key for spec in module_compile_spec]
54+
if len(compile_spec_keys) != len(set(compile_spec_keys)):
55+
raise RuntimeError(
56+
"Unsupported duplicated keys in the CompileSpec settings."
57+
)
58+
if not REQUIRED_COMPILE_SPEC_KEYS.issubset(set(compile_spec_keys)):
59+
raise RuntimeError(
60+
"Following keys are required in the CompileSpec settings: {}."
61+
"".format(REQUIRED_COMPILE_SPEC_KEYS)
62+
)
63+
platform = [
64+
spec.value.decode("utf-8")
65+
for spec in module_compile_spec
66+
if spec.key == "platform-config"
67+
][0]
68+
if platform not in SUPPORTED_PLATFORM_CONFIGS:
69+
raise ValueError(
70+
"Unsupported value of platform-config CompileSpec. Given {} but expected to be one "
71+
"of {}.".format(platform, SUPPORTED_PLATFORM_CONFIGS)
72+
)
73+
5074
# Make sure all inputs are contiguous_format or NCHW or default dim order
5175
assert_default_dim_order(edge_program.graph_module)
5276

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

67-
# This default compile options are only for mt6989 SOC
68-
compile_options = ["--arch=mdla5.1,edpa1.0", "--relax-fp32", "--opt=3"]
91+
compile_options = ["--relax-fp32", "--opt=3"]
6992
for spec in module_compile_spec:
7093
if spec.key in SKIP_COMPILE_SPEC_KEYS:
7194
continue

examples/mediatek/aot_utils/oss_utils/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
NeuropilotQuantizer,
1515
Precision,
1616
)
17+
from executorch.exir.backend.backend_details import CompileSpec
1718
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e
1819

1920

@@ -48,7 +49,7 @@ def build_executorch_binary(
4849
edge_compile_config = exir.EdgeCompileConfig(_check_ir_validity=False)
4950
# skipped op names are used for deeplabV3 model
5051
neuro_partitioner = NeuropilotPartitioner(
51-
[],
52+
[CompileSpec("platform-config", b"mt6989")],
5253
op_names_to_skip={
5354
"aten_convolution_default_106",
5455
"aten_convolution_default_107",

examples/mediatek/model_export_scripts/llama.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,11 @@ def export_to_et_ir(
350350

351351
print("Delegating Edge Program to Neuropilot Backend")
352352
compile_spec = [
353-
CompileSpec("gno", struct.pack("3s", b"LTS")),
354-
CompileSpec("gno-exp", struct.pack("0s", b"")),
355-
CompileSpec("gno-non-4d-tiling", struct.pack("0s", b"")),
353+
CompileSpec("gno", b"LTS"),
354+
CompileSpec("gno-exp", b""),
355+
CompileSpec("gno-non-4d-tiling", b""),
356356
CompileSpec("ImportForever", struct.pack("?", True)),
357+
CompileSpec("platform-config", b"mt6989"),
357358
]
358359
partitioner = NeuropilotPartitioner(compile_spec)
359360
delegated_program = edge_program.to_backend(partitioner)

0 commit comments

Comments
 (0)