Allow embedding shape mismatch

#269
This commit is contained in:
City
2025-04-22 15:50:05 +02:00
parent 66c50234a4
commit 54a4854e0c
2 changed files with 4 additions and 3 deletions
+1 -3
View File
@@ -242,10 +242,8 @@ def gguf_clip_loader(path):
sd[temb_key] = dequantize_tensor(sd[temb_key], dtype=torch.float16)
sd = sd_map_replace(sd, T5_SD_MAP)
elif arch in {"llama"}:
# TODO: pass model_options["vocab_size"] to loader somehow
temb_key = "token_embd.weight"
if temb_key in sd and sd[temb_key].shape != (128320, 4096):
# This still works. TODO: Only relevant for llava?
logging.warning("Warning! token_embd shape may be incorrect for llama 3 model!")
if temb_key in sd and sd[temb_key].shape[0] >= (64 * 1024):
# See note above for T5.
logging.warning(f"Dequantizing {temb_key} to prevent runtime OOM.")
+3
View File
@@ -111,6 +111,9 @@ class GGMLLayer(torch.nn.Module):
# NOTE: using modified load for linear due to not initializing on creation, see GGMLOps todo
if self.is_ggml_quantized(weight=weight, bias=bias) or isinstance(self, torch.nn.Linear):
return self.ggml_load_from_state_dict(state_dict, prefix, *args, **kwargs)
# Not strictly required, but fixes embedding shape mismatch. Threshold set in loader.py
if isinstance(self, torch.nn.Embedding) and self.weight.shape[0] >= (64 * 1024):
return self.ggml_load_from_state_dict(state_dict, prefix, *args, **kwargs)
return super()._load_from_state_dict(state_dict, prefix, *args, **kwargs)
def ggml_load_from_state_dict(self, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs):