We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
BERT classifier doesn't work under distributed_train
The default tokenization is re, I think it's building the dictionary along the way...

**Logs**
Please paste the command line output:

```
ValueError: Dictionaries should be pre-built before distributed train.
ValueError: Dictionaries should be pre-built before distributed train.
```



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `parlai/agents/bert_ranker/bert_dictionary.py`
Content:
```
1 #!/usr/bin/env python3
2 
3 # Copyright (c) Facebook, Inc. and its affiliates.
4 # This source code is licensed under the MIT license found in the
5 # LICENSE file in the root directory of this source tree.
6 from parlai.core.dict import DictionaryAgent
7 from parlai.zoo.bert.build import download
8 from parlai.utils.misc import warn_once
9 
10 try:
11     from pytorch_pretrained_bert import BertTokenizer
12 except ImportError:
13     raise ImportError(
14         'BERT rankers needs pytorch-pretrained-BERT installed. \n '
15         'pip install pytorch-pretrained-bert'
16     )
17 from .helpers import VOCAB_PATH
18 
19 import os
20 
21 
22 class BertDictionaryAgent(DictionaryAgent):
23     """
24     Allow to use the Torch Agent with the wordpiece dictionary of Hugging Face.
25     """
26 
27     def __init__(self, opt):
28         super().__init__(opt)
29         # initialize from vocab path
30         warn_once(
31             'WARNING: BERT uses a Hugging Face tokenizer; ParlAI dictionary args are ignored'
32         )
33         download(opt['datapath'])
34         vocab_path = os.path.join(opt['datapath'], 'models', 'bert_models', VOCAB_PATH)
35         self.tokenizer = BertTokenizer.from_pretrained(vocab_path)
36 
37         self.start_token = '[CLS]'
38         self.end_token = '[SEP]'
39         self.null_token = '[PAD]'
40         self.start_idx = self.tokenizer.convert_tokens_to_ids(['[CLS]'])[
41             0
42         ]  # should be 101
43         self.end_idx = self.tokenizer.convert_tokens_to_ids(['[SEP]'])[
44             0
45         ]  # should be 102
46         self.pad_idx = self.tokenizer.convert_tokens_to_ids(['[PAD]'])[0]  # should be 0
47         # set tok2ind for special tokens
48         self.tok2ind[self.start_token] = self.start_idx
49         self.tok2ind[self.end_token] = self.end_idx
50         self.tok2ind[self.null_token] = self.pad_idx
51         # set ind2tok for special tokens
52         self.ind2tok[self.start_idx] = self.start_token
53         self.ind2tok[self.end_idx] = self.end_token
54         self.ind2tok[self.pad_idx] = self.null_token
55 
56     def txt2vec(self, text, vec_type=list):
57         tokens = self.tokenizer.tokenize(text)
58         tokens_id = self.tokenizer.convert_tokens_to_ids(tokens)
59         return tokens_id
60 
61     def vec2txt(self, vec):
62         if not isinstance(vec, list):
63             # assume tensor
64             idxs = [idx.item() for idx in vec.cpu()]
65         else:
66             idxs = vec
67         toks = self.tokenizer.convert_ids_to_tokens(idxs)
68         return ' '.join(toks)
69 
70     def act(self):
71         return {}
72
```
--- 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/parlai/agents/bert_ranker/bert_dictionary.py b/parlai/agents/bert_ranker/bert_dictionary.py
--- a/parlai/agents/bert_ranker/bert_dictionary.py
+++ b/parlai/agents/bert_ranker/bert_dictionary.py
@@ -24,6 +24,9 @@
     Allow to use the Torch Agent with the wordpiece dictionary of Hugging Face.
     """
 
+    def is_prebuit(self):
+        return True
+
     def __init__(self, opt):
         super().__init__(opt)
         # initialize from vocab path

{"golden_diff": "diff --git a/parlai/agents/bert_ranker/bert_dictionary.py b/parlai/agents/bert_ranker/bert_dictionary.py\n--- a/parlai/agents/bert_ranker/bert_dictionary.py\n+++ b/parlai/agents/bert_ranker/bert_dictionary.py\n@@ -24,6 +24,9 @@\n     Allow to use the Torch Agent with the wordpiece dictionary of Hugging Face.\n     \"\"\"\n \n+    def is_prebuit(self):\n+        return True\n+\n     def __init__(self, opt):\n         super().__init__(opt)\n         # initialize from vocab path\n", "issue": "BERT classifier doesn't work under distributed_train\nThe default tokenization is re, I think it's building the dictionary along the way...\r\n\r\n**Logs**\r\nPlease paste the command line output:\r\n\r\n```\r\nValueError: Dictionaries should be pre-built before distributed train.\r\nValueError: Dictionaries should be pre-built before distributed train.\r\n```\r\n\r\n\n", "before_files": [{"content": "#!/usr/bin/env python3\n\n# Copyright (c) Facebook, Inc. and its affiliates.\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\nfrom parlai.core.dict import DictionaryAgent\nfrom parlai.zoo.bert.build import download\nfrom parlai.utils.misc import warn_once\n\ntry:\n    from pytorch_pretrained_bert import BertTokenizer\nexcept ImportError:\n    raise ImportError(\n        'BERT rankers needs pytorch-pretrained-BERT installed. \\n '\n        'pip install pytorch-pretrained-bert'\n    )\nfrom .helpers import VOCAB_PATH\n\nimport os\n\n\nclass BertDictionaryAgent(DictionaryAgent):\n    \"\"\"\n    Allow to use the Torch Agent with the wordpiece dictionary of Hugging Face.\n    \"\"\"\n\n    def __init__(self, opt):\n        super().__init__(opt)\n        # initialize from vocab path\n        warn_once(\n            'WARNING: BERT uses a Hugging Face tokenizer; ParlAI dictionary args are ignored'\n        )\n        download(opt['datapath'])\n        vocab_path = os.path.join(opt['datapath'], 'models', 'bert_models', VOCAB_PATH)\n        self.tokenizer = BertTokenizer.from_pretrained(vocab_path)\n\n        self.start_token = '[CLS]'\n        self.end_token = '[SEP]'\n        self.null_token = '[PAD]'\n        self.start_idx = self.tokenizer.convert_tokens_to_ids(['[CLS]'])[\n            0\n        ]  # should be 101\n        self.end_idx = self.tokenizer.convert_tokens_to_ids(['[SEP]'])[\n            0\n        ]  # should be 102\n        self.pad_idx = self.tokenizer.convert_tokens_to_ids(['[PAD]'])[0]  # should be 0\n        # set tok2ind for special tokens\n        self.tok2ind[self.start_token] = self.start_idx\n        self.tok2ind[self.end_token] = self.end_idx\n        self.tok2ind[self.null_token] = self.pad_idx\n        # set ind2tok for special tokens\n        self.ind2tok[self.start_idx] = self.start_token\n        self.ind2tok[self.end_idx] = self.end_token\n        self.ind2tok[self.pad_idx] = self.null_token\n\n    def txt2vec(self, text, vec_type=list):\n        tokens = self.tokenizer.tokenize(text)\n        tokens_id = self.tokenizer.convert_tokens_to_ids(tokens)\n        return tokens_id\n\n    def vec2txt(self, vec):\n        if not isinstance(vec, list):\n            # assume tensor\n            idxs = [idx.item() for idx in vec.cpu()]\n        else:\n            idxs = vec\n        toks = self.tokenizer.convert_ids_to_tokens(idxs)\n        return ' '.join(toks)\n\n    def act(self):\n        return {}\n", "path": "parlai/agents/bert_ranker/bert_dictionary.py"}], "after_files": [{"content": "#!/usr/bin/env python3\n\n# Copyright (c) Facebook, Inc. and its affiliates.\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\nfrom parlai.core.dict import DictionaryAgent\nfrom parlai.zoo.bert.build import download\nfrom parlai.utils.misc import warn_once\n\ntry:\n    from pytorch_pretrained_bert import BertTokenizer\nexcept ImportError:\n    raise ImportError(\n        'BERT rankers needs pytorch-pretrained-BERT installed. \\n '\n        'pip install pytorch-pretrained-bert'\n    )\nfrom .helpers import VOCAB_PATH\n\nimport os\n\n\nclass BertDictionaryAgent(DictionaryAgent):\n    \"\"\"\n    Allow to use the Torch Agent with the wordpiece dictionary of Hugging Face.\n    \"\"\"\n\n    def is_prebuit(self):\n        return True\n\n    def __init__(self, opt):\n        super().__init__(opt)\n        # initialize from vocab path\n        warn_once(\n            'WARNING: BERT uses a Hugging Face tokenizer; ParlAI dictionary args are ignored'\n        )\n        download(opt['datapath'])\n        vocab_path = os.path.join(opt['datapath'], 'models', 'bert_models', VOCAB_PATH)\n        self.tokenizer = BertTokenizer.from_pretrained(vocab_path)\n\n        self.start_token = '[CLS]'\n        self.end_token = '[SEP]'\n        self.null_token = '[PAD]'\n        self.start_idx = self.tokenizer.convert_tokens_to_ids(['[CLS]'])[\n            0\n        ]  # should be 101\n        self.end_idx = self.tokenizer.convert_tokens_to_ids(['[SEP]'])[\n            0\n        ]  # should be 102\n        self.pad_idx = self.tokenizer.convert_tokens_to_ids(['[PAD]'])[0]  # should be 0\n        # set tok2ind for special tokens\n        self.tok2ind[self.start_token] = self.start_idx\n        self.tok2ind[self.end_token] = self.end_idx\n        self.tok2ind[self.null_token] = self.pad_idx\n        # set ind2tok for special tokens\n        self.ind2tok[self.start_idx] = self.start_token\n        self.ind2tok[self.end_idx] = self.end_token\n        self.ind2tok[self.pad_idx] = self.null_token\n\n    def txt2vec(self, text, vec_type=list):\n        tokens = self.tokenizer.tokenize(text)\n        tokens_id = self.tokenizer.convert_tokens_to_ids(tokens)\n        return tokens_id\n\n    def vec2txt(self, vec):\n        if not isinstance(vec, list):\n            # assume tensor\n            idxs = [idx.item() for idx in vec.cpu()]\n        else:\n            idxs = vec\n        toks = self.tokenizer.convert_ids_to_tokens(idxs)\n        return ' '.join(toks)\n\n    def act(self):\n        return {}\n", "path": "parlai/agents/bert_ranker/bert_dictionary.py"}]}