Skip to content

Commit 7823792

Browse files
authored
Revert "Arm backend: Make setting artifact_path optional for tests" (#17288)
This reverts commit 52bdacc. ### Summary This is breaking internal CI in https://www.internalfb.com/diff/D92366066 Specifically, breaking CI for all the _INT variant tests across multiple ops (avg_pool2d, tanh, rsqrt, conv2d, cat, addmm, add). cc @psiddh
1 parent dda15fd commit 7823792

4 files changed

Lines changed: 49 additions & 28 deletions

File tree

backends/arm/test/common.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# Copyright 2024-2026 Arm Limited and/or its affiliates.
1+
# Copyright 2024-2025 Arm Limited and/or its affiliates.
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

66

77
import os
88

9+
import tempfile
910
from datetime import datetime
1011

1112
from pathlib import Path
@@ -94,8 +95,9 @@ def get_u55_compile_spec(
9495
"""Default compile spec for Ethos-U55 tests."""
9596
if not custom_path:
9697
custom_path = maybe_get_tosa_collate_path()
97-
if custom_path is not None:
98-
os.makedirs(custom_path, exist_ok=True)
98+
artifact_path = custom_path or tempfile.mkdtemp(prefix="arm_u55_")
99+
if not os.path.exists(artifact_path):
100+
os.makedirs(artifact_path, exist_ok=True)
99101

100102
# https://gitlab.arm.com/artificial-intelligence/ethos-u/ethos-u-vela/-/blob/main/OPTIONS.md
101103
assert macs in [32, 64, 128, 256], "Unsupported MACs value"
@@ -112,7 +114,7 @@ def get_u55_compile_spec(
112114
extra_flags=extra_flags_list,
113115
config_ini=config,
114116
)
115-
.dump_intermediate_artifacts_to(custom_path)
117+
.dump_intermediate_artifacts_to(artifact_path)
116118
.dump_debug_info(tosa_debug_mode)
117119
)
118120
return compile_spec
@@ -131,8 +133,9 @@ def get_u85_compile_spec(
131133

132134
if not custom_path:
133135
custom_path = maybe_get_tosa_collate_path()
134-
if custom_path is not None:
135-
os.makedirs(custom_path, exist_ok=True)
136+
artifact_path = custom_path or tempfile.mkdtemp(prefix="arm_u85_")
137+
if not os.path.exists(artifact_path):
138+
os.makedirs(artifact_path, exist_ok=True)
136139

137140
assert macs in [128, 256, 512, 1024, 2048], "Unsupported MACs value"
138141

@@ -149,7 +152,7 @@ def get_u85_compile_spec(
149152
extra_flags=extra_flags_list,
150153
config_ini=config,
151154
)
152-
.dump_intermediate_artifacts_to(custom_path)
155+
.dump_intermediate_artifacts_to(artifact_path)
153156
.dump_debug_info(tosa_debug_mode)
154157
)
155158
return compile_spec # type: ignore[return-value]
@@ -175,16 +178,25 @@ def get_vgf_compile_spec(
175178
if len(profiles) == 0:
176179
raise ValueError(f"Unsupported vgf compile_spec: {repr(tosa_spec)}")
177180

178-
if custom_path is not None:
179-
os.makedirs(custom_path, exist_ok=True)
181+
if custom_path is None:
182+
artifact_path = "arm_vgf_"
183+
for profile in profiles:
184+
artifact_path = artifact_path + f"_{profile}"
185+
artifact_path = tempfile.mkdtemp(artifact_path)
186+
else:
187+
artifact_path = custom_path
188+
189+
if not os.path.exists(artifact_path):
190+
os.makedirs(artifact_path, exist_ok=True)
191+
180192
if compiler_flags is not None:
181193
compiler_flags_list = compiler_flags.split(" ")
182194
else:
183195
compiler_flags_list = []
184196

185197
compile_spec = (
186198
VgfCompileSpec(tosa_spec, compiler_flags_list)
187-
.dump_intermediate_artifacts_to(custom_path)
199+
.dump_intermediate_artifacts_to(artifact_path)
188200
.dump_debug_info(tosa_debug_mode)
189201
)
190202

backends/arm/test/tester/arm_tester.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import copy
77

88
import logging
9+
import shutil
10+
import tempfile
911

1012
from collections import Counter, defaultdict
1113
from pprint import pformat
@@ -410,6 +412,10 @@ def serialize(
410412
use_portable_ops=self.use_portable_ops,
411413
timeout=self.timeout,
412414
)
415+
assert (
416+
self.compile_spec.get_intermediate_path() is not None
417+
), "Can't dump serialized file when compile specs do not contain an artifact path."
418+
413419
return super().serialize(serialize_stage)
414420

415421
def is_quantized(self) -> bool:
@@ -987,6 +993,14 @@ def _compare_outputs(
987993
)
988994
raise e
989995

996+
def __del__(self):
997+
intermediate_path = self.compile_spec.get_intermediate_path()
998+
if not intermediate_path:
999+
return
1000+
if len(tempdir := tempfile.gettempdir()) > 0:
1001+
if intermediate_path.startswith(tempdir):
1002+
shutil.rmtree(intermediate_path, ignore_errors=True)
1003+
9901004
def check_dtype_count(self, dtype_dict: Dict[str, Dict[str, int]]):
9911005
if self.cur in (
9921006
StageType.PARTITION,

backends/arm/test/tester/serialize.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
# Copyright 2024-2026 Arm Limited and/or its affiliates.
1+
# Copyright 2024-2025 Arm Limited and/or its affiliates.
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

66
import logging
77
import os
8-
import tempfile
98
from typing import Optional
109

1110
import executorch.backends.xnnpack.test.tester.tester as tester
@@ -69,21 +68,11 @@ def run_artifact(self, inputs):
6968
f"Did not find build arm_executor_runner in path {elf_path}, run setup_testing.sh?"
7069
)
7170

72-
tempdir_context = None
73-
if intermediate_path is None:
74-
tempdir_context = tempfile.TemporaryDirectory()
75-
intermediate_path = tempdir_context.name
76-
77-
result = run_target(
71+
return run_target(
7872
self.executorch_program_manager,
7973
inputs_flattened,
8074
intermediate_path,
8175
target_board,
8276
elf_path,
8377
self.timeout,
8478
)
85-
86-
if tempdir_context:
87-
tempdir_context.cleanup()
88-
89-
return result

backends/arm/tosa/backend.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""
1717

1818
import logging
19+
import tempfile
1920
from itertools import count
2021
from typing import cast, Dict, final, List
2122

@@ -246,11 +247,16 @@ def _preprocess( # noqa: C901
246247

247248
if artifact_path:
248249
tag = arm_get_first_delegation_tag(edge_program.graph_module)
249-
debug_tosa_dump(
250-
binary,
251-
artifact_path,
252-
suffix="{}".format(f"_{tag}" if tag else "") + (f"_{tosa_spec}"),
253-
)
250+
251+
# Only dump TOSA if we are not saving to temporary folder.
252+
if len(
253+
tempdir := tempfile.gettempdir()
254+
) > 0 and not artifact_path.startswith(tempdir):
255+
debug_tosa_dump(
256+
binary,
257+
artifact_path,
258+
suffix="{}".format(f"_{tag}" if tag else "") + (f"_{tosa_spec}"),
259+
)
254260

255261
if debug_hook is not None:
256262
if debug_hook.mode == ArmCompileSpec.DebugMode.JSON:

0 commit comments

Comments
 (0)