Skip to content

Commit 995f36e

Browse files
gabe-l-hartCISC
authored andcommitted
feat: Add conversion support in GraniteHybrid for non-hybrid (all attn) (ggml-org#16177)
This is a configuration of the hparams in the GraniteHybrid architecture that devolves to the Granite (or GraniteMoe) architecture (ie Granite 3.x). It may be used for some models in the Granite 4 family with the GraniteHybrid architecture acting as a superset arch. Rather than support it directly in the c++ graph, we simply coerce the architecture flag back to the correct "granite" or "granitemoe" architecture. Branch: gabe-l-hart/GraniteNonHybridConversion Signed-off-by: Gabe Goodhart <[email protected]> Co-authored-by: Sigbjørn Skjæret <[email protected]>
1 parent d8153e1 commit 995f36e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

convert_hf_to_gguf.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7686,6 +7686,21 @@ def __init__(self, *args, **kwargs):
76867686
if i not in self._attn_layers
76877687
]
76887688

7689+
# There are some models in this family that are non-hybrid, but keep the
7690+
# same parent class by setting all layers to "attention." If this is the
7691+
# case, the model architecture needs to be updated to a standard
7692+
# "granite" or "granitemoe" model
7693+
if not self._ssm_layers:
7694+
has_experts = self.find_hparam(["num_experts_per_tok"], optional=True)
7695+
new_arch = (
7696+
gguf.MODEL_ARCH.GRANITE_MOE
7697+
if has_experts else
7698+
gguf.MODEL_ARCH.GRANITE
7699+
)
7700+
self.model_arch = new_arch
7701+
self.gguf_writer.arch = gguf.MODEL_ARCH_NAMES[new_arch]
7702+
self.gguf_writer.add_architecture()
7703+
76897704
# n_group and d_inner are used during reshape_tensors for mamba2
76907705
# NOTE: Explicitly include hparam prefix prefix for d_model to
76917706
# disambiguate with top-level head_dim
@@ -7770,8 +7785,11 @@ def set_gguf_parameters(self):
77707785
self.gguf_writer.add_rope_dimension_count(rope_dim)
77717786
self.gguf_writer.add_head_count_kv(head_count_kv_vec)
77727787

7773-
## If Bamba, use rope, otherwise don't
7774-
use_rope = "BambaForCausalLM" in self.hparams["architectures"]
7788+
## If Bamba or non-hybrid, use rope, otherwise don't
7789+
use_rope = (
7790+
"BambaForCausalLM" in self.hparams["architectures"]
7791+
or not self._ssm_layers
7792+
)
77757793
self.gguf_writer.add_rope_scaling_finetuned(use_rope)
77767794
if not use_rope:
77777795
self.gguf_writer.add_context_length(2**20)

0 commit comments

Comments
 (0)