We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py  error
attributeError: 'BertForPreTraining' object has no attribute 'global_step'

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py`
Content:
```
1 # coding=utf-8
2 # Copyright 2018 The HugginFace Inc. team.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 """Convert BERT checkpoint."""
16 
17 from __future__ import absolute_import
18 from __future__ import division
19 from __future__ import print_function
20 
21 import os
22 import re
23 import argparse
24 import tensorflow as tf
25 import torch
26 import numpy as np
27 
28 from .modeling import BertConfig, BertForPreTraining
29 
30 def convert_tf_checkpoint_to_pytorch(tf_checkpoint_path, bert_config_file, pytorch_dump_path):
31     config_path = os.path.abspath(bert_config_file)
32     tf_path = os.path.abspath(tf_checkpoint_path)
33     print("Converting TensorFlow checkpoint from {} with config at {}".format(tf_path, config_path))
34     # Load weights from TF model
35     init_vars = tf.train.list_variables(tf_path)
36     names = []
37     arrays = []
38     for name, shape in init_vars:
39         print("Loading TF weight {} with shape {}".format(name, shape))
40         array = tf.train.load_variable(tf_path, name)
41         names.append(name)
42         arrays.append(array)
43 
44     # Initialise PyTorch model
45     config = BertConfig.from_json_file(bert_config_file)
46     print("Building PyTorch model from configuration: {}".format(str(config)))
47     model = BertForPreTraining(config)
48 
49     for name, array in zip(names, arrays):
50         name = name.split('/')
51         # adam_v and adam_m are variables used in AdamWeightDecayOptimizer to calculated m and v
52         # which are not required for using pretrained model
53         if any(n in ["adam_v", "adam_m"] for n in name):
54             print("Skipping {}".format("/".join(name)))
55             continue
56         pointer = model
57         for m_name in name:
58             if re.fullmatch(r'[A-Za-z]+_\d+', m_name):
59                 l = re.split(r'_(\d+)', m_name)
60             else:
61                 l = [m_name]
62             if l[0] == 'kernel' or l[0] == 'gamma':
63                 pointer = getattr(pointer, 'weight')
64             elif l[0] == 'output_bias' or l[0] == 'beta':
65                 pointer = getattr(pointer, 'bias')
66             elif l[0] == 'output_weights':
67                 pointer = getattr(pointer, 'weight')
68             else:
69                 pointer = getattr(pointer, l[0])
70             if len(l) >= 2:
71                 num = int(l[1])
72                 pointer = pointer[num]
73         if m_name[-11:] == '_embeddings':
74             pointer = getattr(pointer, 'weight')
75         elif m_name == 'kernel':
76             array = np.transpose(array)
77         try:
78             assert pointer.shape == array.shape
79         except AssertionError as e:
80             e.args += (pointer.shape, array.shape)
81             raise
82         print("Initialize PyTorch weight {}".format(name))
83         pointer.data = torch.from_numpy(array)
84 
85     # Save pytorch-model
86     print("Save PyTorch model to {}".format(pytorch_dump_path))
87     torch.save(model.state_dict(), pytorch_dump_path)
88 
89 
90 if __name__ == "__main__":
91     parser = argparse.ArgumentParser()
92     ## Required parameters
93     parser.add_argument("--tf_checkpoint_path",
94                         default = None,
95                         type = str,
96                         required = True,
97                         help = "Path the TensorFlow checkpoint path.")
98     parser.add_argument("--bert_config_file",
99                         default = None,
100                         type = str,
101                         required = True,
102                         help = "The config json file corresponding to the pre-trained BERT model. \n"
103                             "This specifies the model architecture.")
104     parser.add_argument("--pytorch_dump_path",
105                         default = None,
106                         type = str,
107                         required = True,
108                         help = "Path to the output PyTorch model.")
109     args = parser.parse_args()
110     convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path,
111                                      args.bert_config_file,
112                                      args.pytorch_dump_path)
113
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
         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

{"golden_diff": "diff --git a/pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py b/pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py\n--- a/pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py\n+++ b/pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py\n@@ -50,7 +50,7 @@\n         name = name.split('/')\n         # adam_v and adam_m are variables used in AdamWeightDecayOptimizer to calculated m and v\n         # which are not required for using pretrained model\n-        if any(n in [\"adam_v\", \"adam_m\"] for n in name):\n+        if any(n in [\"adam_v\", \"adam_m\", \"global_step\"] for n in name):\n             print(\"Skipping {}\".format(\"/\".join(name)))\n             continue\n         pointer = model\n", "issue": "pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py  error\nattributeError: 'BertForPreTraining' object has no attribute 'global_step'\n", "before_files": [{"content": "# coding=utf-8\n# Copyright 2018 The HugginFace Inc. team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Convert BERT checkpoint.\"\"\"\n\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport os\nimport re\nimport argparse\nimport tensorflow as tf\nimport torch\nimport numpy as np\n\nfrom .modeling import BertConfig, BertForPreTraining\n\ndef convert_tf_checkpoint_to_pytorch(tf_checkpoint_path, bert_config_file, pytorch_dump_path):\n    config_path = os.path.abspath(bert_config_file)\n    tf_path = os.path.abspath(tf_checkpoint_path)\n    print(\"Converting TensorFlow checkpoint from {} with config at {}\".format(tf_path, config_path))\n    # Load weights from TF model\n    init_vars = tf.train.list_variables(tf_path)\n    names = []\n    arrays = []\n    for name, shape in init_vars:\n        print(\"Loading TF weight {} with shape {}\".format(name, shape))\n        array = tf.train.load_variable(tf_path, name)\n        names.append(name)\n        arrays.append(array)\n\n    # Initialise PyTorch model\n    config = BertConfig.from_json_file(bert_config_file)\n    print(\"Building PyTorch model from configuration: {}\".format(str(config)))\n    model = BertForPreTraining(config)\n\n    for name, array in zip(names, arrays):\n        name = name.split('/')\n        # adam_v and adam_m are variables used in AdamWeightDecayOptimizer to calculated m and v\n        # which are not required for using pretrained model\n        if any(n in [\"adam_v\", \"adam_m\"] for n in name):\n            print(\"Skipping {}\".format(\"/\".join(name)))\n            continue\n        pointer = model\n        for m_name in name:\n            if re.fullmatch(r'[A-Za-z]+_\\d+', m_name):\n                l = re.split(r'_(\\d+)', m_name)\n            else:\n                l = [m_name]\n            if l[0] == 'kernel' or l[0] == 'gamma':\n                pointer = getattr(pointer, 'weight')\n            elif l[0] == 'output_bias' or l[0] == 'beta':\n                pointer = getattr(pointer, 'bias')\n            elif l[0] == 'output_weights':\n                pointer = getattr(pointer, 'weight')\n            else:\n                pointer = getattr(pointer, l[0])\n            if len(l) >= 2:\n                num = int(l[1])\n                pointer = pointer[num]\n        if m_name[-11:] == '_embeddings':\n            pointer = getattr(pointer, 'weight')\n        elif m_name == 'kernel':\n            array = np.transpose(array)\n        try:\n            assert pointer.shape == array.shape\n        except AssertionError as e:\n            e.args += (pointer.shape, array.shape)\n            raise\n        print(\"Initialize PyTorch weight {}\".format(name))\n        pointer.data = torch.from_numpy(array)\n\n    # Save pytorch-model\n    print(\"Save PyTorch model to {}\".format(pytorch_dump_path))\n    torch.save(model.state_dict(), pytorch_dump_path)\n\n\nif __name__ == \"__main__\":\n    parser = argparse.ArgumentParser()\n    ## Required parameters\n    parser.add_argument(\"--tf_checkpoint_path\",\n                        default = None,\n                        type = str,\n                        required = True,\n                        help = \"Path the TensorFlow checkpoint path.\")\n    parser.add_argument(\"--bert_config_file\",\n                        default = None,\n                        type = str,\n                        required = True,\n                        help = \"The config json file corresponding to the pre-trained BERT model. \\n\"\n                            \"This specifies the model architecture.\")\n    parser.add_argument(\"--pytorch_dump_path\",\n                        default = None,\n                        type = str,\n                        required = True,\n                        help = \"Path to the output PyTorch model.\")\n    args = parser.parse_args()\n    convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path,\n                                     args.bert_config_file,\n                                     args.pytorch_dump_path)\n", "path": "pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py"}], "after_files": [{"content": "# coding=utf-8\n# Copyright 2018 The HugginFace Inc. team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Convert BERT checkpoint.\"\"\"\n\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport os\nimport re\nimport argparse\nimport tensorflow as tf\nimport torch\nimport numpy as np\n\nfrom .modeling import BertConfig, BertForPreTraining\n\ndef convert_tf_checkpoint_to_pytorch(tf_checkpoint_path, bert_config_file, pytorch_dump_path):\n    config_path = os.path.abspath(bert_config_file)\n    tf_path = os.path.abspath(tf_checkpoint_path)\n    print(\"Converting TensorFlow checkpoint from {} with config at {}\".format(tf_path, config_path))\n    # Load weights from TF model\n    init_vars = tf.train.list_variables(tf_path)\n    names = []\n    arrays = []\n    for name, shape in init_vars:\n        print(\"Loading TF weight {} with shape {}\".format(name, shape))\n        array = tf.train.load_variable(tf_path, name)\n        names.append(name)\n        arrays.append(array)\n\n    # Initialise PyTorch model\n    config = BertConfig.from_json_file(bert_config_file)\n    print(\"Building PyTorch model from configuration: {}\".format(str(config)))\n    model = BertForPreTraining(config)\n\n    for name, array in zip(names, arrays):\n        name = name.split('/')\n        # adam_v and adam_m are variables used in AdamWeightDecayOptimizer to calculated m and v\n        # which are not required for using pretrained model\n        if any(n in [\"adam_v\", \"adam_m\", \"global_step\"] for n in name):\n            print(\"Skipping {}\".format(\"/\".join(name)))\n            continue\n        pointer = model\n        for m_name in name:\n            if re.fullmatch(r'[A-Za-z]+_\\d+', m_name):\n                l = re.split(r'_(\\d+)', m_name)\n            else:\n                l = [m_name]\n            if l[0] == 'kernel' or l[0] == 'gamma':\n                pointer = getattr(pointer, 'weight')\n            elif l[0] == 'output_bias' or l[0] == 'beta':\n                pointer = getattr(pointer, 'bias')\n            elif l[0] == 'output_weights':\n                pointer = getattr(pointer, 'weight')\n            else:\n                pointer = getattr(pointer, l[0])\n            if len(l) >= 2:\n                num = int(l[1])\n                pointer = pointer[num]\n        if m_name[-11:] == '_embeddings':\n            pointer = getattr(pointer, 'weight')\n        elif m_name == 'kernel':\n            array = np.transpose(array)\n        try:\n            assert pointer.shape == array.shape\n        except AssertionError as e:\n            e.args += (pointer.shape, array.shape)\n            raise\n        print(\"Initialize PyTorch weight {}\".format(name))\n        pointer.data = torch.from_numpy(array)\n\n    # Save pytorch-model\n    print(\"Save PyTorch model to {}\".format(pytorch_dump_path))\n    torch.save(model.state_dict(), pytorch_dump_path)\n\n\nif __name__ == \"__main__\":\n    parser = argparse.ArgumentParser()\n    ## Required parameters\n    parser.add_argument(\"--tf_checkpoint_path\",\n                        default = None,\n                        type = str,\n                        required = True,\n                        help = \"Path the TensorFlow checkpoint path.\")\n    parser.add_argument(\"--bert_config_file\",\n                        default = None,\n                        type = str,\n                        required = True,\n                        help = \"The config json file corresponding to the pre-trained BERT model. \\n\"\n                            \"This specifies the model architecture.\")\n    parser.add_argument(\"--pytorch_dump_path\",\n                        default = None,\n                        type = str,\n                        required = True,\n                        help = \"Path to the output PyTorch model.\")\n    args = parser.parse_args()\n    convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path,\n                                     args.bert_config_file,\n                                     args.pytorch_dump_path)\n", "path": "pytorch_pretrained_bert/convert_tf_checkpoint_to_pytorch.py"}]}