Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions convert_hf_to_gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3690,14 +3690,20 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.vocab_size = None

if cls_out_labels := self.hparams.get("id2label"):
if len(cls_out_labels) == 2 and cls_out_labels[0] == "LABEL_0":
# Remove dummy labels added by AutoConfig
cls_out_labels = None
self.cls_out_labels = cls_out_labels

def set_gguf_parameters(self):
super().set_gguf_parameters()
self.gguf_writer.add_causal_attention(False)
self._try_set_pooling_type()

if cls_out_labels := self.hparams.get("id2label"):
if self.cls_out_labels:
key_name = gguf.Keys.Classifier.OUTPUT_LABELS.format(arch = gguf.MODEL_ARCH_NAMES[self.model_arch])
self.gguf_writer.add_array(key_name, [v for k, v in sorted(cls_out_labels.items())])
self.gguf_writer.add_array(key_name, [v for k, v in sorted(self.cls_out_labels.items())])

def set_vocab(self):
tokens, toktypes, tokpre = self.get_vocab_base()
Expand Down Expand Up @@ -3749,7 +3755,7 @@ def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iter
if name.startswith("cls.seq_relationship"):
return []

if self.hparams.get("id2label"):
if self.cls_out_labels:
# For BertForSequenceClassification (direct projection layer)
if name == "classifier.weight":
name = "classifier.out_proj.weight"
Expand Down