Skip to content
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

Skip annotate boolean input #2999

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 15 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 @@ -41,6 +42,18 @@ def decorator(annotator: Callable):

return decorator

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add empty line

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]):
"""
Expand Down Expand Up @@ -123,11 +136,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