@@ -1112,6 +1112,7 @@ def _write_nemotron_h_moe_gguf(
11121112 extra : str | None = None ,
11131113 malformed_shape : str | None = None ,
11141114 mtp : bool = False ,
1115+ quantized_only : str | None = None ,
11151116) -> None :
11161117 """Write a tiny exact Nemotron-H backbone covering all four layer kinds."""
11171118 from gguf import GGMLQuantizationType , GGUFWriter
@@ -1202,7 +1203,12 @@ def add_q4(name: str, shape: tuple[int, ...]) -> None:
12021203 )
12031204 writer .add_tensor (name , raw , raw_dtype = GGMLQuantizationType .Q4_0 )
12041205
1205- projection = add_q4 if quantized else add_float
1206+ def projection (name : str , shape : tuple [int , ...]) -> None :
1207+ if quantized and (quantized_only is None or name == quantized_only ):
1208+ add_q4 (name , shape )
1209+ else :
1210+ add_float (name , shape )
1211+
12061212 add_float ("token_embd.weight" , (vocab , hidden ))
12071213 add_float ("output_norm.weight" , (hidden ,))
12081214 projection ("output.weight" , (vocab , hidden ))
@@ -5249,6 +5255,20 @@ def test_quantized_source_requires_explicit_dequantization(self, tmp_path: Path)
52495255 == ir .DataType .FLOAT
52505256 )
52515257
5258+ def test_quantized_expert_only_requires_explicit_dequantization (
5259+ self , tmp_path : Path
5260+ ) -> None :
5261+ from mobius .integrations .gguf import build_from_gguf
5262+
5263+ path = tmp_path / "nemotron-h-moe-expert-q4.gguf"
5264+ _write_nemotron_h_moe_gguf (
5265+ path ,
5266+ quantized = True ,
5267+ quantized_only = "blk.1.ffn_up_exps.weight" ,
5268+ )
5269+ with pytest .raises (ValueError , match = r"keep_quantized=False" ):
5270+ build_from_gguf (path , keep_quantized = True )
5271+
52525272 @pytest .mark .parametrize (
52535273 ("kwargs" , "match" ),
52545274 [
0 commit comments