Repository navigation
conversion : use original model tensor names in _flush_nvfp4_experts - #31427
Conversation
This commit updates the _flush_nvfp4_experts to take a new parameter
which is a dictionary mapping the key to the original model tensor name.
The motivation for this is that I noticed that the tensor names being
looked up were not the original model tensor names, for example:
```console
model.layers.1.mlp.experts.up_proj.weight
```
But _nvfp4_layer_algo uses the original per-expert names:
```console
(Pdb) p self._nvfp4_layer_algo
{
'backbone.layers.1.mixer.experts.0.up_proj': 'W4A16_NVFP4',
...
```
This means that the lookup will never match for experts and fall back to
_nvfp4_global_algo. If the global algo is W4A16_NVFP4 then this would
go unnoticed, but for a model like
nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-NVFP4 which is
MIXED_PRECISION, the expert tensors will not get prec_a4=false so they
would use the native W4A4 path on Blackwell even though the original
model tensors declare them as W4A16_NVFP4.
VerificationTested with With the code in this PR applied and the model converted we can see the following: 128 if (prec == GGML_PREC_Q8 || !can_use_q4) {
(gdb) p can_use_q4
$8 = true
(gdb) p prec
$9 = GGML_PREC_Q8
(gdb) n
129 return GGML_PREC_Q8;
(gdb) p src0->name
$10 = "CUDA0#blk.1.ffn_up_exps.weight#0", '\000' <repeats 31 times>Notice that this will return GGML_PREC_Q8 and this will return to: const bool use_native_fp4 = prec_src1 == GGML_PREC_Q4;(gdb) p use_native_fp4
$1 = falseThis tensor has the following prec_a4 setting in the converted model: We can then compare this with master after reconverting the model: (gdb) p can_use_q4
$5 = true
(gdb) p prec
$6 = GGML_PREC_UNDEFINED
(gdb) p src0->name
$4 = "CUDA0#blk.1.ffn_up_exps.weight#0", '\000' <repeats 31 times>
(gdb) f
#0 ggml_cuda_mmq_get_prec_src1 (src0=0xfffd8822cb80, dst=0xaaaab9733e50, cc=1210)
at /llama.cpp/ggml/src/ggml-cuda/mmq.cu:131
131 return GGML_PREC_Q4;So this will return to: const bool use_native_fp4 = prec_src1 == GGML_PREC_Q4;(gdb) p use_native_fp4
$7 = trueThis tensor has the following prec_a4 setting in the converted model: So on master this expert tensor uses the native W4A4 path even though it is The same applies to all the expert tensors. NVIDIA-Nemotron-3.5-Lightning-30B-A3B-NVFP4.gguf
tensor_extra entries: 93
prec_a4 values: {False: 93}
NVFP4 tensors: 93
NVFP4 without entry: 0Master: NVIDIA-Nemotron-3.5-Lightning-30B-A3B-NVFP4.gguf
tensor_extra entries: 47
prec_a4 values: {False: 47}
NVFP4 tensors: 93
NVFP4 without entry: 46 |
I've looked into this for Nemotron and checked that no renaming is done. But I think I see your point here, I'll look into this further in a follow up PR 👍 |
…gml-org#31427) This commit updates the _flush_nvfp4_experts to take a new parameter which is a dictionary mapping the key to the original model tensor name. The motivation for this is that I noticed that the tensor names being looked up were not the original model tensor names, for example: ```console model.layers.1.mlp.experts.up_proj.weight ``` But _nvfp4_layer_algo uses the original per-expert names: ```console (Pdb) p self._nvfp4_layer_algo { 'backbone.layers.1.mixer.experts.0.up_proj': 'W4A16_NVFP4', ... ``` This means that the lookup will never match for experts and fall back to _nvfp4_global_algo. If the global algo is W4A16_NVFP4 then this would go unnoticed, but for a model like nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-NVFP4 which is MIXED_PRECISION, the expert tensors will not get prec_a4=false so they would use the native W4A4 path on Blackwell even though the original model tensors declare them as W4A16_NVFP4.
Overview
This commit updates the _flush_nvfp4_experts to take a new parameter which is a dictionary mapping the key to the original model tensor name.
Additional information
The motivation for this is that I noticed that the tensor names being looked up were not the original model tensor names, for example:
model.layers.1.mlp.experts.up_proj.weightBut _nvfp4_layer_algo uses the original per-expert names:
This means that the lookup will never match for experts and fall back to _nvfp4_global_algo. If the global algo is W4A16_NVFP4 then this would go unnoticed, but for a model like nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-NVFP4 which is MIXED_PRECISION, the expert tensors will not get prec_a4=false, so they would use the native W4A4 path on Blackwell even though the original model tensors declare them as W4A16_NVFP4.
Requirements