Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1from __future__ import annotations2 3from typing import Iterable, TYPE_CHECKING4 5if TYPE_CHECKING:6 from torch import Tensor7 8from .base import ModelBase, TextModel, gguf9 10 11@ModelBase.register("GPTRefactForCausalLM")12class RefactModel(TextModel):13 model_arch = gguf.MODEL_ARCH.REFACT14 15 def set_vocab(self):16 super().set_vocab()17 18 # TODO: how to determine special FIM tokens automatically?19 special_vocab = gguf.SpecialVocab(self.dir_model, load_merges=False,20 special_token_types = ['prefix', 'suffix', 'middle', 'eot'])21 special_vocab._set_special_token("prefix", 1)22 special_vocab._set_special_token("suffix", 3)23 special_vocab._set_special_token("middle", 2)24 special_vocab.chat_template = None # do not add it twice25 special_vocab.add_to_gguf(self.gguf_writer)26 27 def set_gguf_parameters(self):28 hidden_dim = self.hparams["n_embd"]29 inner_dim = 4 * hidden_dim30 hidden_dim = int(2 * inner_dim / 3)31 multiple_of = 25632 ff_dim = multiple_of * ((hidden_dim + multiple_of - 1) // multiple_of)33 34 # refact uses Alibi. So this is from config.json which might be used by training.35 self.gguf_writer.add_context_length(self.hparams["n_positions"])36 self.gguf_writer.add_embedding_length(self.hparams["n_embd"])37 38 self.gguf_writer.add_feed_forward_length(ff_dim)39 self.gguf_writer.add_block_count(self.block_count)40 self.gguf_writer.add_head_count(self.hparams["n_head"])41 self.gguf_writer.add_head_count_kv(1)42 self.gguf_writer.add_layer_norm_rms_eps(self.hparams["layer_norm_epsilon"])43 self.gguf_writer.add_file_type(self.ftype)44 45 def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iterable[tuple[str, Tensor]]:46 hidden_dim = self.hparams["n_embd"]47 inner_dim = 4 * hidden_dim48 hidden_dim = int(2 * inner_dim / 3)49 multiple_of = 25650 ff_dim = multiple_of * ((hidden_dim + multiple_of - 1) // multiple_of)51 n_head = self.hparams["n_head"]52 n_head_kv = 153 head_dim = self.hparams["n_embd"] // n_head54 55 if bid is not None:56 if name == f"transformer.h.{bid}.attn.kv.weight":57 yield from super().modify_tensors(data_torch[:n_head_kv * head_dim], self.format_tensor_name(gguf.MODEL_TENSOR.ATTN_K, bid), bid)58 yield from super().modify_tensors(data_torch[n_head_kv * head_dim:], self.format_tensor_name(gguf.MODEL_TENSOR.ATTN_V, bid), bid)59 return60 if name == f"transformer.h.{bid}.attn.q.weight":61 yield from super().modify_tensors(data_torch, self.format_tensor_name(gguf.MODEL_TENSOR.ATTN_Q, bid), bid)62 return63 if name == f"transformer.h.{bid}.mlp.gate_up_proj.weight":64 yield from super().modify_tensors(data_torch[:ff_dim], self.format_tensor_name(gguf.MODEL_TENSOR.FFN_GATE, bid), bid)65 yield from super().modify_tensors(data_torch[ff_dim:], self.format_tensor_name(gguf.MODEL_TENSOR.FFN_UP, bid), bid)66 return67 68 yield from super().modify_tensors(data_torch, name, bid)69 