Skip to content

Commit 5bea726

Browse files
authored
Arm backend: reducing qtol to 1 after adjusting eps for llama (#18116)
- Reducing qtol from 75 to 1 after adjusting eps from 2^^-16 to 2^^-12 cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell Signed-off-by: Xingguo Li <xingguo.li@arm.com>
1 parent 28783db commit 5bea726

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

backends/arm/quantizer/arm_quantizer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def get_symmetric_quantization_config(
7676
act_qmax: int = 127,
7777
weight_qmin: int = -127,
7878
weight_qmax: int = 127,
79+
eps: float = 2**-16,
7980
) -> QuantizationConfig:
8081
"""Create symmetric quantization config for activations and weights.
8182
@@ -95,7 +96,7 @@ def get_symmetric_quantization_config(
9596
bias.
9697
9798
"""
98-
extra_args: Dict[str, Any] = {"eps": 2**-16}
99+
extra_args: Dict[str, Any] = {"eps": eps}
99100
if is_qat:
100101
if is_dynamic:
101102
act_observer_or_fake_quant_ctr = FakeQuantize

backends/arm/test/models/test_llama.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ def prepare_model(self):
102102
return llama_model, llama_inputs, llama_meta
103103

104104

105-
def _use_partial_quantizer(pipeline):
105+
def _use_partial_quantizer(pipeline, eps=2**-16):
106106
"""Set the pipeline's quantizer to only include Linear layers."""
107107
pipeline.quantizer.set_global(None)
108108
pipeline.quantizer.set_module_type(
109-
torch.nn.Linear, get_symmetric_quantization_config()
109+
torch.nn.Linear, get_symmetric_quantization_config(eps=eps)
110110
)
111111

112112

@@ -209,12 +209,11 @@ def test_llama_tosa_INT_FP_partial_quant():
209209
tosa_extensions=["FP"],
210210
# Due to a few outliers, atol must be set high
211211
atol=1.1,
212-
# TODO(MLETORCH-1875): reduce tolerance
213-
qtol=75,
212+
qtol=1,
214213
frobenius_threshold=None,
215214
cosine_threshold=None,
216215
)
217-
_use_partial_quantizer(pipeline)
216+
_use_partial_quantizer(pipeline, eps=2**-12)
218217
pipeline.run()
219218

220219

@@ -234,8 +233,7 @@ def test_llama_vgf_quant_partial_quant():
234233
quantize=True,
235234
# Due to a few outliers, atol must be set high
236235
atol=1.1,
237-
# TODO(MLETORCH-1875): reduce tolerance
238-
qtol=75,
236+
qtol=1,
239237
)
240-
_use_partial_quantizer(pipeline)
238+
_use_partial_quantizer(pipeline, eps=2**-12)
241239
pipeline.run()

0 commit comments

Comments
 (0)