@@ -239,6 +239,8 @@ def read_gguf_metadata(file_path: str) -> Optional[Dict[str, Any]]:
239239 # Extract embedding length with fallbacks for different architectures
240240 embedding_length = (
241241 metadata .get ('glm4moe.embedding_length' )
242+ or metadata .get ('glm4.embedding_length' ) # GLM4 models (non-MoE)
243+ or metadata .get ('glm.embedding_length' ) # GLM models (non-MoE)
242244 or metadata .get ('llama.embedding_length' )
243245 or metadata .get ('qwen3moe.embedding_length' )
244246 or metadata .get ('qwen3.embedding_length' )
@@ -250,6 +252,10 @@ def read_gguf_metadata(file_path: str) -> Optional[Dict[str, Any]]:
250252 # Extract attention head count with fallbacks
251253 attention_head_count = (
252254 metadata .get ('glm4moe.attention.head_count' )
255+ or metadata .get ('glm4.attention.head_count' ) # GLM4 models (non-MoE)
256+ or metadata .get ('glm4.attention_head_count' ) # Alternative GLM4 format
257+ or metadata .get ('glm.attention.head_count' ) # GLM models (non-MoE)
258+ or metadata .get ('glm.attention_head_count' ) # Alternative GLM format
253259 or metadata .get ('llama.attention_head_count' )
254260 or metadata .get ('qwen3moe.attention_head_count' )
255261 or metadata .get ('qwen3.attention_head_count' )
@@ -261,6 +267,10 @@ def read_gguf_metadata(file_path: str) -> Optional[Dict[str, Any]]:
261267 # Extract KV attention head count with fallbacks (for GQA)
262268 attention_head_count_kv = (
263269 metadata .get ('glm4moe.attention.head_count_kv' )
270+ or metadata .get ('glm4.attention.head_count_kv' ) # GLM4 models (non-MoE)
271+ or metadata .get ('glm4.attention_head_count_kv' ) # Alternative GLM4 format
272+ or metadata .get ('glm.attention.head_count_kv' ) # GLM models (non-MoE)
273+ or metadata .get ('glm.attention_head_count_kv' ) # Alternative GLM format
264274 or metadata .get ('llama.attention_head_count_kv' )
265275 or metadata .get ('qwen3moe.attention_head_count_kv' )
266276 or metadata .get ('qwen3.attention_head_count_kv' )
@@ -273,7 +283,16 @@ def read_gguf_metadata(file_path: str) -> Optional[Dict[str, Any]]:
273283 'layer_count' : int (effective_layer_count ) if effective_layer_count else 0 ,
274284 'architecture' : metadata .get ('general.architecture' , '' ),
275285 'context_length' : context_length ,
276- 'vocab_size' : metadata .get ('llama.vocab_size' , 0 ) or metadata .get ('qwen3moe.vocab_size' , 0 ) or metadata .get ('qwen3.vocab_size' , 0 ) or metadata .get ('qwen.vocab_size' , 0 ) or 0 ,
286+ 'vocab_size' : (
287+ metadata .get ('glm4moe.vocab_size' , 0 )
288+ or metadata .get ('glm4.vocab_size' , 0 ) # GLM4 models (non-MoE)
289+ or metadata .get ('glm.vocab_size' , 0 ) # GLM models (non-MoE)
290+ or metadata .get ('llama.vocab_size' , 0 )
291+ or metadata .get ('qwen3moe.vocab_size' , 0 )
292+ or metadata .get ('qwen3.vocab_size' , 0 )
293+ or metadata .get ('qwen.vocab_size' , 0 )
294+ or 0
295+ ),
277296 'embedding_length' : int (embedding_length ) if embedding_length else 0 ,
278297 'attention_head_count' : int (attention_head_count ) if attention_head_count else 0 ,
279298 'attention_head_count_kv' : int (attention_head_count_kv ) if attention_head_count_kv else 0 ,
@@ -301,7 +320,15 @@ def _extract_context_length(metadata: Dict[str, Any]) -> int:
301320 # Try different possible keys for context length
302321 context_keys = [
303322 'llama.context_length' , # Llama models
304- 'glm4moe.context_length' ,
323+ 'glm4moe.context_length' , # GLM4 MoE models
324+ 'glm4moe.max_sequence_length' , # GLM4 MoE models (alternative)
325+ 'glm4moe.max_seq_len' , # GLM4 MoE models (alternative)
326+ 'glm4.context_length' , # GLM4 models (non-MoE)
327+ 'glm4.max_sequence_length' , # GLM4 models (non-MoE)
328+ 'glm4.max_seq_len' , # GLM4 models (non-MoE)
329+ 'glm.context_length' , # GLM models (non-MoE)
330+ 'glm.max_sequence_length' , # GLM models (non-MoE)
331+ 'glm.max_seq_len' , # GLM models (non-MoE)
305332 'general.context_length' ,
306333 'general.max_sequence_length' ,
307334 'llama.max_seq_len' ,
@@ -346,20 +373,28 @@ def _extract_layer_count(metadata: Dict[str, Any]) -> int:
346373 layer_keys = [
347374 'llama.block_count' , # Most common for Llama models
348375 'glm4moe.block_count' , # GLM4 MoE architecture
376+ 'glm4.block_count' , # GLM4 architecture (non-MoE)
377+ 'glm.block_count' , # GLM architecture (non-MoE)
349378 'qwen3.block_count' , # Qwen3 architecture
350379 'qwen3moe.block_count' , # Qwen3 MoE architecture
351380 'qwen.block_count' , # Qwen architecture
352381 'general.block_count' ,
353382 'llama.layer_count' ,
354383 'glm4moe.layer_count' ,
384+ 'glm4.layer_count' , # GLM4 architecture (non-MoE)
385+ 'glm.layer_count' , # GLM architecture (non-MoE)
355386 'general.layer_count' ,
356387 'qwen.layer_count' ,
357388 'qwen3.layer_count' ,
358389 'llama.n_layer' ,
359390 'glm4moe.n_layer' ,
391+ 'glm4.n_layer' , # GLM4 architecture (non-MoE)
392+ 'glm.n_layer' , # GLM architecture (non-MoE)
360393 'general.n_layer' ,
361394 'llama.num_layers' ,
362395 'glm4moe.num_layers' ,
396+ 'glm4.num_layers' , # GLM4 architecture (non-MoE)
397+ 'glm.num_layers' , # GLM architecture (non-MoE)
363398 'general.num_layers'
364399 ]
365400
0 commit comments