Skip to content

[quantization] Introduce example script for torch.nn.LayerNorm quantization#633

Open
dvsav wants to merge 1 commit intoSamsung:mainfrom
dvsav:quantize_layernorm
Open

[quantization] Introduce example script for torch.nn.LayerNorm quantization#633
dvsav wants to merge 1 commit intoSamsung:mainfrom
dvsav:quantize_layernorm

Conversation

@dvsav
Copy link
Copy Markdown
Contributor

@dvsav dvsav commented Apr 15, 2026

What

This PR introduces an example script quantize_layernorm.py that tests QuantLayerNorm wrapper for torch.nn.LayerNorm module.

Why

Traditinally, every QuantXXX wrapper in tico/quantization/wrapq/wrappers has a respective example script in tico/quantization/wrapq/examples that demostrates quantization of a respective module, estimation of quantization error and conversion to Circle. For some reason torch.nn.LayerNorm doesn't have such a script, and this PR is intended to fill this gap.

Script Output

$ python tico/quantization/wrapq/examples/nn/quantize_layernorm.py
Input shape:              torch.Size([10, 768])
Output shape (FP32):      torch.Size([10, 768])
Output shape (Quantized): torch.Size([10, 768])
┌───────────── Quantization Error Summary ─────────────
│ Mean |diff|: 0.012465
│ PEIR       : 0.598103 %
└──────────────────────────────────────────────────────
    ┌────────────────────────────────────────────┐
 4.1┤                                            │
    │                                         •  │
    │                                     •••    │
 2.7┤                                   •••      │
    │                                ••••        │
    │                              •••           │
 1.3┤                           ••••             │
    │                         ••••               │
    │                       •••                  │
-0.1┤                    ••••                    │
    │                  •••                       │
    │               ••••                         │
-1.5┤             ••••                           │
    │           •••                              │
    │         •••                                │
-2.9┤      •••                                   │
    │    •••                                     │
    │  •                                         │
-4.3┤                                            │
    └┬──────────┬──────────┬─────────┬──────────┬┘
   -4.3       -2.2       -0.1       2.0       4.1 

Circle model saved as 'quantized_layernorm.circle'

Note: the above output depens on PR [quantization] Fix a bug in AffineObserverBase.compute_qparams.

…zation

This change introduces an example script quantize_layernorm.py that tests QuantLayerNorm wrapper for torch.nn.LayerNorm module.

TICO-DCO-1.0-Signed-off-by: d.savchenkov <d.savchenkov@partner.samsung.com>
@dvsav dvsav marked this pull request as ready for review April 16, 2026 08:21
@dvsav dvsav force-pushed the quantize_layernorm branch from d298b5b to b78060d Compare April 16, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant