Repository: huggingface/transformers

Issue:
pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py  error
attributeError: 'BertForPreTraining' object has no attribute 'global_step'


Discussion:
Maybe some additional information could help me help you?
Initialize PyTorch weight ['cls', 'seq_relationship', 'output_weights']
Skipping cls/seq_relationship/output_weights/adam_m
Skipping cls/seq_relationship/output_weights/adam_v
Traceback (most recent call last):
  File "/home/tiandan.cxj/python/model_serving_python/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/tiandan.cxj/python/model_serving_python/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/tiandan.cxj/platform/pytorch_BERT/pytorch-pretrained-BERT/pytorch_pretrained_bert/__main__.py", line 19, in <module>
    convert_tf_checkpoint_to_pytorch(TF_CHECKPOINT, TF_CONFIG, PYTORCH_DUMP_OUTPUT)
  File "/home/tiandan.cxj/platform/pytorch_BERT/pytorch-pretrained-BERT/pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py", line 69, in convert_tf_checkpoint_to_pytorch
    pointer = getattr(pointer, l[0])
  File "/home/tiandan.cxj/python/model_serving_python/lib/python3.5/site-packages/torch/nn/modules/module.py", line 518, in __getattr__
    type(self).__name__, name))
AttributeError: 'BertForPreTraining' object has no attribute 'global_step'
Hum I will see if I can let people import any kind of TF model in PyTorch, that's a bit risky so it has to be done properly.
In the meantime you can add `global_step` in the list line 53 of `convert_tf_checkpoint_to_pytorch.py`
@thomwolf  sir, i am also same issue. it doen't resolve. how i am convert my finetuned pretrained model to pytorch?

```
export BERT_BASE_DIR=/home/dell/backup/NWP/bert-base-uncased/bert_tensorflow_e100

pytorch_pretrained_bert convert_tf_checkpoint_to_pytorch \
  $BERT_BASE_DIR/model.ckpt-100 \
  $BERT_BASE_DIR/bert_config.json \
  $BERT_BASE_DIR/pytorch_model.bin

```

```
Traceback (most recent call last):
  File "/home/dell/Downloads/Downloads/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/dell/Downloads/Downloads/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/dell/backup/bert_env/lib/python3.6/site-packages/pytorch_pretrained_bert/__main__.py", line 19, in <module>
    convert_tf_checkpoint_to_pytorch(TF_CHECKPOINT, TF_CONFIG, PYTORCH_DUMP_OUTPUT)
  File "/home/dell/backup/bert_env/lib/python3.6/site-packages/pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py", line 69, in convert_tf_checkpoint_to_pytorch
    pointer = getattr(pointer, l[0])
  File "/home/dell/backup/bert_env/lib/python3.6/site-packages/torch/nn/modules/module.py", line 535, in __getattr__
    type(self).__name__, name))
AttributeError: 'BertForPreTraining' object has no attribute 'global_step'
```
sir how to resolve this issue?
thanks.

thanks @thomwolf  sir. it was resolved.

Resolving patch:
diff --git a/pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py b/pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py
--- a/pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py
+++ b/pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py
@@ -50,7 +50,7 @@ def convert_tf_checkpoint_to_pytorch(tf_checkpoint_path, bert_config_file, pytor
         name = name.split('/')
         # adam_v and adam_m are variables used in AdamWeightDecayOptimizer to calculated m and v
         # which are not required for using pretrained model
-        if any(n in ["adam_v", "adam_m"] for n in name):
+        if any(n in ["adam_v", "adam_m", "global_step"] for n in name):
             print("Skipping {}".format("/".join(name)))
             continue
         pointer = model


Test patch: