@@ -1169,6 +1169,8 @@ def _raise_for_invalid_dense_c01_tensor_contract(gguf_model) -> None:
11691169 """Validate the exact pinned C01 dense profiles before config extraction."""
11701170 import numpy as np
11711171
1172+ from mobius .integrations .gguf ._tensor_mapping import is_known_skip
1173+
11721174 architecture = gguf_model .architecture
11731175 if architecture not in {"baichuan" , "chatglm" , "phi2" , "seed_oss" }:
11741176 return
@@ -1267,6 +1269,7 @@ def _raise_for_invalid_dense_c01_tensor_contract(gguf_model) -> None:
12671269 actual = {
12681270 name : tuple (int (dimension ) for dimension in shape )
12691271 for name , _raw , _qtype , shape in items
1272+ if not is_known_skip (name )
12701273 }
12711274 required : dict [str , tuple [int , ...]] = {
12721275 "token_embd.weight" : (vocab , hidden ),
@@ -2112,10 +2115,35 @@ def _raise_for_invalid_encoder_tensor_contract(gguf_model) -> None:
21122115 return
21132116
21142117 metadata = gguf_model .metadata
2118+ required_geometry = (
2119+ "context_length" ,
2120+ "embedding_length" ,
2121+ "feed_forward_length" ,
2122+ "block_count" ,
2123+ "attention.head_count" ,
2124+ )
2125+ missing_geometry = [
2126+ f"{ architecture } .{ suffix } "
2127+ for suffix in required_geometry
2128+ if f"{ architecture } .{ suffix } " not in metadata
2129+ ]
2130+ if missing_geometry :
2131+ raise ValueError (
2132+ f"{ architecture } GGUF is missing required encoder metadata: { missing_geometry } "
2133+ )
21152134 hidden = int (metadata [f"{ architecture } .embedding_length" ])
21162135 intermediate = int (metadata [f"{ architecture } .feed_forward_length" ])
21172136 layers = int (metadata [f"{ architecture } .block_count" ])
21182137 num_heads = int (metadata [f"{ architecture } .attention.head_count" ])
2138+ context = int (metadata [f"{ architecture } .context_length" ])
2139+ if min (hidden , intermediate , layers , num_heads , context ) <= 0 or hidden % num_heads :
2140+ raise ValueError (
2141+ f"{ architecture } GGUF has invalid encoder geometry: "
2142+ f"embedding_length={ hidden } , feed_forward_length={ intermediate } , "
2143+ f"block_count={ layers } , attention.head_count={ num_heads } , "
2144+ f"context_length={ context } ; all values must be positive and "
2145+ "embedding_length must be divisible by attention.head_count"
2146+ )
21192147 num_kv_heads = int (metadata .get (f"{ architecture } .attention.head_count_kv" , num_heads ))
21202148 if num_kv_heads != num_heads :
21212149 raise ValueError (
@@ -2125,13 +2153,16 @@ def _raise_for_invalid_encoder_tensor_contract(gguf_model) -> None:
21252153 vocab = int (metadata .get (f"{ architecture } .vocab_size" , 0 ))
21262154 if not vocab :
21272155 vocab = len (metadata .get ("tokenizer.ggml.tokens" , ()))
2128- context = int (metadata [f"{ architecture } .context_length" ])
2156+ if vocab <= 0 :
2157+ raise ValueError (f"{ architecture } GGUF has no positive vocabulary size" )
21292158
21302159 required : dict [str , tuple [int , ...]] = {
21312160 "token_embd.weight" : (vocab , hidden ),
21322161 }
21332162 if architecture == "bert" :
21342163 token_types = int (metadata .get ("tokenizer.ggml.token_type_count" , 0 ))
2164+ if token_types <= 0 :
2165+ raise ValueError ("bert GGUF tokenizer.ggml.token_type_count must be positive" )
21352166 required .update (
21362167 {
21372168 "token_types.weight" : (token_types , hidden ),
0 commit comments