Skip to content

Commit dac4306

Browse files
Introduce required platform-config key in CompileSpec settings
1 parent 5785fc3 commit dac4306

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
@final
@@ -30,6 +32,28 @@ def preprocess(
3032
cls, edge_program: ExportedProgram, module_compile_spec: List[CompileSpec]
3133
) -> PreprocessResult:
3234

35+
# Validate CompileSpec settings
36+
compile_spec_keys = [spec.key for spec in module_compile_spec]
37+
if len(compile_spec_keys) != len(set(compile_spec_keys)):
38+
raise RuntimeError(
39+
"Unsupported duplicated keys in the CompileSpec settings."
40+
)
41+
if not REQUIRED_COMPILE_SPEC_KEYS.issubset(set(compile_spec_keys)):
42+
raise RuntimeError(
43+
"Following keys are required in the CompileSpec settings: {}."
44+
"".format(REQUIRED_COMPILE_SPEC_KEYS)
45+
)
46+
platform = [
47+
spec.value.decode("utf-8")
48+
for spec in module_compile_spec
49+
if spec.key == "platform-config"
50+
][0]
51+
if platform not in SUPPORTED_PLATFORM_CONFIGS:
52+
raise ValueError(
53+
"Unsupported value of platform-config CompileSpec. Given {} but expected to be one "
54+
"of {}.".format(platform, SUPPORTED_PLATFORM_CONFIGS)
55+
)
56+
3357
name_to_node_mappings = {node.name: node for node in edge_program.graph.nodes}
3458
input_names = edge_program.graph_signature.user_inputs
3559
output_names = edge_program.graph_signature.user_outputs
@@ -44,8 +68,7 @@ def preprocess(
4468
if name_to_node_mappings[name].meta["val"].dtype == torch.float32
4569
]
4670

47-
# This default compile options are only for mt6989 SOC
48-
compile_options = ["--arch=mdla5.1,edpa1.0", "--relax-fp32", "--opt=3"]
71+
compile_options = ["--relax-fp32", "--opt=3"]
4972
for spec in module_compile_spec:
5073
if spec.key in SKIP_COMPILE_SPEC_KEYS:
5174
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

@@ -46,7 +47,7 @@ def build_executorch_binary(
4647
edge_compile_config = exir.EdgeCompileConfig(_check_ir_validity=False)
4748
# skipped op names are used for deeplabV3 model
4849
neuro_partitioner = NeuropilotPartitioner(
49-
[],
50+
[CompileSpec("platform-config", b"mt6989")],
5051
op_names_to_skip={
5152
"aten_convolution_default_106",
5253
"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)