Simulate a mixed-precision KV cache that stores the RoPE dimensions in BF16 and the rest in FP8 (E4M3). Implement two functions.
e4m3_grid(): return a sorted 1-D numpy array of all 253 finite FP8 E4M3 values: normals for and , except (NaN); subnormals for ; and a single zero. The largest magnitude is 448.
pack_kv_entries(entries, rope_dims, fp8_grid): entries is an (n, d) float array; the last rope_dims columns are rotary (rope_dims may be 0 or d).
fp8_grid (a sorted 1-D array); ties go to the smaller magnitude; values beyond the grid saturate to its end points."entries" (the dequantized (n, d) float array), "bytes_per_entry" = 2 * rope_dims + (d - rope_dims), "bf16_bytes_per_entry" = 2 * d, "ratio" = their quotient rounded to 4 decimals, and "max_abs_error" = the largest absolute difference between the input and the dequantized entries, rounded to 6 decimals.