Skip to content

Commit 2165b5a

Browse files
Arm backend: Mark composable quantizer APIs experimental (#18318)
Signed-off-by: Sebastian Larsson <sebastian.larsson@arm.com>
1 parent 38b40bc commit 2165b5a

3 files changed

Lines changed: 135 additions & 30 deletions

File tree

backends/arm/quantizer/arm_quantizer.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
SharedQspecQuantizer,
7272
)
7373
from executorch.backends.arm.vgf import VgfCompileSpec
74+
from executorch.exir._warnings import experimental
7475
from torch.fx import GraphModule, Node
7576
from torchao.quantization.pt2e import (
7677
FakeQuantize,
@@ -441,14 +442,26 @@ def _for_each_filtered_node(
441442

442443

443444
class TOSAQuantizer(Quantizer):
444-
"""Manage quantization annotations for TOSA-compatible backends."""
445+
"""Manage quantization annotations for TOSA-compatible backends.
446+
447+
.. warning::
448+
Setting ``use_composable_quantizer=True`` enables an experimental API
449+
surface that may change without notice.
450+
451+
"""
445452

446453
def __init__(
447454
self,
448455
compile_spec_or_tosa_spec,
449456
use_composable_quantizer: bool = False,
450457
) -> None:
451-
"""Create a TOSA quantizer from a TOSA spec or Arm compile spec."""
458+
"""Create a TOSA quantizer from a TOSA spec or Arm compile spec.
459+
460+
.. warning::
461+
Setting ``use_composable_quantizer=True`` enables an experimental
462+
API surface that may change without notice.
463+
464+
"""
452465
self.use_composable_quantizer = use_composable_quantizer
453466
self.quantizer: _TOSAQuantizerV1 | _TOSAQuantizerV2
454467
if use_composable_quantizer:
@@ -606,6 +619,10 @@ def set_io(
606619
self.quantizer.set_io(quantization_config)
607620
return self
608621

622+
@experimental(
623+
"This API is experimental and may change without notice. "
624+
"It is only available when use_composable_quantizer=True."
625+
)
609626
def add_quantizer(self, quantizer: Quantizer) -> TOSAQuantizer:
610627
"""Insert a quantizer with highest precedence."""
611628
if self.use_composable_quantizer:
@@ -614,6 +631,10 @@ def add_quantizer(self, quantizer: Quantizer) -> TOSAQuantizer:
614631
"add_quantizer is only supported in the composable quantizer implementation."
615632
)
616633

634+
@experimental(
635+
"This API is experimental and may change without notice. "
636+
"It is only available when use_composable_quantizer=True."
637+
)
617638
def set_node_finder(
618639
self, quantization_config: Optional[QuantizationConfig], node_finder: NodeFinder
619640
) -> TOSAQuantizer:
@@ -631,6 +652,10 @@ def set_node_finder(
631652
"set_node_finder is only supported in the composable quantizer implementation."
632653
)
633654

655+
@experimental(
656+
"This API is experimental and may change without notice. "
657+
"It is only available when use_composable_quantizer=True."
658+
)
634659
def set_node_target(
635660
self, node_target: OpOverload, quantization_config: Optional[QuantizationConfig]
636661
) -> TOSAQuantizer:
@@ -641,6 +666,10 @@ def set_node_target(
641666
"set_node_target is only supported in the composable quantizer implementation."
642667
)
643668

669+
@experimental(
670+
"This API is experimental and may change without notice. "
671+
"It is only available when use_composable_quantizer=True."
672+
)
644673
def set_node_name(
645674
self, node_name: str, quantization_config: Optional[QuantizationConfig]
646675
) -> TOSAQuantizer:
@@ -1167,6 +1196,10 @@ def set_io(
11671196
class EthosUQuantizer(TOSAQuantizer):
11681197
"""Quantizer supported by the Arm Ethos-U backend.
11691198
1199+
.. warning::
1200+
Setting ``use_composable_quantizer=True`` enables an experimental API
1201+
surface that may change without notice.
1202+
11701203
Args:
11711204
compile_spec (EthosUCompileSpec): Backend compile specification for
11721205
Ethos-U targets.
@@ -1185,6 +1218,10 @@ def __init__(
11851218
class VgfQuantizer(TOSAQuantizer):
11861219
"""Quantizer supported by the Arm Vgf backend.
11871220
1221+
.. warning::
1222+
Setting ``use_composable_quantizer=True`` enables an experimental API
1223+
surface that may change without notice.
1224+
11881225
Args:
11891226
compile_spec (VgfCompileSpec): Backend compile specification for Vgf
11901227
targets.

docs/source/backends/arm-ethos-u/arm-ethos-u-quantization.md

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,23 @@ The Arm Ethos-U delegate supports the following quantization schemes:
1616
### Quantization API
1717

1818
```python
19-
class EthosUQuantizer(compile_spec: 'EthosUCompileSpec') -> 'None'
19+
class EthosUQuantizer(compile_spec: 'EthosUCompileSpec', use_composable_quantizer: 'bool' = False) -> 'None'
2020
```
2121
Quantizer supported by the Arm Ethos-U backend.
2222

23+
.. warning::
24+
Setting ``use_composable_quantizer=True`` enables an experimental API
25+
surface that may change without notice.
26+
2327
Args:
2428
- **compile_spec (EthosUCompileSpec)**: Backend compile specification for
2529
Ethos-U targets.
30+
- **use_composable_quantizer (bool)**: Whether to use the composable quantizer implementation. See https://github.com/pytorch/executorch/issues/17701" for details.
31+
32+
```python
33+
def EthosUQuantizer.add_quantizer(self, quantizer: 'Quantizer') -> 'TOSAQuantizer':
34+
```
35+
Insert a quantizer with highest precedence.
2636

2737
```python
2838
def EthosUQuantizer.quantize_with_submodules(self, model: 'GraphModule', calibration_samples: 'list[tuple]', is_qat: 'bool' = False, fold_quantize: 'bool' = True):
@@ -48,22 +58,24 @@ Returns:
4858
- **GraphModule**: The quantized model.
4959

5060
```python
51-
def EthosUQuantizer.set_global(self, quantization_config: 'QuantizationConfig | None') -> 'TOSAQuantizer':
61+
def EthosUQuantizer.set_global(self, quantization_config: 'Optional[QuantizationConfig]') -> 'TOSAQuantizer':
5262
```
5363
Set quantization_config for submodules not matched by other filters.
5464

5565
Args:
56-
- **quantization_config (QuantizationConfig)**: Configuration to apply to
57-
modules that are not captured by name or type filters.
66+
- **quantization_config (Optional[QuantizationConfig])**: Configuration to
67+
apply to modules that are not captured by name or type filters.
68+
``None`` indicates no quantization.
5869

5970
```python
60-
def EthosUQuantizer.set_io(self, quantization_config: 'QuantizationConfig') -> 'TOSAQuantizer':
71+
def EthosUQuantizer.set_io(self, quantization_config: 'Optional[QuantizationConfig]') -> 'TOSAQuantizer':
6172
```
6273
Set quantization_config for input and output nodes.
6374

6475
Args:
65-
- **quantization_config (QuantizationConfig)**: Configuration describing
66-
activation quantization for model inputs and outputs.
76+
- **quantization_config (Optional[QuantizationConfig])**: Configuration
77+
describing activation quantization for model inputs and outputs.
78+
``None`` indicates no quantization.
6779

6880
```python
6981
def EthosUQuantizer.set_module_name(self, module_name: 'str', quantization_config: 'Optional[QuantizationConfig]') -> 'TOSAQuantizer':
@@ -75,29 +87,51 @@ patterns for that submodule with the provided quantization_config.
7587

7688
Args:
7789
- **module_name (str)**: Fully qualified module name to configure.
78-
- **quantization_config (QuantizationConfig)**: Configuration applied to
79-
the named submodule.
90+
- **quantization_config (Optional[QuantizationConfig])**: Configuration
91+
applied to the named submodule. ``None`` indicates no
92+
quantization.
8093

8194
```python
8295
def EthosUQuantizer.set_module_type(self, module_type: 'Callable', quantization_config: 'Optional[QuantizationConfig]') -> 'TOSAQuantizer':
8396
```
8497
Set quantization_config for submodules with a given module type.
8598

86-
For example, calling set_module_type(Sub) quantizes supported patterns
87-
in each Sub instance with the provided quantization_config.
99+
For example, calling set_module_type(Softmax) quantizes supported
100+
patterns in each Softmax instance with the provided quantization_config.
88101

89102
Args:
90103
- **module_type (Callable)**: Type whose submodules should use the
91104
provided quantization configuration.
92-
- **quantization_config (QuantizationConfig)**: Configuration to apply to
93-
submodules of the given type.
105+
- **quantization_config (Optional[QuantizationConfig])**: Configuration to
106+
apply to submodules of the given type. ``None`` indicates no
107+
quantization.
108+
109+
```python
110+
def EthosUQuantizer.set_node_finder(self, quantization_config: 'Optional[QuantizationConfig]', node_finder: 'NodeFinder') -> 'TOSAQuantizer':
111+
```
112+
Set quantization_config for nodes matched by a custom NodeFinder.
113+
114+
Args:
115+
- **quantization_config (Optional[QuantizationConfig])**: Configuration
116+
describing quantization settings for nodes matched by the provided
117+
NodeFinder. ``None`` indicates no quantization.
118+
119+
```python
120+
def EthosUQuantizer.set_node_name(self, node_name: 'str', quantization_config: 'Optional[QuantizationConfig]') -> 'TOSAQuantizer':
121+
```
122+
Set quantization config for a specific node name.
123+
124+
```python
125+
def EthosUQuantizer.set_node_target(self, node_target: 'OpOverload', quantization_config: 'Optional[QuantizationConfig]') -> 'TOSAQuantizer':
126+
```
127+
Set quantization config for a specific operator target.
94128

95129
```python
96130
def EthosUQuantizer.transform_for_annotation(self, model: 'GraphModule') -> 'GraphModule':
97131
```
98132
Transform the graph to prepare it for quantization annotation.
99133

100-
Currently transforms scalar values to tensor attributes.
134+
Decomposes all operators where required to get correct quantization parameters.
101135

102136
Args:
103137
- **model (GraphModule)**: Model whose graph will be transformed.

docs/source/backends/arm-vgf/arm-vgf-quantization.md

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,23 @@ setting using the `set_module_name` or `set_module_type` methods.
3535
### Quantization API
3636

3737
```python
38-
class VgfQuantizer(compile_spec: 'VgfCompileSpec') -> 'None'
38+
class VgfQuantizer(compile_spec: 'VgfCompileSpec', use_composable_quantizer: 'bool' = False) -> 'None'
3939
```
4040
Quantizer supported by the Arm Vgf backend.
4141

42+
.. warning::
43+
Setting ``use_composable_quantizer=True`` enables an experimental API
44+
surface that may change without notice.
45+
4246
Args:
4347
- **compile_spec (VgfCompileSpec)**: Backend compile specification for Vgf
4448
targets.
49+
- **use_composable_quantizer (bool)**: Whether to use the composable quantizer implementation. See https://github.com/pytorch/executorch/issues/17701" for details.
50+
51+
```python
52+
def VgfQuantizer.add_quantizer(self, quantizer: 'Quantizer') -> 'TOSAQuantizer':
53+
```
54+
Insert a quantizer with highest precedence.
4555

4656
```python
4757
def VgfQuantizer.quantize_with_submodules(self, model: 'GraphModule', calibration_samples: 'list[tuple]', is_qat: 'bool' = False, fold_quantize: 'bool' = True):
@@ -67,22 +77,24 @@ Returns:
6777
- **GraphModule**: The quantized model.
6878

6979
```python
70-
def VgfQuantizer.set_global(self, quantization_config: 'QuantizationConfig | None') -> 'TOSAQuantizer':
80+
def VgfQuantizer.set_global(self, quantization_config: 'Optional[QuantizationConfig]') -> 'TOSAQuantizer':
7181
```
7282
Set quantization_config for submodules not matched by other filters.
7383

7484
Args:
75-
- **quantization_config (QuantizationConfig)**: Configuration to apply to
76-
modules that are not captured by name or type filters.
85+
- **quantization_config (Optional[QuantizationConfig])**: Configuration to
86+
apply to modules that are not captured by name or type filters.
87+
``None`` indicates no quantization.
7788

7889
```python
79-
def VgfQuantizer.set_io(self, quantization_config: 'QuantizationConfig') -> 'TOSAQuantizer':
90+
def VgfQuantizer.set_io(self, quantization_config: 'Optional[QuantizationConfig]') -> 'TOSAQuantizer':
8091
```
8192
Set quantization_config for input and output nodes.
8293

8394
Args:
84-
- **quantization_config (QuantizationConfig)**: Configuration describing
85-
activation quantization for model inputs and outputs.
95+
- **quantization_config (Optional[QuantizationConfig])**: Configuration
96+
describing activation quantization for model inputs and outputs.
97+
``None`` indicates no quantization.
8698

8799
```python
88100
def VgfQuantizer.set_module_name(self, module_name: 'str', quantization_config: 'Optional[QuantizationConfig]') -> 'TOSAQuantizer':
@@ -94,29 +106,51 @@ patterns for that submodule with the provided quantization_config.
94106

95107
Args:
96108
- **module_name (str)**: Fully qualified module name to configure.
97-
- **quantization_config (QuantizationConfig)**: Configuration applied to
98-
the named submodule.
109+
- **quantization_config (Optional[QuantizationConfig])**: Configuration
110+
applied to the named submodule. ``None`` indicates no
111+
quantization.
99112

100113
```python
101114
def VgfQuantizer.set_module_type(self, module_type: 'Callable', quantization_config: 'Optional[QuantizationConfig]') -> 'TOSAQuantizer':
102115
```
103116
Set quantization_config for submodules with a given module type.
104117

105-
For example, calling set_module_type(Sub) quantizes supported patterns
106-
in each Sub instance with the provided quantization_config.
118+
For example, calling set_module_type(Softmax) quantizes supported
119+
patterns in each Softmax instance with the provided quantization_config.
107120

108121
Args:
109122
- **module_type (Callable)**: Type whose submodules should use the
110123
provided quantization configuration.
111-
- **quantization_config (QuantizationConfig)**: Configuration to apply to
112-
submodules of the given type.
124+
- **quantization_config (Optional[QuantizationConfig])**: Configuration to
125+
apply to submodules of the given type. ``None`` indicates no
126+
quantization.
127+
128+
```python
129+
def VgfQuantizer.set_node_finder(self, quantization_config: 'Optional[QuantizationConfig]', node_finder: 'NodeFinder') -> 'TOSAQuantizer':
130+
```
131+
Set quantization_config for nodes matched by a custom NodeFinder.
132+
133+
Args:
134+
- **quantization_config (Optional[QuantizationConfig])**: Configuration
135+
describing quantization settings for nodes matched by the provided
136+
NodeFinder. ``None`` indicates no quantization.
137+
138+
```python
139+
def VgfQuantizer.set_node_name(self, node_name: 'str', quantization_config: 'Optional[QuantizationConfig]') -> 'TOSAQuantizer':
140+
```
141+
Set quantization config for a specific node name.
142+
143+
```python
144+
def VgfQuantizer.set_node_target(self, node_target: 'OpOverload', quantization_config: 'Optional[QuantizationConfig]') -> 'TOSAQuantizer':
145+
```
146+
Set quantization config for a specific operator target.
113147

114148
```python
115149
def VgfQuantizer.transform_for_annotation(self, model: 'GraphModule') -> 'GraphModule':
116150
```
117151
Transform the graph to prepare it for quantization annotation.
118152

119-
Currently transforms scalar values to tensor attributes.
153+
Decomposes all operators where required to get correct quantization parameters.
120154

121155
Args:
122156
- **model (GraphModule)**: Model whose graph will be transformed.

0 commit comments

Comments
 (0)