Skip to content

Skip annotate boolean input (#2957) #3051

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 2 commits into from
Apr 17, 2024
Merged
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
18 changes: 16 additions & 2 deletions backends/qualcomm/quantizer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import torch

from torch._ops import OpOverload
from torch._subclasses import FakeTensor

from torch.ao.quantization.quantizer import (
QuantizationAnnotation,
Expand Down Expand Up @@ -42,6 +43,19 @@ def decorator(annotator: Callable):
return decorator


def _is_input_float_tensor(node: Node):
"""Check if the input is not a float tensor, so that we can skip quantization for the node
since observers only works with float Tensors
"""
if (
not isinstance(node, Node)
or "val" not in node.meta
or not isinstance(node.meta["val"], FakeTensor)
):
return False
return node.meta["val"].dtype == torch.float32


def _is_annotated(nodes: List[Node]):
"""
Given a list of nodes (that represents an operator pattern),
Expand Down Expand Up @@ -123,11 +137,11 @@ def annotate_binary(node: Node, quantization_config: QuantizationConfig) -> None

input_qspec_map = {}
input_act0 = node.args[0]
if isinstance(input_act0, Node):
if _is_input_float_tensor(input_act0):
input_qspec_map[input_act0] = input_act_qspec

input_act1 = node.args[1]
if isinstance(input_act1, Node):
if _is_input_float_tensor(input_act1):
input_qspec_map[input_act1] = input_act_qspec

node.meta[QUANT_ANNOTATION_KEY] = QuantizationAnnotation(
Expand Down
Loading