huggingface / transformers

šŸ¤— Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
135.62k stars 27.15k forks source link

numpy ndarray type is not allowed on process pytorch model #9248

Closed LoveMeWithoutAll closed 3 years ago

LoveMeWithoutAll commented 3 years ago

Environment info

Who can help

tensorflow: @jplu

Information

Model I am using (Bert, XLNet ...): Bert

The problem arises when using:

Changed 1 line that from_pt's default value from False to True((https://github.com/huggingface/transformers/blob/ec07da65e25562040581febaf9b400a462962961/src/transformers/modeling_tf_utils.py#L947))

The tasks I am working on is:

HuggingFace: monologg/kobert

I loaded my pertained pytorch model, and an error occurred on input_processing function

To reproduce

Steps to reproduce the behavior:

  1. run input_processing
  2. numpy ndarray is not allowed type(https://github.com/huggingface/transformers/blob/ec07da65e25562040581febaf9b400a462962961/src/transformers/modeling_tf_utils.py#L331)
  3. So ndarray cannot be processed(https://github.com/huggingface/transformers/blob/ec07da65e25562040581febaf9b400a462962961/src/transformers/modeling_tf_utils.py#L354)
  4. Of course there is not any proper changing for ndarray not as other types(dict, Tensor and etc)
  5. Error occurred like below
  File "/Users/ys/dev/rasa/venv/lib/python3.8/site-packages/transformers/modeling_tf_utils.py", line 357, in input_processing
    raise ValueError(f"Data of type {type(v)} is not allowed only {allowed_types} is accepted for {k}.")
ValueError: Data of type <class 'numpy.ndarray'> is not allowed only (<class 'tensorflow.python.framework.ops.Tensor'>, <class 'bool'>, <class 'int'>, <class 'transformers.file_utils.ModelOutput'>, <class 'tuple'>, <class 'list'>, <class 'dict'>) is accepted for attention_mask.

Expected behavior

Train success!

jplu commented 3 years ago

Hello!

Thanks for reporting this, we will apply a fix for the next release!

patrickvonplaten commented 3 years ago

@LoveMeWithoutAll thanks for issue!

Could you specific your use case here a bit? Do you want to convert a PyTorch model to a tensorflow model and consequently train the tensorflow model? Why do we need to forward ndarray types?

LoveMeWithoutAll commented 3 years ago

@patrickvonplaten Hello I'm using Rasa framework that embedding HuggingFace. Rasa is not yet support Pytorch model, so I must convert from Pytorch to TF model for using pre-trained model. Then ndarray is needed for convert model.

pranavpawar3 commented 3 years ago

@LoveMeWithoutAll Hi, I am also using the Rasa framework with HFTransformers and Language Models in pipeline config. Faced the same issue with the latest transformers, but it works with lower versions, transformers-2.9.0. I haven't tested out on other versions (probably some 3.x might work too!), but 2.9.0 shall work fine if your project setup allows lower version transformers.

LoveMeWithoutAll commented 3 years ago

@LoveMeWithoutAll Hi, I am also using the Rasa framework with HFTransformers and Language Models in pipeline config. Faced the same issue with the latest transformers, but it works with lower versions, transformers-2.9.0. I haven't tested out on other versions (probably some 3.x might work too!), but 2.9.0 shall work fine if your project setup allows lower version transformers.

thank you for your advice! i'll try it as you did

LysandreJik commented 3 years ago

This was fixed on master: https://github.com/huggingface/transformers/pull/9294

We'll release a new version tomorrow, which will benefit from this change. Thanks for reporting it!

LoveMeWithoutAll commented 3 years ago

Thank you for your effort!