Skip to content

Commit

Permalink
py : fix position embeddings chop [no ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
ggerganov committed Sep 17, 2024
1 parent fbbb64f commit a5307f5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions convert_hf_to_gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2701,16 +2701,16 @@ def set_vocab(self):
self.gguf_writer.add_add_eos_token(True)

def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iterable[tuple[str, Tensor]]:
# position embeddings start at pad_token_id + 1, so just chop down the weight tensor
if name == "embeddings.position_embeddings.weight":
if self._position_offset is not None:
data_torch = data_torch[self._position_offset:,:]

# if name starts with "roberta.", remove the prefix
# e.g. https://huggingface.co/BAAI/bge-reranker-v2-m3/tree/main
if name.startswith("roberta."):
name = name[8:]

# position embeddings start at pad_token_id + 1, so just chop down the weight tensor
if name == "embeddings.position_embeddings.weight":
if self._position_offset is not None:
data_torch = data_torch[self._position_offset:,:]

return super().modify_tensors(data_torch, name, bid)


Expand Down

0 comments on commit a5307f5

Please sign in to comment.