char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
fa88ae936
char/aliceai-t5-moe
1from __future__import annotations 2 3from typing import Callable ,Iterable ,TYPE_CHECKING 4 5if TYPE_CHECKING : 6from torch import Tensor 7 8from .base import MmprojModel ,ModelBase ,gguf 9 10 11@ ModelBase . register ( "Llama4ForConditionalGeneration" ) 12# [TAG_HF_EXAMPLE_GATED] meta-llama/Llama-4-Scout-17B-16E-Instruct is gated 13@ ModelBase . example ( "unsloth/Llama-4-Scout-17B-16E-Instruct" ) 14class Llama4VisionModel (MmprojModel ): 15def set_gguf_parameters (self ): 16super ().set_gguf_parameters () 17self .gguf_writer .add_clip_projector_type (gguf .VisionProjectorType .LLAMA4 ) 18self .gguf_writer .add_vision_attention_layernorm_eps (self .hparams ["norm_eps" ]) 19self .gguf_writer .add_vision_projector_scale_factor (int (1.0 / self .hparams ["pixel_shuffle_ratio" ])) 20assert self .hparams ["hidden_act" ]== "gelu" 21self .gguf_writer .add_vision_use_gelu (True ) 22 23@classmethod 24def filter_tensors (cls ,item :tuple [str ,Callable [[],Tensor ]])-> tuple [str ,Callable [[],Tensor ]]| None : 25name ,gen = item 26 27if "multi_modal_projector" not in name and "vision_model" not in name : 28return None 29 30if "positional_embedding_vlm" in name and ".weight" not in name : 31name += ".weight" 32 33return super ().filter_tensors ((name ,gen )) 34 35def modify_tensors (self ,data_torch :Tensor ,name :str ,bid :int | None )-> Iterable [tuple [str ,Tensor ]]: 36if "multi_modal_projector.linear_1" in name : 37# despite the name with number postfix, this is a single fully connected layer 38yield (gguf .TENSOR_NAMES [gguf .MODEL_TENSOR .V_MMPROJ_FC ]+ '.weight' ,data_torch ) 39else : 40yield from super ().modify_tensors (data_torch ,name ,bid )