Repository navigation
feat(quant): support GGML_TYPE_NVFP4 (40), GGML_TYPE_F8_E4M3 (43), and scalar & per-expert .scale across CPU, Vulkan, and CUDA - #68
Conversation
Aletheore Flash reviewNo issues found in this diff. Note: 14 of 36 changed file(s) were not included in this review (the review reads at most 30 files, and skips any file over 100KB). Issues in them would not be found, and citations pointing into them could not be checked against the real file: Blast radius: 39 other file(s) depend on what this PR changes (31 directly, 8 indirectly)Computed from the import graph of this exact commit, not guessed by a model. It sees imports only, so dynamic imports, reflection and non-code references are not counted.
Indirectly affected: |
🔍 Aletheore evidence diffgraph LR
n0["backend.rs"]
n1["src/cpu_moe.rs"]
n2["src/cuda/mod.rs"]
n3["mat.rs"]
n4["src/hy4/forward.rs"]
n5["src/inkling2/forward.rs"]
n6["src/model.rs"]
n7["src/quant/mod.rs"]
n8["mmproj.rs"]
n9["src/vulkan/mod.rs"]
n10["weights.rs"]
n11["cpu_worker.rs"]
n12["src/deepseek/forward.rs"]
n13["src/deepseek/mod.rs"]
n14["expert_cache.rs"]
n15["src/gemma4/forward.rs"]
n16["src/gguf.rs"]
n17["src/glm/forward.rs"]
n18["src/glm/mod.rs"]
n19["src/gpu_model.rs"]
n20["prefill.rs"]
n21["src/hy4/chat.rs"]
n22["src/hy4/mod.rs"]
n23["src/inkling2/chat.rs"]
n24["device.rs"]
n25["src/inkling2/mod.rs"]
n26["lib.rs"]
n27["main.rs"]
n28["src/vision/mod.rs"]
n29["projector.rs"]
n30["prompt.rs"]
n31["preflight.rs"]
n32["spv_smem.rs"]
n33["tests/common/mod.rs"]
n34["tests/cpu_moe.rs"]
n35["tests/gguf.rs"]
n36["tests/gpu_model.rs"]
n37["kv_q8.rs"]
n38["llama_numerics.rs"]
n39["tests/model.rs"]
n40["quant_ggml.rs"]
n41["vision.rs"]
n0 --> n11
n0 --> n14
n0 --> n19
n0 --> n20
n0 --> n24
n0 --> n26
n0 --> n27
n0 --> n33
n0 --> n36
n0 --> n37
n0 --> n38
n1 --> n11
n1 --> n15
n1 --> n26
n1 --> n34
n2 --> n26
n2 --> n31
n2 --> n33
n2 --> n36
n2 --> n37
n2 --> n38
n3 --> n12
n3 --> n13
n3 --> n15
n3 --> n17
n3 --> n24
n3 --> n27
n4 --> n21
n4 --> n22
n4 --> n27
n5 --> n23
n5 --> n24
n5 --> n25
n5 --> n27
n6 --> n11
n6 --> n14
n6 --> n19
n6 --> n20
n6 --> n26
n6 --> n27
n6 --> n30
n6 --> n36
n6 --> n39
n6 --> n41
n7 --> n13
n7 --> n14
n7 --> n16
n7 --> n18
n7 --> n19
n7 --> n26
n7 --> n31
n7 --> n32
n7 --> n40
n8 --> n28
n8 --> n29
n8 --> n33
n9 --> n26
n9 --> n31
n9 --> n33
n9 --> n36
n9 --> n37
n9 --> n38
n10 --> n11
n10 --> n14
n10 --> n16
n10 --> n20
n10 --> n26
n10 --> n29
n10 --> n35
classDef changed fill:#d9772c,color:#fff,stroke:#b85f1c;
classDef changedFinding fill:#c0392b,color:#fff,stroke:#922b21;
classDef dependent fill:#f2f0ec,color:#18140f,stroke:#d6d0c5;
class n0 changed
class n1 changed
class n2 changed
class n3 changed
class n4 changed
class n5 changed
class n6 changed
class n7 changed
class n8 changed
class n9 changed
class n10 changed
class n11 dependent
class n12 dependent
class n13 dependent
class n14 dependent
class n15 dependent
class n16 dependent
class n17 dependent
class n18 dependent
class n19 dependent
class n20 dependent
class n21 dependent
class n22 dependent
class n23 dependent
class n24 dependent
class n25 dependent
class n26 dependent
class n27 dependent
class n28 dependent
class n29 dependent
class n30 dependent
class n31 dependent
class n32 dependent
class n33 dependent
class n34 dependent
class n35 dependent
class n36 dependent
class n37 dependent
class n38 dependent
class n39 dependent
class n40 dependent
class n41 dependent
What changed
Aggregate deltas
|
45b8916 to
dcb5411
Compare
… across CPU, Vulkan, and CUDA
dcb5411 to
0ceb068
Compare
…wice), the per-expert .scale of an Inkling 2 file is applied once (it was applied twice, which broke the output), and the generated tables.rs is as tools/gen_tables.py writes it
|
@ybenyedder Merged, ty. Three fixes went on top in 19bfba8, all found by running it on a CUDA card:
|
Summary
Adds full end-to-end support for
GGML_TYPE_NVFP4(id40),GGML_TYPE_F8_E4M3(id43), and companion<stem>.scaletensors (both scalar[1]F32 per-tensor scales and 1-D[n_expert]F32 per-expert scales) across CPU, Vulkan, and CUDA.Changes
GGML_TYPE_NVFP4(id = 40, 36 bytes / 64 elements):UE4M3,0x00and0x7F->0.0) sub-block scales at bytes0..4and4 × 8bytes of packed 4-bitE2M1nibbles (lo = 0..8,hi = 8..16) at bytes4..36usingKVALUES_FP4 = [0, 1, 2, 3, 4, 6, 8, 12, 0, -1, -2, -3, -4, -6, -8, -12]withue4m3_to_f32halved to match2 × E2M1.src/quant/mod.rs(dequant_row,nvfp4),src/cpu_moe.rs(dot_nvfp4againstQ8_K),src/vulkan/shaders/deq.glsl(qi8and shared-memory 2-codes-per-lookups_iq4inqw), andsrc/cuda/kernels.cu(QI<40>,deq8<40>,fp4_lut).GGML_TYPE_F8_E4M3(id = 43, 1 byte / element):0x7F/0xFFNaN ->0.0), classified asfloat_x()(decoded directly without block-integerQ8_1activation quantization).src/quant/mod.rs(f8_e4m3_to_f32),src/vulkan/shaders/deq.glsl(deq8T == 43), andsrc/cuda/kernels.cu(deq8<43>,FTYPES).<stem>.scaleTensors (Scalar[1]F32 & Per-Expert 1-D[n_expert]F32):Weights::get(src/weights.rs) andMat::load/Mat::expert_host(src/deepseek/mat.rs) automatically load<stem>.scale(e.g. ModelOptweight_scale_2inQwen3.8-27B-NVFP4-QAD.ggufor per-expert 1-D[n_expert]scales inInkling-2-Minimainline GGUFs) and attachscale: f32toTensor,Mat, andGpuTensor.Tensor::row,cpu_moe::matvec,cpu_moe::batch_rows,Mat::row_into,Mat::matvec,matvec_rows), Vulkan (dequant.comp,gemv_f.comp,gemv_q.comp,gemm_f.glsl,gemmi.glsl), and CUDA (dequant_*,gemv_*,gemvn_*,gemm_*,gemms_*,gemmi_*,gemmis_*), including pairedgemvq2with distinctsc1/sc2scales andact = 0, 1, 2in prefill GEMM.Verification
cargo test --release --lib --locked: 96/96 passedcargo test --release --test quant --locked: 25/25 passed (nvfp4_and_f8_e4m3_blocksok)cargo test --release --test backend --locked: 10/10 passed (spirv_is_freshok)cargo test --release --test kernels --locked:tensor_scale_applies_to_all_gpu_ops,vulkan_type_matrix(all 30GgmlTypevariants), andgemv_partial_superblocks_and_q2_0passed on AMD Radeon 890M (gfx1150, RADV Vulkan).Qwen3.8-27B-NVFP4-QAD.gguf(--gpu --backend vulkan).src/cuda/kernels.cuandsrc/cuda/mod.rsare kept in lockstep (cuda::tests::kernel_namespasses) and not compiled on this AMD host.