Skip to content

Commit febc06e

Browse files
digantdesaifacebook-github-bot
authored andcommitted
Move XNNPACKQuantizer from PyTorch to ExecuTorch
Summary: X-link: pytorch/pytorch#144940 This migrates XNNPACKQuantizer from PyTorch to ExecuTorch. Rationale: Main motivation is to avoid pytorch pin update in OSS after updating XNNPACKQuantizer, which can be rather frequent. Other impact and considerations: - PT2e flow (which lives in PyTorch) relies havily on XNNPACKQuantizer for a "example" implementation for quantizer and more importantly tests. Fow now, we will keep the torch.ao.quantization.xnnpack_quantizer as is but mark is as not BC, and deprecated to discourace future new dependencies on it. - Other OSS repository using XNNPACKQuantizer from PyTorch now have to take an additional dependency on ExecuTorch. Differential Revision: D68191752
1 parent f58c8ec commit febc06e

36 files changed

+3854
-42
lines changed

backends/cadence/aot/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ python_library(
6565
"//executorch/backends/cadence/aot/quantizer:fusion_pass",
6666
"//executorch/backends/cadence/runtime:runtime",
6767
"//executorch/backends/cadence/aot/quantizer:quantizer",
68+
"//executorch/backends/xnnpack/quantizer:xnnpack_quantizer",
6869
"//executorch/backends/transforms:decompose_sdpa",
6970
"//executorch/backends/transforms:remove_clone_ops",
7071
"//executorch/exir:lib",

backends/cadence/aot/export_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from executorch.exir import ExecutorchProgramManager
2727
from torch import nn
2828
from torch.ao.quantization.observer import HistogramObserver, MinMaxObserver
29-
from torch.ao.quantization.quantizer.xnnpack_quantizer_utils import (
29+
from executorch.backends.xnnpack.quantizer.xnnpack_quantizer_utils import (
3030
QuantizationConfig,
3131
QuantizationSpec,
3232
)

backends/cadence/aot/quantizer/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ python_library(
3434
":patterns",
3535
":utils",
3636
"//caffe2:torch",
37+
"//executorch/backends/xnnpack/quantizer:xnnpack_quantizer_utils",
3738
],
3839
)
3940

backends/cadence/aot/quantizer/quantizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from torch.ao.quantization.observer import HistogramObserver, MinMaxObserver
3333
from torch.ao.quantization.quantizer import DerivedQuantizationSpec, Quantizer
3434
from torch.ao.quantization.quantizer.composable_quantizer import ComposableQuantizer
35-
from torch.ao.quantization.quantizer.xnnpack_quantizer_utils import (
35+
from executorch.backends.xnnpack.quantizer.xnnpack_quantizer_utils import (
3636
OperatorConfig,
3737
QuantizationAnnotation,
3838
QuantizationConfig,

backends/example/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ python_library(
1111
deps = [
1212
"//caffe2:torch",
1313
"//executorch/backends/example/example_operators:example_operators_lib",
14+
"//executorch/backends/xnnpack/quantizer:xnnpack_quantizer",
1415
],
1516
)
1617

backends/example/example_quantizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from torch.ao.quantization.observer import HistogramObserver, MinMaxObserver
1414
from torch.ao.quantization.pt2e.graph_utils import find_sequential_partitions
1515
from torch.ao.quantization.quantizer import QuantizationSpec, Quantizer
16-
from torch.ao.quantization.quantizer.xnnpack_quantizer_utils import OperatorConfig
16+
from executorch.backends.xnnpack.quantizer.xnnpack_quantizer_utils import OperatorConfig
1717

1818

1919
def get_uint8_tensor_spec(observer_or_fake_quant_ctr):

backends/transforms/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def define_common_targets():
195195
deps = [
196196
"fbsource//third-party/pypi/expecttest:expecttest", # @manual
197197
":duplicate_dynamic_quant_chain",
198+
"//executorch/backends/xnnpack/quantizer:xnnpack_quantizer",
198199
"//caffe2:torch",
199200
"//executorch/exir:lib",
200201
],

backends/transforms/test/test_duplicate_dynamic_quant_chain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
from executorch.backends.transforms.duplicate_dynamic_quant_chain import (
1212
DuplicateDynamicQuantChainPass,
1313
)
14-
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e
15-
from torch.ao.quantization.quantizer.xnnpack_quantizer import (
14+
from executorch.backends.xnnpack.quantizer.xnnpack_quantizer import (
1615
get_symmetric_quantization_config,
1716
XNNPACKQuantizer,
1817
)
18+
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e
1919

2020
# TODO: Move away from using torch's internal testing utils
2121
from torch.testing._internal.common_quantization import (

backends/vulkan/quantizer/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ python_library(
99
],
1010
deps = [
1111
"//caffe2:torch",
12+
"//executorch/backends/xnnpack/quantizer:xnnpack_quantizer_utils",
1213
],
1314
)

backends/vulkan/quantizer/vulkan_quantizer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
from typing import Any, Callable, Dict, Optional
1313

1414
import torch
15-
from torch.ao.quantization.observer import MinMaxObserver, PerChannelMinMaxObserver
16-
from torch.ao.quantization.qconfig import _ObserverOrFakeQuantizeConstructor
17-
from torch.ao.quantization.quantizer import QuantizationSpec, Quantizer
18-
from torch.ao.quantization.quantizer.xnnpack_quantizer_utils import (
15+
from executorch.backends.xnnpack.quantizer.xnnpack_quantizer_utils import (
1916
_convert_scalars_to_attrs,
2017
OP_TO_ANNOTATOR,
2118
propagate_annotation,
2219
QuantizationConfig,
2320
)
21+
from torch.ao.quantization.observer import MinMaxObserver, PerChannelMinMaxObserver
22+
from torch.ao.quantization.qconfig import _ObserverOrFakeQuantizeConstructor
23+
from torch.ao.quantization.quantizer import QuantizationSpec, Quantizer
2424
from torch.fx import Node
2525

2626

0 commit comments

Comments
 (0)