AttributeError: 'BertForPreTraining' object has no attribute 'shape'
See original GitHub issueIs there any suggestion for fixing the following? I was trying “convert_tf_checkpoint_to_pytorch.py” to convert a model trained from scratch but the conversion didn’t work out…
Skipping cls/seq_relationship/output_weights/adam_v
Traceback (most recent call last):
File "pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py", line 66, in <module>
args.pytorch_dump_path)
File "pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py", line 37, in convert_tf_checkpoint_to_pytorch
load_tf_weights_in_bert(model, tf_checkpoint_path)
File "/content/my_pytorch-pretrained-BERT/pytorch_pretrained_bert/modeling.py", line 117, in load_tf_weights_in_bert
assert pointer.shape == array.shape
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 535, in __getattr__
type(self).__name__, name))
AttributeError: 'BertForPreTraining' object has no attribute 'shape'
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (2 by maintainers)
Top Results From Across the Web
Unable to load TF2-checkpoints into Huggingface
I get the error “AttributeError: 'BertForPreTraining' object has no attribute 'shape'”. I have tried both the “transformers-cli convert” ...
Read more >How to solve Attribute Error after running BERT model
Error I receive is AttributeError: 'str' object has no attribute 'shape'. The previous step before the code was creating a custom data ...
Read more >ckpt转bin模型报错解决:AttributeError: 'BertForPreTraining ...
ckpt转bin模型报错解决:AttributeError: 'BertForPreTraining' object has no attribute 'shape' #393.
Read more >attributeerror: 'dataloader' object has no attribute 'shape'
We are using Roboflow for object detection using Yolov4 Pytorch model for our custom data set. During the training process, we are getting...
Read more >Sentiment Analysis with BERT and Transformers by Hugging ...
While the original Transformer has an encoder (for reading the input) ... error "AttributeError: 'BertModel' object has no attribute 'bias'".
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’m getting a similar error when trying to convert the newer BERT models released at tensorflow/models/tree/master/official/nlp/.
These models are either BERT models trained with Keras or else checkpoints converted from the original google-research/bert repository. I also get the same error when I convert the TF1 to TF2 checkpoints myself using the tf2_encoder_checkpoint_converter.py script:
What I have tried:
First, I have downloaded a model:
After unpacking:
The command prints the configuration but throws the following error:
This is happening in a fresh environment with PyTorch 1.3 installed in Anaconda (Linux), as well as pip-installing
tf-nightlyandtransformers(2.3.0).Has anyone else been able to successfully convert the TF 2.0 version models to PyTorch or know where I’m going wrong? Thanks!
@thomwolf If the above fix will be added to the master branch this will be great https://github.com/smartshark/transformers/pull/1