diff --git a/backends/samsung/_passes/conv1d_to_conv2d.py b/backends/samsung/_passes/conv1d_to_conv2d.py index 5a5daf70938..d59875022d3 100644 --- a/backends/samsung/_passes/conv1d_to_conv2d.py +++ b/backends/samsung/_passes/conv1d_to_conv2d.py @@ -42,7 +42,9 @@ def update_kernel(self, weight_node: torch.Tensor): weight_3d, -1 ) else: - RuntimeError("Weight of 1d conv should be constant tensor or Parameter obj") + raise RuntimeError( + "Weight of 1d conv should be constant tensor or Parameter obj" + ) weight_node.meta["val"] = weight_node.meta["val"].data.unsqueeze(dim=-1) def call(self, graph_module: torch.fx.GraphModule): diff --git a/backends/xnnpack/operators/node_visitor.py b/backends/xnnpack/operators/node_visitor.py index 160ee03c765..1963e4494fd 100644 --- a/backends/xnnpack/operators/node_visitor.py +++ b/backends/xnnpack/operators/node_visitor.py @@ -475,7 +475,10 @@ def define_tensor( # noqa: C901 elif quant_params.axis == 1: quant_params.axis = 0 else: - assert f"Unsupported weight per channel quantization axis for depthwise conv2d / conv_transpose2d : {quant_params.axis}, expecting 0 / 1." + check_or_raise( + False, + f"Unsupported weight per channel quantization axis for depthwise conv2d / conv_transpose2d : {quant_params.axis}, expecting 0 / 1.", + ) # Serialize tensor value custom_meta = tensor.meta.get("custom", None) diff --git a/export/export.py b/export/export.py index 8dd48dd9eaa..627e6ab38ce 100644 --- a/export/export.py +++ b/export/export.py @@ -714,7 +714,7 @@ def print_delegation_info(self) -> None: ) if not lowering_stage: raise RuntimeError( - "No delegation info available, atleast one of the lowering stages should be present" + "No delegation info available, at least one of the lowering stages should be present" ) stage_artifact = self._stage_to_artifacts.get(lowering_stage[0]) diff --git a/export/tests/test_print_delegation_info.py b/export/tests/test_print_delegation_info.py new file mode 100644 index 00000000000..71d30ee9745 --- /dev/null +++ b/export/tests/test_print_delegation_info.py @@ -0,0 +1,48 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + + +import unittest + +import torch +from executorch.export import ExportRecipe, ExportSession +from executorch.export.types import StageType + + +class Tiny(torch.nn.Module): + def forward(self, x: torch.Tensor) -> torch.Tensor: + return x + 1 + + +class TestPrintDelegationInfoGuards(unittest.TestCase): + def test_print_delegation_info_requires_a_lowering_stage(self) -> None: + session = ExportSession( + model=Tiny(), + example_inputs=[(torch.randn(2, 3),)], + export_recipe=ExportRecipe( + name="test", + pipeline_stages=[StageType.TORCH_EXPORT], + ), + ) + with self.assertRaises(RuntimeError) as cm: + session.print_delegation_info() + self.assertIn("at least one of the lowering stages", str(cm.exception)) + + def test_print_delegation_info_requires_lowering_artifact(self) -> None: + session = ExportSession( + model=Tiny(), + example_inputs=[(torch.randn(2, 3),)], + export_recipe=ExportRecipe( + name="test", + pipeline_stages=[ + StageType.TORCH_EXPORT, + StageType.TO_EDGE_TRANSFORM_AND_LOWER, + ], + ), + ) + with self.assertRaises(RuntimeError) as cm: + session.print_delegation_info() + self.assertIn("run the lowering stage first", str(cm.exception))