[Python] ValueError: Unrecognized model in ./MRPC/. Should have a `model_type` key in its...

Discussão em 'Python' iniciado por Stack, Julho 4, 2025.

  1. Stack

    Stack Membro Participativo

    Goal: Amend this Notebook to work with Albert and Distilbert models

    Kernel: conda_pytorch_p36. I did Restart & Run All, and refreshed file view in working directory.

    Error occurs in Section 1.2, only for these 2 new models.

    For filenames etc., I've created a variable used everywhere:

    MODEL_NAME = 'albert-base-v2' # 'distilbert-base-uncased', 'bert-base-uncased'


    I replaced imports with:

    from transformers import (AutoConfig, AutoModel, AutoTokenizer)
    #from transformers import (BertConfig, BertForSequenceClassification, BertTokenizer,)


    As suggested in Transformers Documentation - Auto Classes.


    Instantiating one of AutoConfig, AutoModel, and AutoTokenizer will directly create a class of the relevant architecture.
    ​

    Section 1.2:

    # load model
    model = AutoModel.from_pretrained(configs.output_dir) # BertForSequenceClassification
    model.to(configs.device)


    # quantize model
    quantized_model = torch.quantization.quantize_dynamic(
    model, {torch.nn.Linear}, dtype=torch.qint8
    )

    #print(quantized_model)

    def print_size_of_model(model):
    torch.save(model.state_dict(), "temp.p")
    print('Size (MB):', os.path.getsize("temp.p")/(1024*1024))
    os.remove('temp.p')

    print_size_of_model(model)
    print_size_of_model(quantized_model)


    Traceback:

    ValueError: Unrecognized model in ./MRPC/. Should have a `model_type` key in its config.json, or contain one of the following strings in its name: imagegpt, qdqbert, vision-encoder-decoder, trocr, fnet, segformer, vision-text-dual-encoder, perceiver, gptj, layoutlmv2, beit, rembert, visual_bert, canine, roformer, clip, bigbird_pegasus, deit, luke, detr, gpt_neo, big_bird, speech_to_text_2, speech_to_text, vit, wav2vec2, m2m_100, convbert, led, blenderbot-small, retribert, ibert, mt5, t5, mobilebert, distilbert, albert, bert-generation, camembert, xlm-roberta, pegasus, marian, mbart, megatron-bert, mpnet, bart, blenderbot, reformer, longformer, roberta, deberta-v2, deberta, flaubert, fsmt, squeezebert, hubert, bert, openai-gpt, gpt2, transfo-xl, xlnet, xlm-prophetnet, prophetnet, xlm, ctrl, electra, speech-encoder-decoder, encoder-decoder, funnel, lxmert, dpr, layoutlm, rag, tapas, splinter, sew-d, sew, unispeech-sat, unispeech, wavlm


    Please let me know if there's anything else I can add to post.

    Continue reading...

Compartilhe esta Página