Skip to content

quantize::sgfp4_decoder

More...

Classes

Name
class quantize::sgfp4_decoder::SGFP4FormatError

Functions

Name
int int4_to_int(int nib)
int sym2_to_ternary(int sym)
np.ndarray decode_v1(bytes binary, int O, int I)
np.ndarray decode_v2(bytes binary, int O, int I)

Detailed Description

Reference SGFP4 decoder implementing the normative decode semantics.

The decoder covers both SGFP4 profiles from the format specification:

* v1 fixed payload: ``headers[B] | offsets[B] | codes_blob[B*2048]``.
* v2 adaptive: ``SGF4 | 0x02 | B | pad0 | record_offsets[B] | pad1 |
  records``.

The v2 stream frames its record structure. The original tensor dimensions
``(O, I)`` are supplied by the enclosing model manifest and are required to
recover the macroblock grid and crop edge padding.

Functions Documentation

function int4_to_int

int int4_to_int(
    int nib
)
Decode a two's-complement 4-bit code.```


### function sym2_to_ternary

```python
int sym2_to_ternary(
    int sym
)
Decode a 2-bit ternary symbol; reserved ``11`` decodes as zero.```


### function decode_v1

```python
np.ndarray decode_v1(
    bytes binary,
    int O,
    int I
)
Decode a v1 fixed-payload container to a float32 ``(O, I)`` tensor.```


### function decode_v2

```python
np.ndarray decode_v2(
    bytes binary,
    int O,
    int I
)

Decode a v2 quadtree-adaptive container using manifest shape metadata.


Updated on 2026-10-09 at 03:59:43 +0000