Float4

For conceptual model usage and type mapping, see:

class pyrogue.Float4(bitSize)[source]

Model class for 4-bit E2M1 floating point numbers (NVIDIA Blackwell FP4).

Parameters:
  • bitSize (int) – Number of bits being represented. Must be 8 (stored in 1-byte word).

  • args (Any)

  • kwargs (Any)

Return type:

Any

Notes

Format: 1 sign bit, 2 exponent bits, 1 mantissa bit (E2M1). Bias = 1. No infinity representation. No NaN representation. All 16 bit patterns are finite values or zero. Only 8 distinct magnitudes: 0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0. Maximum representable value is 6.0. Stored in lower 4 bits of a uint8_t byte. Supported by NVIDIA Blackwell GPUs.

pytype

alias of float

toBytes(value)[source]

Convert float to 1-byte E2M1 encoding (4 active bits in uint8).

NaN and infinity inputs are clamped to max finite value (+/-6.0) since E2M1 has no NaN or infinity encodings.

Return type:

bytearray

Parameters:

value (float)

fromBytes(ba)[source]

Decode 1-byte E2M1 encoding to float.

All 16 bit patterns decode to finite values or zero (no NaN/Inf).

Return type:

float

Parameters:

ba (bytes)

fromString(string)[source]

Parse a string into a float value.

Return type:

float

Parameters:

string (str)

minValue()[source]

Return the minimum representable value (-6.0).

Return type:

float

maxValue()[source]

Return the maximum representable value (6.0).

Return type:

float

class pyrogue.Float4BE(bitSize)[source]

Model class for 4-bit E2M1 floats stored as big endian.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any