ANTSHIV ROBOTICS C-KERNEL-ENGINE · SHIVASNOTES
MXFP4NVFP4Q4_K
ANTSHIV ROBOTICS / BUILDING REAL RUNTIMES

Four bits.
Three different contracts.

MXFP4

E8M0 / 32
One ruler / 32 values

NVFP4

E4M3 / 16 + FP32 global
Local + tensor scales

Q4_K

factors + scale/min pairs
Integer codes + offsets

From packed weights to onboard inference — with C-Kernel-Engine.
Q4_K_M is a model recipe built from a mixture of tensor types.

02 / THE THREE CONTRACTS

Same values. Different rulers.

1 × E8M0E4M3 / 16E4M3 / 16FP32 global

32 four-bit values · Next transforms the diagram.

MXFP4

One E8M0 scale
for all 32 values.

NVFP4

Two groups of 16.
Each gets an E4M3 scale.

Tensor scale

An FP32 global scale
completes this NVFP4 view.

Conceptual grouping, not physical byte layout. Metadata objects are enlarged for visibility.

03 / THE THREE CONTRACTS

On a robot, memory is shared.

BF16

16bits / weight

Four-bit payload

4bits / weight
7 billion × 2 bytes = 14 GB
7 billion × ½ byte = 3.5 GB

Onboard memory also serves sensor buffers, KV cache and runtime workspace.
Decimal GB; ideal weight payload only. Scales and mixed tensors add overhead.

04 / THE THREE CONTRACTS

One row. One output.

A tiny row of W multiplied by x; bias is zero here.

Weights w

−1.30.901.70

Input x

21−1.50
w · x = −2 + .30 − .90 + .85
y = −1.75
05 / READ THE FORMAT NAME

E2M1: four bits, three jobs.

E = exponent bits · M = stored fraction bits · sign is additional.

0

1 sign bit

10

2 exponent bits

1

1 fraction bit

Sign: 0 means positive. Exponent: binary 10 = 2; subtract bias 1.

Fraction: binary .1 = ½. A normal value has an implicit leading 1.

(+1) × 22−1 × (1 + ½) = 3

A normal E2M1 example used by MXFP4 and NVFP4. Zero and subnormal encodings use a different rule.

06 / THE THREE CONTRACTS

Does 0101 mean five?

E2M1: one sign bit, two exponent bits, one fraction bit.

E2M1: 0101 means 3. Q4_K: 0101 means integer 5.

E2M1 magnitudes: 0, ½, 1, 1½, 2, 3, 4, 6.
Both signs are encoded; larger magnitudes have wider gaps.

This codebook is shared by the MXFP4 and NVFP4 examples. It is not signed INT4.

07 / PREDICT / THEN MOVE THE RULER

Does a smaller scale always help?

OriginalRebuilt
① Snap at scale 0.5
② Shrink to 0.125
③ Inspect the errors

Positive half of E2M1; nearest value, midpoint ties toward smaller magnitude. Original values: 0.35 and 1.7.

08 / THE THREE CONTRACTS

Move the ruler. Watch the error.

Scales: ⅛, ¼, ½, 1, 2 · deterministic nearest value; midpoint ties use smaller magnitude.
Original w
FP4 values
Reconstructed ŵ
Dot product
Signed output error

Teaching quantizer with selectable scales, not a production scale-selection algorithm or a format-quality benchmark.

09 / MXFP4 / THE SHARED SCALE

E8M0: just a power of two.

8 exponent bits · 0 fraction bits · no sign bit.

01111110

Stored exponent byte: 0x7E = 126

decoded exponent = 126 − 127 = −1
shared scale = 2−1 = 0.5

One byte stretches the ruler for all 32 FP4 values.
Example: code value 3 × scale 0.5 = 1.5.

Finite E8M0 scales are positive powers of two. 0xFF denotes NaN; zero is not representable. Bias:127.

10 / THE THREE CONTRACTS

One ruler for all 32 codes.

Drag to orbit · scroll to zoom

32 FP4 codes

Mint cubes: E2M1 codes.
16 payload bytes in total.

One E8M0 scale

Gold: one byte for all 32 codes.
Example: exponent −1 → 0.5.

Decode the values

Read the signed E2M1 codebook. Height shows each value.

Apply the shared scale

ŵ = FP4(code) × 2ᵉ
3 × 0.5 = 1.5

17 bytes / 32 weights = 4.25 bits per weight. Schematic geometry. Blender source · GLB model

11 / NVFP4 / THE LOCAL SCALE

E4M3: a finer scale in one byte.

1 sign + 4 exponent + 3 fraction bits = 8 bits.

0

Positive

0101

Exponent: 5

010

Fraction: 2/8

Subtract exponent bias 7. The stored fraction adds to an implicit 1.

(+1) × 25−7 × (1 + 2/8) = 0.3125

NVFP4 uses this FP8 scale for 16 E2M1 codes.
With global scale 1: 3 × 0.3125 × 1 = 0.9375.

E4M3 normal example: byte 0x2A. The weights remain four-bit codes; their shared scale uses eight bits. Special encodings have separate rules.

12 / THE THREE CONTRACTS

NVFP4: two levels of scale.

Drag to orbit · scroll to zoom

32 FP4 codes

Each mint cube represents one four-bit code.

Two local scales

Gold E4M3 scales: one per 16 codes. Lines show ownership.

One tensor scale

Blue FP32 scale: shared across the tensor.

ŵ = FP4(code) × block scale × tensor scale

A grouping diagram, not a chip or byte-proportional model. Blender source · GLB model

13 / THE RECONSTRUCTION

A different decoding rule.

256 weights → eight subblocks of 32.

132 weights
sᵢ · mᵢ
232 weights
sᵢ · mᵢ
332 weights
sᵢ · mᵢ
432 weights
sᵢ · mᵢ
532 weights
sᵢ · mᵢ
632 weights
sᵢ · mᵢ
732 weights
sᵢ · mᵢ
832 weights
sᵢ · mᵢ
ŵᵢ = d × sⱼ × qᵢ − dmin × mⱼ

qᵢ is an unsigned nibble, 0…15.
Each subblock has a 6-bit scale and a 6-bit minimum parameter.

d and dmin are FP16 superblock factors. This is affine reconstruction, not the E2M1 codebook.

14 / Q4_K / KEEP ONE WEIGHT IN VIEW

Follow w₀. Same identity, new encoding.

ORIGINAL1.1CODE5BYTE0xA5DECODED1.0× ACTIVATION2.0w₀
① Encode
② Pack
③ Reconstruct
④ Multiply

Chosen gain 0.25 and offset 0.25. Illustrative nearest-code quantization, not CKE’s production parameter search.
The white outline tracks w₀; the companion high nibble belongs to w₃₂.

15 / THE RECONSTRUCTION

What is inside 144 bytes?

qs[0…31]qs[32…63]qs[64…95]qs[96…127]12 metadata bytesddmin

128 mint cubes
One cube = one byte.
Two codes per byte.

12 gold cubes
Eight scales + eight minima, six bits each.

Two blue blocks
d and dmin: FP16,
two bytes each.

4 chunks × 64 weights
= 256 weights

Memory offsets: d 0–1 · dmin 2–3 · metadata 4–15 · payload 16–143. Exploded view; sizes are schematic.

16 / THE RECONSTRUCTION

Split. Scale. Subtract.

0xA51010 0101510× (.125 × 2)× (.125 × 3)− (.0625 × 4)− (.0625 × 8)ŵ₀1ŵ₃₂3.25UNPACKLOCAL GAINOFFSETWEIGHT
① Low: b & 15
High: b >> 4
② Multiply each code
by its own d × sⱼ.
③ Subtract dmin × mⱼ.
Offsets are separate.
④ Store at lanes 0 / 32.
They are not adjacent.

Predict: do the two nibbles become neighbouring weights? Advance to reveal their destinations.

17 / THE RECONSTRUCTION

Open a real Q4_K block.

Drag to orbit · scroll to zoom

144 bytes → 256 weights

128 payload bytes + 12 metadata bytes + two 2-byte FP16 factors.

① Unpack 8 scale/minimum pairs.

② Split 0xA5 → low 5 / high 10.

③ Gain: d × s₀ = .125 × 2 = .25
5 × .25 = 1.25

④ Offset: .0625 × 4 = .25
ŵ₀ = 1.25 − .25 = 1

White outline: w₀ from the previous walkthrough. Sizes are schematic; height encodes values after splitting. Blender source · CKE-verified fixture

18 / CKE / THE DIAGRAM MEETS THE C

Watch the real decoder execute.

347const float d1 = d * (float)sc[2 * iter];
348const float m1 = dmin * (float)m[2 * iter];
352const uint8_t *qs = &block->qs[iter * 32];
353float *out = &output[iter * 64];
357const int q = (qs[l] & 0x0F);
358out[l] = d1 * (float)q - m1;
363const int q = (qs[l] >> 4);
364out[32 + l] = d2 * (float)q - m2;
w₀ · byte 0xA5
Ready
① Metadata
② Pointers
③ Mask
④ Reconstruct
⑤ Shift + route

Verbatim selected lines from CKE dequant_kernels.c; loops and other setup omitted. First iteration, l = 0.
d2 = 0.375 and m2 = 0.5 for the companion subblock. Scalar reference; optimized kernels may fuse decoding with compute.

19 / THE RECONSTRUCTION

A model is a collection of tensors.

Tensor A

Q4_K

Tensor B

Higher precision

Tensor C

Q4_K

Inspect the tensor inventory.

Q4_K_M selects a mixture of tensor types.
The precise mix depends on the converter, architecture and version.

Conceptual inventory, not a claim about any particular checkpoint.

20 / THE RECONSTRUCTION

Four bits is the starting point.

RepresentationAccountingBits / weight
MXFP4(32 × 4 + 8) ÷ 324.25
NVFP4(16 × 4 + 8) ÷ 16 + 32/N4.5 + 32/N
Q4_K block(128 + 12 + 4) bytes × 8 ÷ 2564.5

N: values sharing the NVFP4 global scale. Excludes padding, containers and other tensors. Q4_K_M overall size depends on its tensor mix.

21 / THE RUNTIME

The runtime must keep its promise.

Checkpointtensor types
Converterpacked layout
Dispatchmatching kernel
Computewider accumulator
Verifyreference parity

Four times smaller. Four times faster?

No guaranteed speed ratio: bandwidth, decoding and compute all matter. Measure on the target hardware.

22 / ANTSHIV ROBOTICS / PUT THE KERNEL IN CONTEXT

Measure the whole input-to-decision path.

INPUTcamera / voicePREPROCESSresize / featuresMODELquantized weightsDECISIONdownstream logic
① Prepare input
② Run inference
③ Use the result

Conceptual application, not a demonstrated control deployment. Weight storage is one part of memory; kernel time is one part of latency.

23 / THE RUNTIME

Three gates for a useful quant.

Correct bytes

Decode known blocks.
Check scales and lanes.

Useful behavior

Same model and tokenizer.
Test the intended robot tasks.

Target hardware

Measure latency and memory.
Check prefill and decode.

Hold KV precision, workload, hardware and runtime revision fixed when comparing weight formats.

24 / THE RUNTIME

The code is only half the story.

MXFP4

E2M1 values
One E8M0 scale / 32

NVFP4

E2M1 values
E4M3 / 16 + FP32 global

Q4_K

Unsigned integer codes
Subblock gain − offset

The format defines the meaning.
Our runtime must preserve it.

Q4_K_M describes a tensor recipe. None of these labels alone guarantees model quality or inference speed.

25 / THE RUNTIME

Keep building with Antshiv Robotics.

Antshiv Robotics on YouTube · antshiv.com
Watch the engineering on the channel. Read the mathematics on ShivasNotes.

MAIN EPISODE COMPLETE

Optional deep dives.

Bit packing · numerical examples · alternate animation clips · sources

Use these for a longer cut, a follow-up video, or questions.
Return to opening · Open sources

APPENDIX 01 / OPTIONAL DEEP DIVE

Ask three questions.

01 · Value

What does a four-bit code mean?
Integer or FP4?

02 · Scale

Which values share a ruler?
16, 32, or subblocks?

03 · Recipe

Which tensor gets which format?
Uniform or mixed?

Q4_K_M belongs at the recipe level. Q4_K is an underlying block type.

APPENDIX 02 / OPTIONAL DEEP DIVE

One scale for 32 values.

E8M0 scale → power of two
ŵᵢ = FP4(codeᵢ) × 2ᵉ
code value 3 × scale ½ = 1.5

One 8-bit scale per 32 four-bit elements. This diagram shows grouping, not physical byte order.

APPENDIX 03 / OPTIONAL DEEP DIVE

A finer local ruler.

Block A · 16 values

Block B · 16 values

ŵᵢ = FP4(codeᵢ) × sᵦ × sɢ

sᵦ: E4M3 block scale   sɢ: FP32 tensor scale

3 × .3125 × 1 = .9375

NVFP4 reconstruction convention. Some APIs store reciprocal scales; inspect the contract.

APPENDIX 04 / OPTIONAL DEEP DIVE

Same row. Different reconstruction.

IllustrationReconstructed weightsOutput
Original−1, .30, .90, 1.70−1.75
FP4 · scale .5−1, .25, 1, 1.5−2.00
FP4 · .3125 × 1−.9375, .3125, .9375, 1.875−1.5625
Δy = Σᵢ (ŵᵢ − wᵢ)xᵢ

Chosen valid reconstruction scales; not matched production quantizers. This example cannot rank model quality.

APPENDIX 05 / OPTIONAL DEEP DIVE

Decode the number, step by step.

d = .125s = 2q = 5dmin = .0625m = 4
local scale = .125 × 2 = .25
offset = .0625 × 4 = .25
ŵ = .25 × 5 − .25 = 1.00

Valid illustrative metadata. It demonstrates decoding, not how the quantizer fits the parameters.

APPENDIX 06 / OPTIONAL DEEP DIVE

Right arithmetic. Wrong lane?

0xA3

Low nibble · 3

qs[l] & 0x0F
output[l]

High nibble · 10

qs[l] >> 4
output[l + 32]

In each 64-weight chunk of the Q4_K decoder,
the two halves use different subblock metadata.

CKE dequant_q4_k_block, first iteration. These are not adjacent output weights.

APPENDIX 07 / OPTIONAL DEEP DIVE

Watch the layers separate.

APPENDIX 08 / OPTIONAL DEEP DIVE

A weight moves. An error remains.

APPENDIX 09 / OPTIONAL DEEP DIVE

Twelve bytes. Sixteen parameters.

Eight scales + eight minima × 6 bits = 96 bits = 12 bytes.

s₄ = (a₈ & 15) | ((a₀ >> 6) << 4)

Fixture: a₈ = 0x21; a₀ = 0x82 → 1 | 32 = 33

m₄ = (a₈ >> 4) | ((a₄ >> 6) << 4)

Fixture: a₄ = 0x44 → 2 | 16 = 18

a means the packed scales[12] array. Entries0–3 use the low6bits directly; entries4–7 combine bits from separate bytes. These are unsigned integer parameters, not FP4 values.

APPENDIX 10 / OPTIONAL DEEP DIVE

One byte. Two different rulers.

Low nibble → weight 0

0xA5 & 15 = 5

.125 × 2 × 5 − .0625 × 4

ŵ₀ = 1

High nibble → weight 32

0xA5 >> 4 = 10

.125 × 3 × 10 − .0625 × 8

ŵ₃₂ = 3.25

Repeat for 32 bytes → 64 weights.
Four chunks → all 256 weights.

Scalar reference: 144 packed bytes → 1,024 FP32 bytes.
A fused kernel can decode tiles into registers and multiply immediately.

Reconstruction approximates the original weights. Q4_K_M is a tensor-mixing recipe; this demonstrates one Q4_K block.

APPENDIX 11 / OPTIONAL DEEP DIVE

Specifications, code, and provenance.

Local Reveal.js + pinned GSAP 3.13.0. Numerical demonstrations are illustrative; no performance results are claimed.