Open mfuntowicz opened 2 years ago
For the record, it seems manually "enforcing" the symmetry in the calibration ranges restore performances:
calibration_ranges = calibrator.compute_range()
# here v[0] == v[1], let's chnge it to -v[0]
calibration_ranges = {k: (-v[0], v[1]) for k, v in calibrations_ranges.items()}
Yes, TRT only supports symmetric quantization.
@yufenglee I'm not using TRT, I'm using ORT CPU EP
OK, I see. Then you are running on machine without VNNI.
I though about it too, but I'm running on a VNNI machine, Intel i9-10980XE π€
> lscpu ξ² β ξ² 10070 ξ² 00:13:26
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 46 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 36
On-line CPU(s) list: 0-35
Vendor ID: GenuineIntel
Model name: Intel(R) Core(TM) i9-10980XE CPU @ 3.00GHz
CPU family: 6
Model: 85
Thread(s) per core: 2
Core(s) per socket: 18
Socket(s): 1
Stepping: 7
CPU max MHz: 4800.0000
CPU min MHz: 1200.0000
BogoMIPS: 6000.00
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq
dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single ssbd mba ibrs ibpb stibp ibrs_en
hanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_ll
c cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512_vnni md_clear flush_l1d arch_capabilities
Virtualization features:
Virtualization: VT-x
Caches (sum of all):
L1d: 576 KiB (18 instances)
L1i: 576 KiB (18 instances)
L2: 18 MiB (18 instances)
L3: 24.8 MiB (1 instance)
NUMA:
NUMA node(s): 1
NUMA node0 CPU(s): 0-35
Vulnerabilities:
Itlb multihit: KVM: Mitigation: VMX disabled
L1tf: Not affected
Mds: Not affected
Meltdown: Not affected
Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling
Srbds: Not affected
Tsx async abort: Mitigation; TSX disabled
If on machine with VNNI, the perf is expected to be similar.
I thought the performance to be latency. @chilo-ms.
Also, I want to point out the calibration ranges generated by ORT seems wrong min = max for entropy/percentiles schema, see attached JSON file in first message.
Thanks @mfuntowicz! Yes, it is a bug for non-symmetric activation: https://github.com/microsoft/onnxruntime/blob/be9cc40aa51679daed51c88f9ce8ceecd5e6a800/onnxruntime/python/tools/quantization/calibrate.py#L557.
Thanks @mfuntowicz for bringing out this problem. The range of tensor in percentiles calibration method in ORT only considers symmetric and will fix the bug.
Hi ORT folks ππ».
I continue my walk over all the possible calibration techniques provided by ORT, especially target BERT-like models, and spot something strange w.r.t the calibration ranges generated by different
Calibrater
.I'm using the following schema:
uint8
, asymmetricint8
, symmetricfalse
"qdq"
Everything is highly inspired by the ORT example on BERT-SQuAD
Every attempt with a calibration method different than
minmax
leads to very poor exact match and F1 score (like EM < 0.01 and F1 < 0.1)The baseline I'm using is from HuggingFace's Hub: https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad
EM = 85.875, F1 = 92.080
u8/s8
, minmax, 256 samples:EM = 84.588, F1 = 91.519
u8/s8
, entropy, 256 samples, 128 bins:EM = 82.980, F1 = 90.468
u8/s8
, percentiles, 256 samples, 2048 bins, 99.999%:EM = 0.302 , F1 = 5.82
when looking at the calibration ranges for percentiles I'm confused by the results (see JSON below).
Am I missing something? I would have expected to have a negative side on each node (as I get with
entropy
).Also, histogram-based values are symmetric, the left-side values are always the negative of the right-side. Is it expected? Even in asymmetric mode?
Thanks a lot for your inputs on this ππ»