Skip to content

Commit 3907795

Browse files
committed
fix(convert): Sanity check on merged FFN tensor sizes
Branch: GraniteMoE Co-Authored-By: [email protected] Signed-off-by: Gabe Goodhart <[email protected]>
1 parent b5b9e4b commit 3907795

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

convert_hf_to_gguf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4127,7 +4127,9 @@ def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iter
41274127
"""
41284128

41294129
if name.endswith("block_sparse_moe.input_linear.weight"):
4130-
gate, up = data_torch.chunk(2, dim=-2)
4130+
ffn_dim = self.hparams["intermediate_size"]
4131+
assert data_torch.shape[-2] == 2 * ffn_dim, "Merged FFN tensor size must be 2 * intermediate_size"
4132+
gate, up = data_torch[..., :ffn_dim, :], data_torch[..., ffn_dim:, :]
41314133
return [
41324134
(self.format_tensor_name(gguf.MODEL_TENSOR.FFN_GATE_EXP, bid), gate),
41334135
(self.format_tensor_name(gguf.MODEL_TENSOR.FFN_UP_EXP, bid), up),

0 commit comments

Comments
 (0)