(path)
| 468 | return torch.ByteTensor(list(spm.SerializeToString())) |
| 469 | |
| 470 | def gguf_clip_loader(path): |
| 471 | sd, extra = gguf_sd_loader(path, is_text_model=True) |
| 472 | arch = extra.get("arch_str", None) |
| 473 | if arch in {"t5", "t5encoder"}: |
| 474 | temb_key = "token_embd.weight" |
| 475 | if temb_key in sd and sd[temb_key].shape == (256384, 4096): |
| 476 | # non-standard Comfy-Org tokenizer |
| 477 | sd["spiece_model"] = gguf_tokenizer_loader(path, sd[temb_key].shape) |
| 478 | # TODO: dequantizing token embed here is janky but otherwise we OOM due to tensor being massive. |
| 479 | logging.warning(f"Dequantizing {temb_key} to prevent runtime OOM.") |
| 480 | sd[temb_key] = dequantize_tensor(sd[temb_key], dtype=torch.float16) |
| 481 | sd = sd_map_replace(sd, T5_SD_MAP) |
| 482 | elif arch in {"llama", "qwen2vl", "qwen3", "qwen3vl", "gemma3"}: |
| 483 | # TODO: pass model_options["vocab_size"] to loader somehow |
| 484 | temb_key = "token_embd.weight" |
| 485 | if temb_key in sd and sd[temb_key].shape[0] >= (64 * 1024): |
| 486 | if arch == "llama" and sd[temb_key].shape == (131072, 5120): |
| 487 | # non-standard Comfy-Org tokenizer |
| 488 | sd["tekken_model"] = gguf_tekken_tokenizer_loader(path, sd[temb_key].shape) |
| 489 | elif arch == "gemma3": |
| 490 | sd["spiece_model"] = gguf_gemma3_tokenizer_loader(path) |
| 491 | # See note above for T5. |
| 492 | logging.warning(f"Dequantizing {temb_key} to prevent runtime OOM.") |
| 493 | sd[temb_key] = dequantize_tensor(sd[temb_key], dtype=torch.float16) |
| 494 | if arch == "gemma3": |
| 495 | sd = sd_map_replace(sd, GEMMA3_SD_MAP) |
| 496 | sd = gemma3_norm_corrections(sd) |
| 497 | else: |
| 498 | sd = sd_map_replace(sd, LLAMA_SD_MAP) |
| 499 | if arch == "llama": |
| 500 | sd = llama_permute(sd, 32, 8) # L3 / Mistral |
| 501 | if arch == "qwen2vl": |
| 502 | vsd = gguf_mmproj_loader(path) |
| 503 | sd.update(vsd) |
| 504 | else: |
| 505 | pass |
| 506 | return sd |
no test coverage detected