AI Grounds

Open AI Grounds on a desktop

These interactive lessons need a larger screen. Please continue on a desktop or laptop computer.

Guided discovery

Linear Quantization (INT4) Lab

Share a scale. Round a value. Inspect the cost.

Synthetic blocks, not trained-model measurements. This toy uses unsigned 4-bit codes 0–15 (uint4); signed int4 uses −8..7. Reconstructed real values can be negative through the zero-point offset.

Your quantizer

Auto is a fixed demonstration preset, not an automatic sample-min/max estimate. All presets round calibration endpoints to 0.001. Clamping limits a code to 0–15 by choosing the closest boundary.

Calibration min -0.16000

Calibration max +0.14000

Scale s 0.02000

Zero point z 8

16 codes = 15 gaps · s = (max − min) / 15 · z = clamp(round(−min/s), 0, 15)

Probe bounds -0.223 to +0.203 stay fixed across this block’s presets. The probe does not change the 102 fixed block samples. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

Real value to reconstructed level

Three rows share the same real-number scale, including sources beyond the levels. The top row has all 16 reconstructed levels; code 8 represents zero. The dot is x, the square is x̂. Exact positions have no minimum drawn error.

Levels
x +0.053
x̂ +0.06000

Reconstructed endpoints: code 0 = -0.16000 · code 15 = +0.14000

These can differ from calibration min/max after the zero point rounds to an integer. Each unclamped rounded code has an error bound s/2 = 0.01000. The bound does not apply to clamped values.

Arithmetic trace

q = clamp(round(x/s) + z, 0, 15) · x̂ = s(q − z) · error = x̂ − x

x / s
2.65000
Rounded offset
3
Raw code = offset + z
11
Clamped code q
11
Reconstructed x̂
+0.06000
Signed error
+0.00700

Raw code was not clamped. Round nearest, with half ties toward +∞ (for example −2.5 → −2). Authored decimal inputs are treated exactly for this tie decision; ONNX uses ties-to-even instead.

Input cell after clamping: +0.05000 ≤ x < +0.07000. Endpoint codes include arbitrarily far tails; not every input assigned an endpoint code was clamped. This describes the mathematical decimal rule, beyond the bounded inspector.

Mean absolute error

Average |x̂ − x| across the 102 fixed samples, including clamped samples.

0.00560

Σ absolute error / sample count

Changing only the separate probe leaves this unchanged.

Clamped samples

Samples whose rounded raw code falls below 0 or above 15.

3 / 102

2.94%

This is different from merely lying outside calibration endpoints, or being assigned code 0/15.

Pack two codes

A nibble is 4 bits; a byte is 8. The first code occupies the high nibble, the fixed second code 6 the low nibble. This pair is a packing demonstration, not two selected block samples.

11 = 1011 · fixed 6 = 0110 → 0xB6 (10110110, one byte)

Codes alone: 32-bit FP32 → 4-bit payload = 8× reduction. Illustrative block format: 51 payload bytes + 4-byte FP32 scale + 1-byte zero point = 56 bytes, versus 408 FP32 bytes (7.29×). An odd sample count pads the last half-byte; real formats can add alignment, containers or other metadata. This does not measure model accuracy or speed.

Code counts and reconstructed levels

Bars use a common 0–100% scale of all 102 samples. Zero-count codes have zero width. The final column counts genuinely clamped samples, not every boundary assignment.

CodeReconstructed levelCount / share of blockClamped count
0-0.160002 / 1.96%2
1-0.140000 / 0.00%0
2-0.120002 / 1.96%0
3-0.100004 / 3.92%0
4-0.080004 / 3.92%0
5-0.060005 / 4.90%0
6-0.040009 / 8.82%0
7-0.0200020 / 19.61%0
80.0000020 / 19.61%0
9+0.0200015 / 14.71%0
10+0.040009 / 8.82%0
11 · Probe code+0.060004 / 3.92%0
12+0.080002 / 1.96%0
13+0.100004 / 3.92%0
14+0.120000 / 0.00%0
15+0.140002 / 1.96%1
All original and quantized samples

Every original occurrence is retained, including repeated synthetic values. This is the fixed dataset used by the block error summaries.

SampleOriginal xRounded offsetRaw codeStored qReconstructedErrorClamped?
1-0.19000-9-10-0.16000+0.03000Yes
2-0.17480-9-10-0.16000+0.01480Yes
3-0.12040-622-0.12000+0.00040No
4-0.12040-622-0.12000+0.00040No
5-0.10530-533-0.10000+0.00530No
6-0.10530-533-0.10000+0.00530No
7-0.09030-533-0.10000-0.00970No
8-0.09030-533-0.10000-0.00970No
9-0.07950-444-0.08000-0.00050No
10-0.07950-444-0.08000-0.00050No
11-0.07090-444-0.08000-0.00910No
12-0.07090-444-0.08000-0.00910No
13-0.06230-355-0.06000+0.00230No
14-0.06230-355-0.06000+0.00230No
15-0.05370-355-0.06000-0.00630No
16-0.05370-355-0.06000-0.00630No
17-0.05370-355-0.06000-0.00630No
18-0.04510-266-0.04000+0.00510No
19-0.04510-266-0.04000+0.00510No
20-0.04510-266-0.04000+0.00510No
21-0.03870-266-0.04000-0.00130No
22-0.03870-266-0.04000-0.00130No
23-0.03870-266-0.04000-0.00130No
24-0.03350-266-0.04000-0.00650No
25-0.03350-266-0.04000-0.00650No
26-0.03350-266-0.04000-0.00650No
27-0.02840-177-0.02000+0.00840No
28-0.02840-177-0.02000+0.00840No
29-0.02840-177-0.02000+0.00840No
30-0.02840-177-0.02000+0.00840No
31-0.02370-177-0.02000+0.00370No
32-0.02370-177-0.02000+0.00370No
33-0.02370-177-0.02000+0.00370No
34-0.02370-177-0.02000+0.00370No
35-0.01890-177-0.02000-0.00110No
36-0.01890-177-0.02000-0.00110No
37-0.01890-177-0.02000-0.00110No
38-0.01890-177-0.02000-0.00110No
39-0.01460-177-0.02000-0.00540No
40-0.01460-177-0.02000-0.00540No
41-0.01460-177-0.02000-0.00540No
42-0.01460-177-0.02000-0.00540No
43-0.01030-177-0.02000-0.00970No
44-0.01030-177-0.02000-0.00970No
45-0.01030-177-0.02000-0.00970No
46-0.01030-177-0.02000-0.00970No
47-0.006400880.00000+0.00640No
48-0.006400880.00000+0.00640No
49-0.006400880.00000+0.00640No
50-0.006400880.00000+0.00640No
51-0.003400880.00000+0.00340No
52-0.003400880.00000+0.00340No
53-0.003400880.00000+0.00340No
54-0.003400880.00000+0.00340No
550.000000880.000000.00000No
560.000000880.000000.00000No
570.000000880.000000.00000No
580.000000880.000000.00000No
59+0.003400880.00000-0.00340No
60+0.003400880.00000-0.00340No
61+0.003400880.00000-0.00340No
62+0.003400880.00000-0.00340No
63+0.006900880.00000-0.00690No
64+0.006900880.00000-0.00690No
65+0.006900880.00000-0.00690No
66+0.006900880.00000-0.00690No
67+0.01070199+0.02000+0.00930No
68+0.01070199+0.02000+0.00930No
69+0.01070199+0.02000+0.00930No
70+0.01070199+0.02000+0.00930No
71+0.01500199+0.02000+0.00500No
72+0.01500199+0.02000+0.00500No
73+0.01500199+0.02000+0.00500No
74+0.01500199+0.02000+0.00500No
75+0.01980199+0.02000+0.00020No
76+0.01980199+0.02000+0.00020No
77+0.01980199+0.02000+0.00020No
78+0.01980199+0.02000+0.00020No
79+0.02490199+0.02000-0.00490No
80+0.02490199+0.02000-0.00490No
81+0.02490199+0.02000-0.00490No
82+0.0310021010+0.04000+0.00900No
83+0.0310021010+0.04000+0.00900No
84+0.0310021010+0.04000+0.00900No
85+0.0378021010+0.04000+0.00220No
86+0.0378021010+0.04000+0.00220No
87+0.0378021010+0.04000+0.00220No
88+0.0456021010+0.04000-0.00560No
89+0.0456021010+0.04000-0.00560No
90+0.0456021010+0.04000-0.00560No
91+0.0550031111+0.06000+0.00500No
92+0.0550031111+0.06000+0.00500No
93+0.0654031111+0.06000-0.00540No
94+0.0654031111+0.06000-0.00540No
95+0.0774041212+0.08000+0.00260No
96+0.0774041212+0.08000+0.00260No
97+0.0924051313+0.10000+0.00760No
98+0.0924051313+0.10000+0.00760No
99+0.1084051313+0.10000-0.00840No
100+0.1084051313+0.10000-0.00840No
101+0.1496071515+0.14000-0.00960No
102+0.1700091715+0.14000-0.03000Yes
Original distribution bins

Twenty-four calibration bins use [start, end), with the final right endpoint included. Explicit underflow/overflow counts retain out-of-range samples; these counts are not code-clamping counts.

Source intervalCountShare of block
Below -0.1600021.96%
[-0.16000, -0.14750)00.00%
[-0.14750, -0.13500)00.00%
[-0.13500, -0.12250)00.00%
[-0.12250, -0.11000)21.96%
[-0.11000, -0.09750)21.96%
[-0.09750, -0.08500)21.96%
[-0.08500, -0.07250)21.96%
[-0.07250, -0.06000)43.92%
[-0.06000, -0.04750)32.94%
[-0.04750, -0.03500)65.88%
[-0.03500, -0.02250)1110.78%
[-0.02250, -0.01000)1211.76%
[-0.01000, +0.00250)1211.76%
[+0.00250, +0.01500)1211.76%
[+0.01500, +0.02750)1110.78%
[+0.02750, +0.04000)65.88%
[+0.04000, +0.05250)32.94%
[+0.05250, +0.06500)21.96%
[+0.06500, +0.07750)43.92%
[+0.07750, +0.09000)00.00%
[+0.09000, +0.10250)21.96%
[+0.10250, +0.11500)21.96%
[+0.11500, +0.12750)00.00%
[+0.12750, +0.14000]00.00%
Above +0.1400021.96%

LLM weights, auto range. Probe +0.05300, rounded offset 3, raw code 11, stored code 11, reconstructed +0.06000, error +0.00700. Not clamped. Block mean absolute error 0.00560, 3 clamped samples of 102. Packed byte 0xB6.