Skip to main content

Python function

float32_to_bfloat16_as_uint16

float32_to_bfloat16_as_uint16()

max.pipelines.lib.float32_to_bfloat16_as_uint16(arr)

source

Converts a float32 array to bfloat16 representation stored as uint16.

BFloat16 is the upper 16 bits of float32 with proper rounding. This allows us to halve memory usage while maintaining the exponent range.

Parameters:

arr (ndarray[tuple[Any, ...], dtype[float32]]) – Float32 numpy array

Returns:

Uint16 array containing bfloat16 bit representation with same shape

Return type:

ndarray[tuple[Any, …], dtype[uint16]]