Skip to content

Commit 50fe3b3

Browse files
Arm backend: Use correct log-level in tests (#15545)
Arm tests logged too much as comparisons with logger.level were used instead of logger.getEffectiveLevel(). logger.level will always be logging.NOTSET unless explicitly set with logger.setLevel() which we want to avoid. Instead, we should use logger.getEffectiveLevel() which will inherit the level from its parent. Signed-off-by: Oscar Andersson <[email protected]>
1 parent 15a0fcd commit 50fe3b3

File tree

10 files changed

+14
-21
lines changed

10 files changed

+14
-21
lines changed

backends/arm/_passes/decompose_embedding_pass.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from .arm_pass_utils import create_node, get_first_fake_tensor
1818

1919
logger = logging.getLogger(__name__)
20-
logger.setLevel(logging.WARNING)
2120

2221

2322
class DecomposeEmbeddingPass(ArmPass):

backends/arm/ethosu/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _compile_tosa_flatbuffer(
6363
binary = vela_compile(
6464
tosa_flatbuffer,
6565
compile_flags,
66-
verbose=logger.getEffectiveLevel() == logging.INFO,
66+
verbose=logger.getEffectiveLevel() <= logging.INFO,
6767
intermediate_path=compile_spec.get_intermediate_path(),
6868
)
6969
return binary

backends/arm/operator_support/right_shift_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ def is_node_tosa_supported(
4848
"""
4949
# TODO MLETORCH-525 Remove warning
5050
if tosa_spec.is_U55_subset:
51-
logging.warning(f"{node.target} may introduce one-off errors.")
51+
logger.warning(f"{node.target} may introduce one-off errors.")
5252
return True

backends/arm/operator_support/slice_copy_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ def is_node_tosa_supported(self, node: fx.Node, tosa_spec: TosaSpecification) ->
3232

3333
args = node.args
3434
if len(args) == 5 and (step := args[4]) != 1:
35-
logging.warning(f"{node.target} with step size of {step} not supported.")
35+
logger.warning(f"{node.target} with step size of {step} not supported.")
3636
return False
3737
return True

backends/arm/test/conftest.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
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

6-
import logging
76
import os
87
import random
9-
import sys
108
from typing import Any
119

1210
import pytest
@@ -29,8 +27,6 @@ def pytest_configure(config):
2927
if config.option.arm_run_tosa_version:
3028
pytest._test_options["tosa_version"] = config.option.arm_run_tosa_version
3129

32-
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
33-
3430

3531
def pytest_collection_modifyitems(config, items):
3632
pass

backends/arm/test/misc/test_debug_feats.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
)
2424
from executorch.backends.test.harness.stages import StageType
2525

26-
2726
input_t1 = Tuple[torch.Tensor] # Input x
2827

2928

@@ -261,14 +260,14 @@ def test_dump_tosa_debug_tosa(test_data: input_t1):
261260

262261

263262
@common.parametrize("test_data", Linear.inputs)
264-
def test_dump_tosa_ops(caplog, test_data: input_t1):
263+
def test_dump_tosa_ops(capsys, test_data: input_t1):
265264
aten_ops: list[str] = []
266265
exir_ops: list[str] = []
267266
pipeline = TosaPipelineINT[input_t1](Linear(), test_data, aten_ops, exir_ops)
268267
pipeline.pop_stage("run_method_and_compare_outputs")
269268
pipeline.dump_operator_distribution("to_edge_transform_and_lower")
270269
pipeline.run()
271-
assert "TOSA operators:" in caplog.text
270+
assert "TOSA operators:" in capsys.readouterr().out
272271

273272

274273
class Add(torch.nn.Module):
@@ -282,12 +281,15 @@ def forward(self, x):
282281

283282
@common.parametrize("test_data", Add.inputs)
284283
@common.XfailIfNoCorstone300
285-
def test_fail_dump_tosa_ops(caplog, test_data: input_t1):
284+
def test_fail_dump_tosa_ops(capsys, test_data: input_t1):
286285
aten_ops: list[str] = []
287286
exir_ops: list[str] = []
288287
pipeline = EthosU55PipelineINT[input_t1](
289288
Add(), test_data, aten_ops, exir_ops, use_to_edge_transform_and_lower=True
290289
)
291290
pipeline.dump_operator_distribution("to_edge_transform_and_lower")
292291
pipeline.run()
293-
assert "Can not get operator distribution for Vela command stream." in caplog.text
292+
assert (
293+
"Can not get operator distribution for Vela command stream."
294+
in capsys.readouterr().out
295+
)

backends/arm/test/models/test_deit_tiny_arm.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from torchvision import transforms
2424

2525
logger = logging.getLogger(__name__)
26-
logger.setLevel(logging.INFO)
2726

2827

2928
deit_tiny = timm.models.deit.deit_tiny_patch16_224(pretrained=True)

backends/arm/test/runner_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,11 +763,11 @@ def run_tosa_graph(
763763
if isinstance(tosa_version, Tosa_1_00):
764764
import tosa_reference_model as reference_model # type: ignore[import-untyped]
765765

766-
debug_mode = "ALL" if logger.level <= logging.DEBUG else None
766+
debug_mode = "ALL" if logger.getEffectiveLevel() <= logging.DEBUG else None
767767
outputs_np, status = reference_model.run(
768768
graph,
769769
inputs_np,
770-
verbosity=_tosa_refmodel_loglevel(logger.level),
770+
verbosity=_tosa_refmodel_loglevel(logger.getEffectiveLevel()),
771771
initialize_variable_tensor_from_numpy=True,
772772
debug_mode=debug_mode,
773773
)

backends/arm/test/tester/analyze_output_utils.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,8 @@ def dump_error_output(
312312

313313

314314
if __name__ == "__main__":
315-
import sys
316315

317-
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
318-
319-
""" This is expected to produce the example output of print_diff"""
316+
"""This is expected to produce the example output of print_diff"""
320317
torch.manual_seed(0)
321318
a = torch.rand(3, 3, 2, 2) * 0.01
322319
b = a.clone().detach()

backends/arm/test/tester/arm_tester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ def _dump_str(to_print: str, path_to_dump: Optional[str] = None):
832832
with open(path_to_dump, "a") as fp:
833833
fp.write(to_print)
834834
else:
835-
logger.info(to_print)
835+
print(to_print)
836836

837837

838838
def _format_dict(to_print: dict, print_table: bool = True) -> str:

0 commit comments

Comments
 (0)