From 43181f57d9eaf4856003309e1508d80970b4879f Mon Sep 17 00:00:00 2001 From: Yi Li Date: Mon, 9 Sep 2024 14:05:24 -0700 Subject: [PATCH] Add a target rule for ops_registrations (#5191) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/5191 Pull Request resolved: https://github.com/pytorch/executorch/pull/5083 Add a target rule for ops_registrations in the OSS repo to enable including this in fb repo Reviewed By: zonglinpeng, hsharma35 Differential Revision: D62206605 --- backends/cadence/aot/TARGETS | 11 +++++++++++ backends/cadence/aot/ops_registrations.py | 17 +++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/backends/cadence/aot/TARGETS b/backends/cadence/aot/TARGETS index d077169022a..08093efe317 100644 --- a/backends/cadence/aot/TARGETS +++ b/backends/cadence/aot/TARGETS @@ -60,6 +60,17 @@ python_library( ], ) +python_library( + name = "ops_registrations", + srcs = [ + "ops_registrations.py", + ], + deps = [ + "fbcode//caffe2:torch", + "fbcode//executorch/backends/cadence/aot:utils", + ], +) + export_file(name = "functions.yaml") executorch_generated_lib( diff --git a/backends/cadence/aot/ops_registrations.py b/backends/cadence/aot/ops_registrations.py index a4d856ebed2..a5e00573918 100644 --- a/backends/cadence/aot/ops_registrations.py +++ b/backends/cadence/aot/ops_registrations.py @@ -4,11 +4,12 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. +# pyre-strict + from math import prod from typing import Optional, Tuple import torch -from executorch.exir.scalar_type import ScalarType from torch.library import impl, Library from .utils import get_conv1d_output_size, get_conv2d_output_size @@ -74,8 +75,8 @@ def quantize_per_tensor_meta( zero_point: int, quant_min: int, quant_max: int, - dtype: ScalarType, -): + dtype: torch.dtype, +) -> torch.Tensor: return input.new_empty(input.size(), dtype=dtype) @@ -86,8 +87,8 @@ def dequantize_per_tensor_meta( zero_point: int, quant_min: int, quant_max: int, - dtype: ScalarType, -): + dtype: torch.dtype, +) -> torch.Tensor: return input.new_empty(input.size(), dtype=torch.float) @@ -102,7 +103,7 @@ def quantized_linear_meta( out_shift: torch.Tensor, out_zero_point: int, offset: Optional[torch.Tensor], -): +) -> torch.Tensor: # src comes in shape [leading_dims, in_dim] # weight comes in shape [out_dim, in_dim] # output comes in empty with shape [leading_dims, out_dim] @@ -162,7 +163,7 @@ def quantized_layer_norm_meta( eps: float, output_scale: float, output_zero_point: int, -): +) -> torch.Tensor: return input.new_empty(input.size(), dtype=torch.uint8) @@ -173,7 +174,7 @@ def quantized_relu_meta( out_zero_point: int, out_multiplier: torch.Tensor, out_shift: torch.Tensor, -): +) -> torch.Tensor: return X.new_empty(X.size(), dtype=torch.uint8)