qualia_core_db/inference/moe/
nvfp4.rs1pub use qualia_inference_kernel::moe::nvfp4::*;
3
4#[cfg(test)]
5mod tests {
6 use super::*;
7
8 #[test]
9 fn test_fp8_e4m3_conversion() {
10 assert_eq!(fp8_e4m3_to_f32(0x38), 1.0);
13 assert_eq!(fp8_e4m3_to_f32(0x40), 2.0);
15 assert_eq!(fp8_e4m3_to_f32(0xB8), -1.0);
17 }
18
19 #[test]
20 fn test_dequantize_nvfp4_block() {
21 let mut packed = [0u8; 8];
22 packed[0] = 0x42;
24 packed[1] = 0xA7;
26
27 let scale = 0x38; let global = 1.0f32;
29 let mut out = [0.0f32; 16];
30
31 dequantize_nvfp4_block(&packed, scale, global, &mut out);
32
33 assert_eq!(out[0], 1.0);
34 assert_eq!(out[1], 2.0);
35 assert_eq!(out[2], 6.0);
36 assert_eq!(out[3], -1.0);
37 assert_eq!(out[4], 0.0);
38 }
39
40 #[test]
41 fn test_nvfp4_gemv_zero_heap() {
42 let mut packed = [0u8; 16];
44 packed[0] = 0x42;
46 packed[8] = 0x53;
48
49 let scales = [0x38, 0x38]; let mut input = [0.0f32; 16];
51 input[0] = 10.0;
52 input[1] = 5.0;
53
54 let mut out = [0.0f32; 2];
55 nvfp4_gemv_zero_heap(&input, &packed, &scales, 1.0, 2, 16, &mut out).unwrap();
56
57 assert_eq!(out[0], 20.0);
59 assert_eq!(out[1], 30.0);
61 }
62}