For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Python function
bfloat16_as_uint16_to_float32
bfloat16_as_uint16_to_float32()
max.driver.bfloat16_as_uint16_to_float32(arr)
Converts bfloat16 bit patterns (stored as uint16) to float32.
The conversion is exact: a bfloat16 value is the top 16 bits of a
float32.
For example, read a bfloat16 buffer back as float32:
import numpy as np
from max.driver import (
Buffer,
bfloat16_as_uint16_to_float32,
float32_to_bfloat16_as_uint16,
)
from max.dtype import DType
bits = float32_to_bfloat16_as_uint16(np.array([1.5], np.float32))
buffer = Buffer.from_numpy(bits).view(DType.bfloat16)
values = bfloat16_as_uint16_to_float32(
buffer.view(DType.uint16).to_numpy()
)