transformers icon indicating copy to clipboard operation
transformers copied to clipboard

GGUF support for BERT architecture

Open Dimmension opened this issue 1 year ago • 1 comments

Feature request

I want to add the ability to use GGUF BERT models in transformers. Currently the library does not support this architecture. When I try to load it, I get an error TypeError: Architecture 'bert' is not supported. I have done most of the mapping, with some fields I am having difficulty. Can anybody help me and provide comments on this feature?

Motivation

I ran into a problem that I can't use gguf models in RASA(rasa uses standard from_pretrained). So I decided to make BERT support

Your contribution

That's my extended ggml.py file

GGUF_TENSOR_MAPPING = {
    "bert": {
        "context_length": "max_position_embeddings",
        "block_count": "num_hidden_layers",
        "feed_forward_length": "intermediate_size",
        "embedding_length": "hidden_size",
        "attention.head_cgguf>=0.10.0ount": "num_attention_heads",
        "attention.layer_norm_rms_epsilon": "rms_norm_eps",
        # "attention.causal": "",
        # "pooling_type": "",
        "vocab_size": "vocab_size",
    }
}
 
GGUF_CONFIG_MAPPING = {
    "bert": {
        "context_length": "max_position_embeddings",
        "block_count": "num_hidden_layers",
        "feed_forward_length": "intermediate_size",
        "embedding_length": "hidden_size",
        "attention.head_cgguf>=0.10.0ount": "num_attention_heads",
        "attention.layer_norm_rms_epsilon": "rms_norm_eps",
        # "attention.causal": "",
        # "pooling_type": "",
        "vocab_size": "vocab_size",
    }
}
 
GGUF_TOKENIZER_MAPPING = {
    "tokenizer": {
        # "ggml.token_type_count": "",
        # "ggml.pre": "",
        "ggml.model": "tokenizer_type",
        "ggml.tokens": "all_special_tokens",
        "ggml.token_type": "all_special_ids",
        "ggml.unknown_token_id": "unk_token_id",
        "ggml.seperator_token_id": "sep_token_id",
        "ggml.padding_token_id": "pad_token_id",
        "ggml.cls_token_id": "cls_token_id",
        "ggml.mask_token_id": "mask_token_id",
    },
    "tokenizer_config": {       
        "ggml.unknown_token_id": "unk_token_id",
        "ggml.seperator_token_id": "sep_token_id",
        "ggml.padding_token_id": "pad_token_id",
        "ggml.cls_token_id": "cls_token_id",
        "ggml.mask_token_id": "mask_token_id",
    },
}

Dimmension avatar Oct 18 '24 08:10 Dimmension