Skip to content

Add small repro test for unsigned -> signed et loss error #8506

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
Feb 19, 2025
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
1 change: 1 addition & 0 deletions backends/cadence/aot/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ python_library(
typing = True,
deps = [
"//caffe2:torch",
":ops_registrations",
":compiler_utils",
"//executorch/backends/cadence/aot:pass_utils",
"//executorch/backends/cadence/aot:utils",
Expand Down
8 changes: 7 additions & 1 deletion backends/cadence/aot/fuse_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from numbers import Number
from typing import cast, Sequence

# Import these for the cadence function signatures.
import executorch.backends.cadence.aot.ops_registrations # noqa: F401
Copy link
Contributor

Choose a reason for hiding this comment

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

This line broke the linter job: https://github.com/pytorch/executorch/actions/runs/13398623818/job/37423762070#step:15:7593

I think it needs two spaces before the #. Please run lintrunner -a to fix this, and make sure that the job is passing before merging PRs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sent #8575 to fix this


import torch
import torch.fx
from executorch.backends.cadence.aot.compiler_utils import (
Expand Down Expand Up @@ -849,7 +852,10 @@ def attempt_fusion(
if isinstance(arg, torch.fx.Node)
and isinstance(arg.target, EdgeOpOverload)
and get_edge_overload_packet(arg.target)
== exir_ops.edge.quantized_decomposed.dequantize_per_tensor
in (
exir_ops.edge.quantized_decomposed.dequantize_per_tensor,
exir_ops.edge.cadence.dequantize_per_tensor,
)
]
multiplier_nodes = [
arg
Expand Down
2 changes: 2 additions & 0 deletions backends/cadence/aot/remove_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ class Subgraph:
exir_ops.edge.aten.hardtanh.default,
exir_ops.edge.quantized_decomposed.quantize_per_tensor.default,
exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default,
exir_ops.edge.cadence.quantize_per_tensor.default,
exir_ops.edge.cadence.dequantize_per_tensor.default,
}

# must be initialized in the constructor
Expand Down
8 changes: 8 additions & 0 deletions backends/cadence/aot/reorder_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def get_descendent_quant_ops(self, node: torch.fx.Node) -> List[torch.fx.Node]:
if user_target in {
torch.ops.quantized_decomposed.quantize_per_tensor,
exir_ops.edge.quantized_decomposed.quantize_per_tensor,
torch.ops.cadence.quantize_per_tensor,
exir_ops.edge.cadence.quantize_per_tensor,
}:
descendent_quant_ops.append(user)
# If the successor is a trivially quantizable op, consider its users
Expand Down Expand Up @@ -300,6 +302,8 @@ def advance_quantize_op(self, graph_module: torch.fx.GraphModule):
if get_overload_packet(node.target) not in (
exir_ops.edge.quantized_decomposed.quantize_per_tensor,
torch.ops.quantized_decomposed.quantize_per_tensor,
exir_ops.edge.cadence.quantize_per_tensor,
torch.ops.cadence.quantize_per_tensor,
):
continue

Expand Down Expand Up @@ -413,6 +417,7 @@ def postponing_feasible(self, dequant_node: torch.fx.Node):
in {
exir_ops.edge.quantized_decomposed.quantize_per_tensor,
exir_ops.edge.quantized_decomposed.quantize_per_channel,
exir_ops.edge.cadence.quantize_per_tensor,
}
for x in users
)
Expand All @@ -422,6 +427,7 @@ def postpone_dequantize_op(self, graph_module: torch.fx.GraphModule) -> bool:
packet_to_overload_map = {
exir_ops.edge.quantized_decomposed.dequantize_per_tensor: "default",
exir_ops.edge.quantized_decomposed.dequantize_per_channel: "default",
exir_ops.edge.cadence.dequantize_per_tensor: "default",
}
graph = graph_module.graph
modified = False
Expand Down Expand Up @@ -500,6 +506,7 @@ class SinkOpsCloserToUsePass(ExportPass):
exir_ops.edge.aten.dequantize,
exir_ops.edge.quantized_decomposed.dequantize_per_tensor,
exir_ops.edge.quantized_decomposed.dequantize_per_channel,
exir_ops.edge.cadence.dequantize_per_tensor,
}

def sink_ops_closer_to_use(self, graph_module: torch.fx.GraphModule):
Expand Down Expand Up @@ -558,6 +565,7 @@ class HoistOpsCloserToDefPass(ExportPass):

hoistable_ops: Set[EdgeOpOverload] = {
exir_ops.edge.quantized_decomposed.quantize_per_tensor,
exir_ops.edge.cadence.quantize_per_tensor,
exir_ops.edge.aten.slice_copy,
exir_ops.edge.aten.select_copy,
}
Expand Down
10 changes: 6 additions & 4 deletions backends/cadence/aot/replace_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,12 @@ def call_operator(
kwargs: Dict[str, Argument],
meta: NodeMetadata,
) -> ProxyValue:
if op not in {exir_ops.edge.quantized_decomposed.quantize_per_tensor.default}:
ns = exir_ops.edge if isinstance(op, EdgeOpOverload) else torch.ops
if op != ns.quantized_decomposed.quantize_per_tensor.default:
return super().call_operator(op, args, kwargs, meta)

return super().call_operator(
exir_ops.edge.cadence.quantize_per_tensor.default,
ns.cadence.quantize_per_tensor.default,
args,
kwargs,
meta,
Expand All @@ -188,11 +189,12 @@ def call_operator(
kwargs: Dict[str, Argument],
meta: NodeMetadata,
) -> ProxyValue:
if op not in {exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default}:
ns = exir_ops.edge if isinstance(op, EdgeOpOverload) else torch.ops
if op != ns.quantized_decomposed.dequantize_per_tensor.default:
return super().call_operator(op, args, kwargs, meta)

return super().call_operator(
exir_ops.edge.cadence.dequantize_per_tensor.default,
ns.cadence.dequantize_per_tensor.default,
args,
kwargs,
meta,
Expand Down
Loading