-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Description
Description
Some newer model configurations (such as ChatGLM3) no longer include the field "num_hidden_layers".
Instead, they provide "num_layers".
The current converter code contains the following line:
self.gguf_writer.add_block_count(
self.hparams.get("num_layers", self.hparams["num_hidden_layers"])
)This leads to a KeyError even if "num_layers" is present and "num_hidden_layers" is not present in the model config.
Questions
-
Is the absence of
"num_hidden_layers"in newer models expected?
It appears that recent architectures rely on"num_layers"instead. -
Was the original line intended to assume
"num_hidden_layers"always exists?
If not, the KeyError suggests that the converter logic may be outdated for modern model configs. -
Should the converter be updated to support both fields safely rather than assuming
"num_hidden_layers"is always present?
Cause of the Error
The line:
self.hparams["num_hidden_layers"]directly indexes into the dict.
If "num_hidden_layers" is missing, Python raises:
KeyError: 'num_hidden_layers'
This happens even when "num_layers" is present, because the dict lookup is only used when "num_layers" is missing from the get() call.
Suggested Fix
To avoid failing when "num_hidden_layers" is absent, the line could be updated to a safer fallback:
self.gguf_writer.add_block_count(
self.hparams.get("num_layers", self.hparams.get("num_hidden_layers", 0)))This ensures:
"num_layers"is used when available"num_hidden_layers"is used if"num_layers"is missing- a fallback value (e.g.,
0) prevents a crash