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 Iterable ,TYPE_CHECKING 4 5if TYPE_CHECKING : 6from torch import Tensor 7 8from .base import ModelBase ,TextModel ,gguf 9 10 11@ ModelBase . register ( "MPTForCausalLM" ) 12@ ModelBase . example ( "anas-awadalla/mpt-7b" ) 13class MPTModel (TextModel ): 14model_arch = gguf .MODEL_ARCH .MPT 15 16def set_vocab (self ): 17try : 18self ._set_vocab_gpt2 () 19except Exception : 20# Fallback for SEA-LION model 21self ._set_vocab_sentencepiece () 22self .gguf_writer .add_add_bos_token (False ) 23self .gguf_writer .add_pad_token_id (3 ) 24self .gguf_writer .add_eos_token_id (1 ) 25self .gguf_writer .add_unk_token_id (0 ) 26 27def set_gguf_parameters (self ): 28self .gguf_writer .add_context_length (self .hparams ["max_seq_len" ]) 29self .gguf_writer .add_embedding_length (self .hparams ["d_model" ]) 30self .gguf_writer .add_block_count (self .block_count ) 31self .gguf_writer .add_feed_forward_length (4 * self .hparams ["d_model" ]) 32self .gguf_writer .add_head_count (self .hparams ["n_heads" ]) 33if kv_n_heads := self .hparams ["attn_config" ].get ("kv_n_heads" ): 34self .gguf_writer .add_head_count_kv (kv_n_heads ) 35self .gguf_writer .add_layer_norm_eps (1e-5 ) 36if self .hparams ["attn_config" ]["clip_qkv" ]is not None : 37self .gguf_writer .add_clamp_kqv (self .hparams ["attn_config" ]["clip_qkv" ]) 38if self .hparams ["attn_config" ]["alibi" ]: 39self .gguf_writer .add_max_alibi_bias (self .hparams ["attn_config" ]["alibi_bias_max" ]) 40else : 41self .gguf_writer .add_max_alibi_bias (0.0 ) 42 43def modify_tensors (self ,data_torch :Tensor ,name :str ,bid :int | None )-> Iterable [tuple [str ,Tensor ]]: 44if "scales" in name : 45new_name = self .map_tensor_name (name ,try_suffixes = (".weight" ,".bias" ,".scales" )) 46new_name = new_name .replace ("scales" ,"act.scales" ) 47else : 48new_name = self .map_tensor_name (name ,try_suffixes = (".weight" ,".bias" )) 49 50yield from super ().modify_tensors (data_torch ,new_name ,bid )