Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Converting FARM classification model to hugging face model #553

@Ganeshpadmanaban

Description

@Ganeshpadmanaban

Describe the bug
I'm not able to save a trained farm-classification model to hugging face format since I want to move to the other framework for more specific operations.

Error message

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-83-b2a730b6ac24> in <module>
----> 1 convert_to_transformers()

<ipython-input-82-8ab35f02f804> in convert_to_transformers()
     12 
     13     # convert to transformers
---> 14     transformer_model = model.convert_to_transformers()
     15 
     16     # save it (note: transformers use str instead of Path objects)

    555             setattr(transformers_model, transformers_model.base_model_prefix, self.language_model.model)
    556             transformers_model.classifier.load_state_dict(
--> 557                 self.prediction_heads[0].feed_forward.feed_forward[0].state_dict())
    558         elif self.prediction_heads[0].model_type == "token_classification":
    559             # add more info to config

   1043         if len(error_msgs) > 0:
   1044             raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
-> 1045                                self.__class__.__name__, "\n\t".join(error_msgs)))
   1046         return _IncompatibleKeys(missing_keys, unexpected_keys)
   1047 

RuntimeError: Error(s) in loading state_dict for Linear:
	size mismatch for weight: copying a param with shape torch.Size([2, 768]) from checkpoint, the shape in current model is torch.Size([2, 4096]).

To Reproduce

System:

  • OS: Ubuntu 18.04
  • GPU/CPU: i7
  • FARM version: 0.4.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions