@@ -112,7 +112,14 @@ def _write_quantized_gguf(
112112 writer .add_head_count (num_heads )
113113 writer .add_head_count_kv (num_kv_heads )
114114 writer .add_rope_freq_base (10000.0 )
115- writer .add_layer_norm_rms_eps (1e-5 )
115+ if architecture in {"olmo" , "cohere2" }:
116+ writer .add_layer_norm_eps (1e-5 )
117+ else :
118+ writer .add_layer_norm_rms_eps (1e-5 )
119+ if architecture == "cohere2" :
120+ writer .add_sliding_window (128 )
121+ writer .add_logit_scale (0.0625 )
122+ writer .add_rope_dimension_count (head_dim := hidden_size // num_heads )
116123 writer .add_vocab_size (vocab_size )
117124
118125 head_dim = hidden_size // num_heads
@@ -262,16 +269,25 @@ def add_projection(name: str, n_out: int, k_in: int) -> None:
262269 hidden_size ,
263270 num_heads * head_dim ,
264271 )
265- add_projection (f"blk.{ i } .ffn_gate.weight" , intermediate_size , hidden_size )
272+ if architecture != "arcee" :
273+ add_projection (f"blk.{ i } .ffn_gate.weight" , intermediate_size , hidden_size )
266274 add_projection (f"blk.{ i } .ffn_up.weight" , intermediate_size , hidden_size )
267275 add_projection (f"blk.{ i } .ffn_down.weight" , hidden_size , intermediate_size )
268- # Norms (float32)
269- add_float (f"blk.{ i } .attn_norm.weight" , (hidden_size ,))
270- add_float (f"blk.{ i } .ffn_norm.weight" , (hidden_size ,))
276+ if architecture == "olmo2" :
277+ add_float (f"blk.{ i } .post_attention_norm.weight" , (hidden_size ,))
278+ add_float (f"blk.{ i } .post_ffw_norm.weight" , (hidden_size ,))
279+ add_float (f"blk.{ i } .attn_q_norm.weight" , (num_heads * head_dim ,))
280+ add_float (f"blk.{ i } .attn_k_norm.weight" , (num_kv_heads * head_dim ,))
281+ elif architecture == "cohere2" :
282+ add_float (f"blk.{ i } .attn_norm.weight" , (hidden_size ,))
283+ elif architecture != "olmo" :
284+ add_float (f"blk.{ i } .attn_norm.weight" , (hidden_size ,))
285+ add_float (f"blk.{ i } .ffn_norm.weight" , (hidden_size ,))
271286
272287 # Output norm + optional untied lm_head
273- add_float ("output_norm.weight" , (hidden_size ,))
274- if not tie_embeddings :
288+ if architecture != "olmo" :
289+ add_float ("output_norm.weight" , (hidden_size ,))
290+ if architecture != "cohere2" and not tie_embeddings :
275291 if output_quantization == "q4_0" :
276292 _add_q4_0 ("output.weight" , vocab_size , hidden_size )
277293 elif output_quantization == "q8_0" :
@@ -441,6 +457,53 @@ def test_float_only_default_uses_float_path(self, float_only_gguf: Path):
441457 assert "GatherBlockQuantized" not in op_types
442458 assert "BlockQuantizedMatMul" not in op_types
443459
460+ @pytest .mark .parametrize (
461+ "architecture" ,
462+ ["olmo" , "olmo2" , "cohere2" , "arcee" , "smollm3" , "exaone" ],
463+ )
464+ @pytest .mark .parametrize ("projection_quantization" , ["f32" , "q4_0" ])
465+ def test_dense_cohort_builds_complete_graphs (
466+ self ,
467+ architecture : str ,
468+ projection_quantization : str ,
469+ tmp_path : Path ,
470+ ) -> None :
471+ """Exact per-architecture tensor sets satisfy the full graph."""
472+ from mobius .integrations .gguf import build_from_gguf
473+
474+ path = tmp_path / f"{ architecture } -{ projection_quantization } .gguf"
475+ _write_quantized_gguf (
476+ path ,
477+ architecture = architecture ,
478+ projection_quantization = projection_quantization ,
479+ )
480+
481+ model = build_from_gguf (path )["model" ]
482+ op_types = {node .op_type for node in model .graph }
483+ if projection_quantization == "q4_0" :
484+ assert "MatMulNBits" in op_types
485+ else :
486+ assert "MatMulNBits" not in op_types
487+
488+ output_dir = tmp_path / f"{ architecture } -{ projection_quantization } -onnx"
489+ build_from_gguf (path ).save (output_dir , progress_bar = False )
490+ session = ort .InferenceSession (
491+ str (output_dir / "model.onnx" ),
492+ providers = ["CPUExecutionProvider" ],
493+ )
494+ feeds = {
495+ "input_ids" : np .array ([[1 , 2 ]], dtype = np .int64 ),
496+ "attention_mask" : np .ones ((1 , 2 ), dtype = np .int64 ),
497+ "position_ids" : np .array ([[0 , 1 ]], dtype = np .int64 ),
498+ "past_key_values.0.key" : np .empty ((1 , 2 , 0 , 16 ), dtype = np .float32 ),
499+ "past_key_values.0.value" : np .empty ((1 , 2 , 0 , 16 ), dtype = np .float32 ),
500+ }
501+ first = session .run (["logits" ], feeds )[0 ]
502+ second = session .run (["logits" ], feeds )[0 ]
503+ assert first .shape == (1 , 2 , 256 )
504+ assert np .isfinite (first ).all ()
505+ np .testing .assert_array_equal (first , second )
506+
444507 def test_q4_0_matmulnbits_has_explicit_zero_points (self , q4_0_gguf : Path ):
445508 """GGUF Q4_0 projections explicitly encode zp=8 instead of EP defaults."""
446509 from mobius .integrations .gguf import build_from_gguf
0 commit comments