From 400831a83fcd3658fb4eceac89886b0654b9a94f Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Wed, 27 Nov 2024 15:32:37 -0800 Subject: [PATCH] Fix cadence BUCK deps and pyre (#7116) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/7116 Reviewed By: davidlin54 Differential Revision: D66553586 --- backends/cadence/runtime/TARGETS | 1 + backends/cadence/runtime/runtime.py | 3 --- backends/cadence/runtime/utils.py | 16 +++------------- examples/cadence/operators/test_add_op.py | 2 ++ extension/llm/export/quantizer_lib.py | 2 -- 5 files changed, 6 insertions(+), 18 deletions(-) diff --git a/backends/cadence/runtime/TARGETS b/backends/cadence/runtime/TARGETS index db3fe0ad1e6..95a7bdc3694 100644 --- a/backends/cadence/runtime/TARGETS +++ b/backends/cadence/runtime/TARGETS @@ -18,6 +18,7 @@ python_library( "//executorch/devtools/bundled_program:config", "//executorch/devtools/bundled_program:core", "//executorch/devtools/bundled_program/serialize:lib", + "//executorch/devtools:lib", "//executorch/exir:lib", ], ) diff --git a/backends/cadence/runtime/runtime.py b/backends/cadence/runtime/runtime.py index bf2932d9c79..0268931c409 100644 --- a/backends/cadence/runtime/runtime.py +++ b/backends/cadence/runtime/runtime.py @@ -167,9 +167,7 @@ def run( def compare( - # pyre-fixme[2]: Parameter annotation cannot be `Any`. outputs: Any, - # pyre-fixme[2]: Parameter annotation cannot be `Any`. ref_outputs: Any, name: str = "", eps_error: float = 1e-1, @@ -223,7 +221,6 @@ def run_and_compare( compare(outputs, ref_outputs, eps_error=eps_error, eps_warn=eps_warn) -# pyre-fixme[24]: Generic type `np.ndarray` expects 2 type parameters. def to_nd_array(v: Union[bool, numbers.Number, ndarray, torch.Tensor]) -> np.ndarray: if isinstance(v, np.ndarray): return v diff --git a/backends/cadence/runtime/utils.py b/backends/cadence/runtime/utils.py index b3ed622e8b2..0a85b6dd618 100644 --- a/backends/cadence/runtime/utils.py +++ b/backends/cadence/runtime/utils.py @@ -13,12 +13,11 @@ import torch -# pyre-fixme[24]: Generic type `np.ndarray` expects 2 type parameters. -def distance(fn: Callable[[np.ndarray, np.ndarray], float]) -> Callable[ +def distance( + fn: Callable[[np.ndarray, np.ndarray], float], +) -> Callable[ [ - # pyre-fixme[24]: Generic type `np.ndarray` expects 2 type parameters. typing.Union[np.ndarray, torch._tensor.Tensor], - # pyre-fixme[24]: Generic type `np.ndarray` expects 2 type parameters. typing.Union[np.ndarray, torch._tensor.Tensor], ], float, @@ -27,9 +26,7 @@ def distance(fn: Callable[[np.ndarray, np.ndarray], float]) -> Callable[ # the distance between two N-D tensors given a function. This can be a RMS # function, maximum abs diff, or any kind of distance function. def wrapper( - # pyre-fixme[24]: Generic type `np.ndarray` expects 2 type parameters. a: Union[np.ndarray, torch.Tensor], - # pyre-fixme[24]: Generic type `np.ndarray` expects 2 type parameters. b: Union[np.ndarray, torch.Tensor], ) -> float: # convert a and b to np.ndarray type fp64 @@ -68,24 +65,20 @@ def wrapper( @distance -# pyre-fixme[24]: Generic type `np.ndarray` expects 2 type parameters. def rms(a: np.ndarray, b: np.ndarray) -> float: return ((a - b) ** 2).mean() ** 0.5 @distance -# pyre-fixme[24]: Generic type `np.ndarray` expects 2 type parameters. def max_abs_diff(a: np.ndarray, b: np.ndarray) -> float: return np.abs(a - b).max() @distance -# pyre-fixme[24]: Generic type `np.ndarray` expects 2 type parameters. def max_rel_diff(x: np.ndarray, x_ref: np.ndarray) -> float: return np.abs((x - x_ref) / x_ref).max() -# pyre-fixme[24]: Generic type `np.ndarray` expects 2 type parameters. def to_np_arr_fp64(x: Union[np.ndarray, torch.Tensor]) -> np.ndarray: if isinstance(x, torch.Tensor): x = x.detach().cpu().numpy() @@ -94,11 +87,8 @@ def to_np_arr_fp64(x: Union[np.ndarray, torch.Tensor]) -> np.ndarray: return x -# pyre-fixme[3]: Return type must be annotated. def normalized_rms( - # pyre-fixme[24]: Generic type `np.ndarray` expects 2 type parameters. predicted: Union[np.ndarray, torch.Tensor], - # pyre-fixme[24]: Generic type `np.ndarray` expects 2 type parameters. ground_truth: Union[np.ndarray, torch.Tensor], ): num = rms(predicted, ground_truth) diff --git a/examples/cadence/operators/test_add_op.py b/examples/cadence/operators/test_add_op.py index 5481540b4f7..7799fe624bb 100644 --- a/examples/cadence/operators/test_add_op.py +++ b/examples/cadence/operators/test_add_op.py @@ -13,6 +13,7 @@ class ATenOpTestCases(unittest.TestCase): + # pyre-fixme[16]: Module `parameterized.parameterized` has no attribute `expand`. @parameterized.expand( [ [(7, 5, 6), (7, 5, 6)], @@ -61,6 +62,7 @@ def forward(self, x: torch.Tensor, y: torch.Tensor): model, (X, Y), file_name=self._testMethodName, run_and_compare=False ) + # pyre-fixme[16]: Module `parameterized.parameterized` has no attribute `expand`. @parameterized.expand( [ [(7, 5, 6), (7, 5, 6)], diff --git a/extension/llm/export/quantizer_lib.py b/extension/llm/export/quantizer_lib.py index ba281864a9f..3a9eebd2c36 100644 --- a/extension/llm/export/quantizer_lib.py +++ b/extension/llm/export/quantizer_lib.py @@ -184,14 +184,12 @@ def get_qnn_quantizer( ) qnn_quantizer.set_per_channel_conv_quant(enable=False) qnn_quantizer.set_per_channel_linear_quant(enable=False) - # pyre-ignore: Undefined attribute [16]: Module `executorch.backends` has no attribute `qualcomm`. qnn_quantizer.set_quant_config( quant_dtype, is_qat=is_qat, act_observer=MinMaxObserver ) elif quant_config == "16a4w": # pyre-ignore: Undefined attribute [16]: Module `executorch.backends` has no attribute `qualcomm`. quant_dtype = QuantDtype.use_16a4w - # pyre-ignore: Undefined attribute [16]: Module `executorch.backends` has no attribute `qualcomm`. qnn_quantizer.set_quant_config( quant_dtype, is_qat=is_qat, act_observer=MinMaxObserver )