-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cadence - refactor quantizer and passes (#3539)
Summary: Pull Request resolved: #3539 Update the quantizer to the latest internal version, and heavily refactor it for readability and maintenance. Reviewed By: cccclai Differential Revision: D57082021 fbshipit-source-id: 947753859f6ffc5ea9ea0e803d2c4a0fd30bf608
- Loading branch information
1 parent
60c94e8
commit 629b112
Showing
8 changed files
with
1,106 additions
and
859 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from executorch.exir.dialects._ops import ops as exir_ops | ||
from executorch.exir.pass_base import ExportPass | ||
|
||
|
||
class ReplacePT2QuantWithCadenceQuant(ExportPass): | ||
""" | ||
Replace the pt2 quantization ops with custom cadence quantization ops. | ||
""" | ||
|
||
def call_operator(self, op, args, kwargs, meta): | ||
if op not in {exir_ops.edge.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, | ||
args, | ||
kwargs, | ||
meta, | ||
) | ||
|
||
|
||
class ReplacePT2DequantWithCadenceDequant(ExportPass): | ||
""" | ||
Replace the pt2 dequantization ops with custom cadence dequantization ops. | ||
""" | ||
|
||
def call_operator(self, op, args, kwargs, meta): | ||
if op not in {exir_ops.edge.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, | ||
args, | ||
kwargs, | ||
meta, | ||
) |
Oops, something went wrong.