Module numeric

Module numeric 

Source
Expand description

Host-side numeric conversions shared by every weight loader: the FP8 E4M3 decode table and the f32 -> BF16 cast.

This is the single copy. It used to exist twice — once in spark-model/src/weight_map/fp8_lut.rs (live) and once in atlas-quant/src/fp8.rs (unreachable, zero dependents) — with the byte-exactness tests attached to the copy that never ran. Both crates already depended on atlas-core, so the fix was to move the arithmetic down here and bring the tests with it.

Pure arithmetic: no CUDA, no allocation, compiles under every feature combination. The CUDA-side mirrors are E4M3_LUT_GMOE and __float2bfloat16_rn in kernels/gb10/common/moe_fp8_grouped_gemm.cu; they must agree with this file element for element.

Statics§

FP8_E4M3_LUT
FP8 E4M3 -> f32 lookup table (256 entries, one per byte value).

Functions§

bf16_bytes_to_f32
Widen little-endian BF16 bytes to f32. Exact — BF16 is the top 16 bits of an f32, so this is a shift, never a rounding.
f32_to_bf16
Convert f32 to BF16 with IEEE-754 round-to-nearest-even.
fp8_e4m3_to_f32
Decode one FP8 E4M3 byte to f32 (branchless, single array lookup).