Skip to content

Add a target rule for ops_registrations (#5083) #5191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions backends/cadence/aot/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 9 additions & 8 deletions backends/cadence/aot/ops_registrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand All @@ -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)


Expand All @@ -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]
Expand Down Expand Up @@ -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)


Expand All @@ -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)


Expand Down
Loading