Skip to content

Commit 79dff9a

Browse files
dulinrileyfacebook-github-bot
authored andcommitted
Add small repro test for unsigned -> signed et loss error
Summary: There was a difference in behavior from `quantized_decomposed.quantize_per_tensor` and `cadence.quantize_per_tensor`, specifically how rounding half values worked. The former rounds towards even (based on `torch.round` which does that). The latter rounds away from zero. Make sure the python implementation matches the Executorch implementation in this regard. Meta: We found the cause of the et_loss issue in Eye Tracking Regressor which was caused when switching the observer types: it led to off-by-one errors in between the "quantized_decomposed" and "cadence" variants of the dq/q functions. This small test repros the issue. To fix this, we change to use cadence quant functions earlier in the pipeline (before turing ref-forward), and we change their python implementation to more closely match the Executorch implementation with some rounding tricks. Differential Revision: D69668881
1 parent 8148603 commit 79dff9a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

backends/cadence/aot/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ python_library(
180180
typing = True,
181181
deps = [
182182
"//caffe2:torch",
183+
":ops_registrations",
183184
":compiler_utils",
184185
"//executorch/backends/cadence/aot:pass_utils",
185186
"//executorch/backends/cadence/aot:utils",

backends/cadence/aot/fuse_ops.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import torch
2020
import torch.fx
21+
# Import these for the cadence function signatures.
22+
import executorch.backends.cadence.aot.ops_registrations # noqa: F401
2123
from executorch.backends.cadence.aot.compiler_utils import (
2224
broadcastable,
2325
get_cascaded_ops,

backends/cadence/aot/replace_ops.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,12 @@ def call_operator(
158158
kwargs: Dict[str, Argument],
159159
meta: NodeMetadata,
160160
) -> ProxyValue:
161-
if op not in {exir_ops.edge.quantized_decomposed.quantize_per_tensor.default}:
161+
ns = exir_ops.edge if isinstance(op, EdgeOpOverload) else torch.ops
162+
if op != ns.quantized_decomposed.quantize_per_tensor.default:
162163
return super().call_operator(op, args, kwargs, meta)
163164

164165
return super().call_operator(
165-
exir_ops.edge.cadence.quantize_per_tensor.default,
166+
ns.cadence.quantize_per_tensor.default,
166167
args,
167168
kwargs,
168169
meta,
@@ -184,11 +185,12 @@ def call_operator(
184185
kwargs: Dict[str, Argument],
185186
meta: NodeMetadata,
186187
) -> ProxyValue:
187-
if op not in {exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default}:
188+
ns = exir_ops.edge if isinstance(op, EdgeOpOverload) else torch.ops
189+
if op != ns.quantized_decomposed.dequantize_per_tensor.default:
188190
return super().call_operator(op, args, kwargs, meta)
189191

190192
return super().call_operator(
191-
exir_ops.edge.cadence.dequantize_per_tensor.default,
193+
ns.cadence.dequantize_per_tensor.default,
192194
args,
193195
kwargs,
194196
meta,

0 commit comments

Comments
 (0)