Skip to content

Commit

Permalink
convert-hf : do not use model name to distinguish Phi-4 from Phi-3
Browse files Browse the repository at this point in the history
  • Loading branch information
sszymczy committed Dec 14, 2024
1 parent 7555ab1 commit 520e8a0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions convert_hf_to_gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2129,8 +2129,14 @@ class Phi3MiniModel(Model):
model_arch = gguf.MODEL_ARCH.PHI3

def set_vocab(self):
if self.metadata.name == "Phi 4":
return self._set_vocab_gpt2()
# Phi-4 model uses GPT2Tokenizer
tokenizer_config_file = self.dir_model / 'tokenizer_config.json'
if tokenizer_config_file.is_file():
with open(tokenizer_config_file, "r", encoding="utf-8") as f:
tokenizer_config_json = json.load(f)
tokenizer_class = tokenizer_config_json['tokenizer_class']
if tokenizer_class == 'GPT2Tokenizer':
return self._set_vocab_gpt2()

from sentencepiece import SentencePieceProcessor

Expand Down Expand Up @@ -2248,8 +2254,9 @@ def set_gguf_parameters(self):
self.gguf_writer.add_rope_dimension_count(rope_dims)
self.gguf_writer.add_rope_freq_base(self.find_hparam(["rope_theta"]))
self.gguf_writer.add_file_type(self.ftype)
if self.metadata.name != "Phi 4":
self.gguf_writer.add_sliding_window(self.find_hparam(["sliding_window"]))
# handle null value of sliding_window (Phi-4 model)
if (sliding_window := self.hparams.get("sliding_window")) is not None:
self.gguf_writer.add_sliding_window(sliding_window)

def generate_extra_tensors(self) -> Iterable[tuple[str, Tensor]]:
n_embd = self.find_hparam(["hidden_size", "n_embd"])
Expand Down

0 comments on commit 520e8a0

Please sign in to comment.