Skip to content

Commit

Permalink
convert : add BertForMaskedLM (ggerganov#10919)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggerganov authored Dec 21, 2024
1 parent a91a413 commit 5cd85b5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion convert_hf_to_gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2628,7 +2628,7 @@ def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iter
return [(self.map_tensor_name(name), data_torch)]


@Model.register("BertModel", "CamembertModel")
@Model.register("BertModel", "BertForMaskedLM", "CamembertModel")
class BertModel(Model):
model_arch = gguf.MODEL_ARCH.BERT

Expand Down Expand Up @@ -2694,10 +2694,25 @@ def phantom(tok):
def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iterable[tuple[str, Tensor]]:
del bid # unused

if name.startswith("bert."):
name = name[5:]

if name.endswith(".gamma"):
name = name[:-6] + ".weight"

if name.endswith(".beta"):
name = name[:-5] + ".bias"

# we are only using BERT for embeddings so we don't need the pooling layer
if name in ("embeddings.position_ids", "pooler.dense.weight", "pooler.dense.bias"):
return [] # we don't need these

if name.startswith("cls.predictions"):
return []

if name.startswith("cls.seq_relationship"):
return []

return [(self.map_tensor_name(name), data_torch)]


Expand Down

0 comments on commit 5cd85b5

Please sign in to comment.