Skip to content

Commit bc136dd

Browse files
committed
Fix glm4 models
1 parent c2437b8 commit bc136dd

5 files changed

Lines changed: 92 additions & 358 deletions

File tree

backend/architecture_profiles.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,60 @@ def compute_block_and_effective_layers(
7878
}
7979

8080

81+
class GlmProfile(ArchitectureProfile):
82+
"""Profile for GLM models (non-MoE variants like GLM-Z1, GLM-4)."""
83+
def __init__(self) -> None:
84+
super().__init__(names=("glm", "glm4"))
85+
86+
def compute_block_and_effective_layers(
87+
self,
88+
metadata: Dict[str, Any],
89+
base_block_count: int,
90+
) -> Dict[str, int]:
91+
# Try GLM-specific keys first (check both glm.* and glm4.*)
92+
glm_block_count = (
93+
metadata.get("glm4.block_count")
94+
or metadata.get("glm.block_count")
95+
or metadata.get("glm4.layer_count")
96+
or metadata.get("glm.layer_count")
97+
or metadata.get("glm4.n_layer")
98+
or metadata.get("glm.n_layer")
99+
)
100+
101+
# Also check for nextn_predict_layers (used in some GLM variants)
102+
nextn_layers = (
103+
metadata.get("glm4.nextn_predict_layers")
104+
or metadata.get("glm.nextn_predict_layers")
105+
)
106+
107+
block_count = base_block_count
108+
if isinstance(glm_block_count, (int, float)) and glm_block_count > 0:
109+
block_count = int(glm_block_count)
110+
111+
# For GLM models, effective_layer_count = block_count (no +1 like Llama)
112+
# Some GLM variants have nextn_predict_layers that should be added
113+
effective_layer_count = block_count or 0
114+
if isinstance(nextn_layers, (int, float)) and nextn_layers > 0:
115+
effective_layer_count = int(effective_layer_count) + int(nextn_layers)
116+
117+
logger.info(
118+
"glm profile: block_count=%s, effective_layer_count=%s "
119+
"(base_block_count=%s, glm_block_count=%s, nextn_predict_layers=%s)",
120+
block_count,
121+
effective_layer_count,
122+
base_block_count,
123+
glm_block_count,
124+
nextn_layers,
125+
)
126+
127+
return {
128+
"block_count": int(block_count) if block_count else 0,
129+
"effective_layer_count": int(effective_layer_count)
130+
if effective_layer_count
131+
else 0,
132+
}
133+
134+
81135
class LlamaLikeProfile(ArchitectureProfile):
82136
"""
83137
LLaMA-style decoder-only LMs (llama, mistral, mixtral, gemma, etc.).
@@ -208,6 +262,7 @@ def compute_block_and_effective_layers(
208262

209263
PROFILES: List[ArchitectureProfile] = [
210264
Glm4MoeProfile(),
265+
GlmProfile(), # Must come after Glm4MoeProfile so glm4moe matches first
211266
LlamaLikeProfile(),
212267
QwenFamilyProfile(),
213268
DeepseekProfile(),

backend/gguf_reader.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

frontend/src/components/config/HfDefaultsCard.vue

Lines changed: 0 additions & 188 deletions
This file was deleted.

frontend/src/components/config/ModelInfoSection.vue

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
<p>This model automatically exposes the /v1/embeddings endpoint via llama.cpp.</p>
2323
</div>
2424
</div>
25-
<HfDefaultsCard
26-
v-if="hasHfMetadata"
27-
:hf-metadata="hfMetadata"
28-
:hf-context-value="hfContextValue"
29-
:hf-defaults-list="hfDefaultsList"
30-
:hf-layer-info-list="hfLayerInfoList"
31-
:loading="hfMetadataLoading"
32-
/>
3325
</div>
3426
<div class="header-actions">
3527
<div class="action-buttons">
@@ -70,7 +62,6 @@
7062
import { computed } from 'vue'
7163
import { formatFileSize } from '@/utils/formatting'
7264
import Button from 'primevue/button'
73-
import HfDefaultsCard from './HfDefaultsCard.vue'
7465
7566
const props = defineProps({
7667
model: {
@@ -89,18 +80,6 @@ const props = defineProps({
8980
type: Object,
9081
default: null
9182
},
92-
hfContextValue: {
93-
type: Number,
94-
default: null
95-
},
96-
hfDefaultsList: {
97-
type: Array,
98-
default: () => []
99-
},
100-
hfLayerInfoList: {
101-
type: Array,
102-
default: () => []
103-
},
10483
hfMetadataLoading: {
10584
type: Boolean,
10685
default: false

0 commit comments

Comments
 (0)