We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
installation from source requires installing cffi
This is a very minor documentation issue
note: using python3/pip3 as there is a comment about requiring python 3 for fairseq-py
not using anaconda..I have had issues with package consistency..so I avoid it
fairseq-py installed with 
git clone https://github.com/facebookresearch/fairseq-py.git
sudo pip3 install -r requirements.txt 

levinth@zt-gpu-lin-1:~/fairseq-py$ sudo python3 setup.py build
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/torch/utils/ffi/__init__.py", line 12, in <module>
    import cffi
ImportError: No module named 'cffi'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 13, in <module>
    from torch.utils.ffi import create_extension
  File "/usr/local/lib/python3.5/dist-packages/torch/utils/ffi/__init__.py", line 14, in <module>
    raise ImportError("torch.utils.ffi requires the cffi package")
ImportError: torch.utils.ffi requires the cffi package
levinth@zt-gpu-lin-1:~/fairseq-py$ pip3 install cffi

and then the build worked
likely can be fixed by adding cffii to requirements.txt

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `fairseq/progress_bar.py`
Content:
```
1 # Copyright (c) 2017-present, Facebook, Inc.
2 # All rights reserved.
3 #
4 # This source code is licensed under the license found in the LICENSE file in
5 # the root directory of this source tree. An additional grant of patent rights
6 # can be found in the PATENTS file in the same directory.
7 #
8 
9 """
10 Wrapper around various loggers and progress bars (e.g., tqdm).
11 """
12 
13 from collections import OrderedDict
14 import json
15 from numbers import Number
16 import sys
17 
18 from tqdm import tqdm
19 
20 from fairseq.meters import AverageMeter
21 
22 
23 class progress_bar(object):
24     """Abstract class for progress bars."""
25     def __init__(self, iterable, epoch=None, prefix=None):
26         self.iterable = iterable
27         self.epoch = epoch
28         self.prefix = ''
29         if epoch is not None:
30             self.prefix += '| epoch {:03d}'.format(epoch)
31         if prefix is not None:
32             self.prefix += ' | {}'.format(prefix)
33 
34     def __enter__(self):
35         return self
36 
37     def __exit__(self, *exc):
38         return False
39 
40     def __iter__(self):
41         raise NotImplementedError
42 
43     def log(self, stats):
44         """Log intermediate stats according to log_interval."""
45         raise NotImplementedError
46 
47     def print(self, stats):
48         """Print end-of-epoch stats."""
49         raise NotImplementedError
50 
51     def _str_commas(self, stats):
52         return ', '.join(key + '=' + stats[key].strip()
53                          for key in stats.keys())
54 
55     def _str_pipes(self, stats):
56         return ' | '.join(key + ' ' + stats[key].strip()
57                           for key in stats.keys())
58 
59     def _format_stats(self, stats):
60         postfix = OrderedDict(stats)
61         # Preprocess stats according to datatype
62         for key in postfix.keys():
63             # Number: limit the length of the string
64             if isinstance(postfix[key], Number):
65                 postfix[key] = '{:g}'.format(postfix[key])
66             # Meter: display both current and average value
67             elif isinstance(postfix[key], AverageMeter):
68                 postfix[key] = '{:.2f} ({:.2f})'.format(
69                     postfix[key].val, postfix[key].avg)
70             # Else for any other type, try to get the string conversion
71             elif not isinstance(postfix[key], str):
72                 postfix[key] = str(postfix[key])
73             # Else if it's a string, don't need to preprocess anything
74         return postfix
75 
76 
77 class json_progress_bar(progress_bar):
78     """Log output in JSON format."""
79 
80     def __init__(self, iterable, epoch=None, prefix=None, log_interval=1000):
81         super().__init__(iterable, epoch, prefix)
82         self.log_interval = log_interval
83         self.stats = None
84 
85     def __iter__(self):
86         size = float(len(self.iterable))
87         for i, obj in enumerate(self.iterable):
88             yield obj
89             if self.stats is not None and i > 0 and \
90                     self.log_interval is not None and i % self.log_interval == 0:
91                 update = self.epoch + float(i / size) if self.epoch is not None else None
92                 stats = self._format_stats(self.stats, epoch=self.epoch, update=update)
93                 print('sweep_log: ' + json.dumps(stats), flush=True)
94 
95     def log(self, stats):
96         """Log intermediate stats according to log_interval."""
97         self.stats = stats
98 
99     def print(self, stats):
100         """Print end-of-epoch stats."""
101         stats = self._format_stats(self.stats, epoch=self.epoch)
102         print("sweep_log: " + json.dumps(stats), flush=True)
103 
104     def _format_stats(self, stats, epoch=None, update=None):
105         postfix = OrderedDict()
106         if epoch is not None:
107             postfix['epoch'] = epoch
108         if update is not None:
109             postfix['update'] = update
110         # Preprocess stats according to datatype
111         for key in stats.keys():
112             # Meter: display both current and average value
113             if isinstance(stats[key], AverageMeter):
114                 postfix[key] = stats[key].val
115                 postfix[key + '_avg'] = stats[key].avg
116             else:
117                 postfix[key] = stats[key]
118         return postfix
119 
120 
121 class noop_progress_bar(progress_bar):
122     """No logging."""
123 
124     def __init__(self, iterable, epoch=None, prefix=None):
125         super().__init__(iterable, epoch, prefix)
126 
127     def __iter__(self):
128         for obj in self.iterable:
129             yield obj
130 
131     def log(self, stats):
132         """Log intermediate stats according to log_interval."""
133         pass
134 
135     def print(self, stats):
136         """Print end-of-epoch stats."""
137         pass
138 
139 
140 class simple_progress_bar(progress_bar):
141     """A minimal logger for non-TTY environments."""
142 
143     def __init__(self, iterable, epoch=None, prefix=None, log_interval=1000):
144         super().__init__(iterable, epoch, prefix)
145         self.log_interval = log_interval
146         self.stats = None
147 
148     def __iter__(self):
149         size = len(self.iterable)
150         for i, obj in enumerate(self.iterable):
151             yield obj
152             if self.stats is not None and i > 0 and \
153                     self.log_interval is not None and i % self.log_interval == 0:
154                 postfix = self._str_commas(self.stats)
155                 print('{}:  {:5d} / {:d} {}'.format(self.prefix, i, size, postfix),
156                       flush=True)
157 
158     def log(self, stats):
159         """Log intermediate stats according to log_interval."""
160         self.stats = self._format_stats(stats)
161 
162     def print(self, stats):
163         """Print end-of-epoch stats."""
164         postfix = self._str_pipes(self._format_stats(stats))
165         print('{} | {}'.format(self.prefix, postfix), flush=True)
166 
167 
168 class tqdm_progress_bar(progress_bar):
169     """Log to tqdm."""
170 
171     def __init__(self, iterable, epoch=None, prefix=None):
172         super().__init__(iterable, epoch, prefix)
173         self.tqdm = tqdm(iterable, self.prefix, leave=False)
174 
175     def __iter__(self):
176         return iter(self.tqdm)
177 
178     def log(self, stats):
179         """Log intermediate stats according to log_interval."""
180         self.tqdm.set_postfix(self._format_stats(stats), refresh=False)
181 
182     def print(self, stats):
183         """Print end-of-epoch stats."""
184         postfix = self._str_pipes(self._format_stats(stats))
185         self.tqdm.write('{} | {}'.format(self.tqdm.desc, postfix))
186
```
--- 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/fairseq/progress_bar.py b/fairseq/progress_bar.py
--- a/fairseq/progress_bar.py
+++ b/fairseq/progress_bar.py
@@ -13,7 +13,6 @@
 from collections import OrderedDict
 import json
 from numbers import Number
-import sys
 
 from tqdm import tqdm

{"golden_diff": "diff --git a/fairseq/progress_bar.py b/fairseq/progress_bar.py\n--- a/fairseq/progress_bar.py\n+++ b/fairseq/progress_bar.py\n@@ -13,7 +13,6 @@\n from collections import OrderedDict\n import json\n from numbers import Number\n-import sys\n \n from tqdm import tqdm\n", "issue": "installation from source requires installing cffi\nThis is a very minor documentation issue\r\nnote: using python3/pip3 as there is a comment about requiring python 3 for fairseq-py\r\nnot using anaconda..I have had issues with package consistency..so I avoid it\r\nfairseq-py installed with \r\ngit clone https://github.com/facebookresearch/fairseq-py.git\r\nsudo pip3 install -r requirements.txt \r\n\r\nlevinth@zt-gpu-lin-1:~/fairseq-py$ sudo python3 setup.py build\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.5/dist-packages/torch/utils/ffi/__init__.py\", line 12, in <module>\r\n    import cffi\r\nImportError: No module named 'cffi'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"setup.py\", line 13, in <module>\r\n    from torch.utils.ffi import create_extension\r\n  File \"/usr/local/lib/python3.5/dist-packages/torch/utils/ffi/__init__.py\", line 14, in <module>\r\n    raise ImportError(\"torch.utils.ffi requires the cffi package\")\r\nImportError: torch.utils.ffi requires the cffi package\r\nlevinth@zt-gpu-lin-1:~/fairseq-py$ pip3 install cffi\r\n\r\nand then the build worked\r\nlikely can be fixed by adding cffii to requirements.txt\n", "before_files": [{"content": "# Copyright (c) 2017-present, Facebook, Inc.\n# All rights reserved.\n#\n# This source code is licensed under the license found in the LICENSE file in\n# the root directory of this source tree. An additional grant of patent rights\n# can be found in the PATENTS file in the same directory.\n#\n\n\"\"\"\nWrapper around various loggers and progress bars (e.g., tqdm).\n\"\"\"\n\nfrom collections import OrderedDict\nimport json\nfrom numbers import Number\nimport sys\n\nfrom tqdm import tqdm\n\nfrom fairseq.meters import AverageMeter\n\n\nclass progress_bar(object):\n    \"\"\"Abstract class for progress bars.\"\"\"\n    def __init__(self, iterable, epoch=None, prefix=None):\n        self.iterable = iterable\n        self.epoch = epoch\n        self.prefix = ''\n        if epoch is not None:\n            self.prefix += '| epoch {:03d}'.format(epoch)\n        if prefix is not None:\n            self.prefix += ' | {}'.format(prefix)\n\n    def __enter__(self):\n        return self\n\n    def __exit__(self, *exc):\n        return False\n\n    def __iter__(self):\n        raise NotImplementedError\n\n    def log(self, stats):\n        \"\"\"Log intermediate stats according to log_interval.\"\"\"\n        raise NotImplementedError\n\n    def print(self, stats):\n        \"\"\"Print end-of-epoch stats.\"\"\"\n        raise NotImplementedError\n\n    def _str_commas(self, stats):\n        return ', '.join(key + '=' + stats[key].strip()\n                         for key in stats.keys())\n\n    def _str_pipes(self, stats):\n        return ' | '.join(key + ' ' + stats[key].strip()\n                          for key in stats.keys())\n\n    def _format_stats(self, stats):\n        postfix = OrderedDict(stats)\n        # Preprocess stats according to datatype\n        for key in postfix.keys():\n            # Number: limit the length of the string\n            if isinstance(postfix[key], Number):\n                postfix[key] = '{:g}'.format(postfix[key])\n            # Meter: display both current and average value\n            elif isinstance(postfix[key], AverageMeter):\n                postfix[key] = '{:.2f} ({:.2f})'.format(\n                    postfix[key].val, postfix[key].avg)\n            # Else for any other type, try to get the string conversion\n            elif not isinstance(postfix[key], str):\n                postfix[key] = str(postfix[key])\n            # Else if it's a string, don't need to preprocess anything\n        return postfix\n\n\nclass json_progress_bar(progress_bar):\n    \"\"\"Log output in JSON format.\"\"\"\n\n    def __init__(self, iterable, epoch=None, prefix=None, log_interval=1000):\n        super().__init__(iterable, epoch, prefix)\n        self.log_interval = log_interval\n        self.stats = None\n\n    def __iter__(self):\n        size = float(len(self.iterable))\n        for i, obj in enumerate(self.iterable):\n            yield obj\n            if self.stats is not None and i > 0 and \\\n                    self.log_interval is not None and i % self.log_interval == 0:\n                update = self.epoch + float(i / size) if self.epoch is not None else None\n                stats = self._format_stats(self.stats, epoch=self.epoch, update=update)\n                print('sweep_log: ' + json.dumps(stats), flush=True)\n\n    def log(self, stats):\n        \"\"\"Log intermediate stats according to log_interval.\"\"\"\n        self.stats = stats\n\n    def print(self, stats):\n        \"\"\"Print end-of-epoch stats.\"\"\"\n        stats = self._format_stats(self.stats, epoch=self.epoch)\n        print(\"sweep_log: \" + json.dumps(stats), flush=True)\n\n    def _format_stats(self, stats, epoch=None, update=None):\n        postfix = OrderedDict()\n        if epoch is not None:\n            postfix['epoch'] = epoch\n        if update is not None:\n            postfix['update'] = update\n        # Preprocess stats according to datatype\n        for key in stats.keys():\n            # Meter: display both current and average value\n            if isinstance(stats[key], AverageMeter):\n                postfix[key] = stats[key].val\n                postfix[key + '_avg'] = stats[key].avg\n            else:\n                postfix[key] = stats[key]\n        return postfix\n\n\nclass noop_progress_bar(progress_bar):\n    \"\"\"No logging.\"\"\"\n\n    def __init__(self, iterable, epoch=None, prefix=None):\n        super().__init__(iterable, epoch, prefix)\n\n    def __iter__(self):\n        for obj in self.iterable:\n            yield obj\n\n    def log(self, stats):\n        \"\"\"Log intermediate stats according to log_interval.\"\"\"\n        pass\n\n    def print(self, stats):\n        \"\"\"Print end-of-epoch stats.\"\"\"\n        pass\n\n\nclass simple_progress_bar(progress_bar):\n    \"\"\"A minimal logger for non-TTY environments.\"\"\"\n\n    def __init__(self, iterable, epoch=None, prefix=None, log_interval=1000):\n        super().__init__(iterable, epoch, prefix)\n        self.log_interval = log_interval\n        self.stats = None\n\n    def __iter__(self):\n        size = len(self.iterable)\n        for i, obj in enumerate(self.iterable):\n            yield obj\n            if self.stats is not None and i > 0 and \\\n                    self.log_interval is not None and i % self.log_interval == 0:\n                postfix = self._str_commas(self.stats)\n                print('{}:  {:5d} / {:d} {}'.format(self.prefix, i, size, postfix),\n                      flush=True)\n\n    def log(self, stats):\n        \"\"\"Log intermediate stats according to log_interval.\"\"\"\n        self.stats = self._format_stats(stats)\n\n    def print(self, stats):\n        \"\"\"Print end-of-epoch stats.\"\"\"\n        postfix = self._str_pipes(self._format_stats(stats))\n        print('{} | {}'.format(self.prefix, postfix), flush=True)\n\n\nclass tqdm_progress_bar(progress_bar):\n    \"\"\"Log to tqdm.\"\"\"\n\n    def __init__(self, iterable, epoch=None, prefix=None):\n        super().__init__(iterable, epoch, prefix)\n        self.tqdm = tqdm(iterable, self.prefix, leave=False)\n\n    def __iter__(self):\n        return iter(self.tqdm)\n\n    def log(self, stats):\n        \"\"\"Log intermediate stats according to log_interval.\"\"\"\n        self.tqdm.set_postfix(self._format_stats(stats), refresh=False)\n\n    def print(self, stats):\n        \"\"\"Print end-of-epoch stats.\"\"\"\n        postfix = self._str_pipes(self._format_stats(stats))\n        self.tqdm.write('{} | {}'.format(self.tqdm.desc, postfix))\n", "path": "fairseq/progress_bar.py"}], "after_files": [{"content": "# Copyright (c) 2017-present, Facebook, Inc.\n# All rights reserved.\n#\n# This source code is licensed under the license found in the LICENSE file in\n# the root directory of this source tree. An additional grant of patent rights\n# can be found in the PATENTS file in the same directory.\n#\n\n\"\"\"\nWrapper around various loggers and progress bars (e.g., tqdm).\n\"\"\"\n\nfrom collections import OrderedDict\nimport json\nfrom numbers import Number\n\nfrom tqdm import tqdm\n\nfrom fairseq.meters import AverageMeter\n\n\nclass progress_bar(object):\n    \"\"\"Abstract class for progress bars.\"\"\"\n    def __init__(self, iterable, epoch=None, prefix=None):\n        self.iterable = iterable\n        self.epoch = epoch\n        self.prefix = ''\n        if epoch is not None:\n            self.prefix += '| epoch {:03d}'.format(epoch)\n        if prefix is not None:\n            self.prefix += ' | {}'.format(prefix)\n\n    def __enter__(self):\n        return self\n\n    def __exit__(self, *exc):\n        return False\n\n    def __iter__(self):\n        raise NotImplementedError\n\n    def log(self, stats):\n        \"\"\"Log intermediate stats according to log_interval.\"\"\"\n        raise NotImplementedError\n\n    def print(self, stats):\n        \"\"\"Print end-of-epoch stats.\"\"\"\n        raise NotImplementedError\n\n    def _str_commas(self, stats):\n        return ', '.join(key + '=' + stats[key].strip()\n                         for key in stats.keys())\n\n    def _str_pipes(self, stats):\n        return ' | '.join(key + ' ' + stats[key].strip()\n                          for key in stats.keys())\n\n    def _format_stats(self, stats):\n        postfix = OrderedDict(stats)\n        # Preprocess stats according to datatype\n        for key in postfix.keys():\n            # Number: limit the length of the string\n            if isinstance(postfix[key], Number):\n                postfix[key] = '{:g}'.format(postfix[key])\n            # Meter: display both current and average value\n            elif isinstance(postfix[key], AverageMeter):\n                postfix[key] = '{:.2f} ({:.2f})'.format(\n                    postfix[key].val, postfix[key].avg)\n            # Else for any other type, try to get the string conversion\n            elif not isinstance(postfix[key], str):\n                postfix[key] = str(postfix[key])\n            # Else if it's a string, don't need to preprocess anything\n        return postfix\n\n\nclass json_progress_bar(progress_bar):\n    \"\"\"Log output in JSON format.\"\"\"\n\n    def __init__(self, iterable, epoch=None, prefix=None, log_interval=1000):\n        super().__init__(iterable, epoch, prefix)\n        self.log_interval = log_interval\n        self.stats = None\n\n    def __iter__(self):\n        size = float(len(self.iterable))\n        for i, obj in enumerate(self.iterable):\n            yield obj\n            if self.stats is not None and i > 0 and \\\n                    self.log_interval is not None and i % self.log_interval == 0:\n                update = self.epoch + float(i / size) if self.epoch is not None else None\n                stats = self._format_stats(self.stats, epoch=self.epoch, update=update)\n                print('sweep_log: ' + json.dumps(stats), flush=True)\n\n    def log(self, stats):\n        \"\"\"Log intermediate stats according to log_interval.\"\"\"\n        self.stats = stats\n\n    def print(self, stats):\n        \"\"\"Print end-of-epoch stats.\"\"\"\n        stats = self._format_stats(self.stats, epoch=self.epoch)\n        print(\"sweep_log: \" + json.dumps(stats), flush=True)\n\n    def _format_stats(self, stats, epoch=None, update=None):\n        postfix = OrderedDict()\n        if epoch is not None:\n            postfix['epoch'] = epoch\n        if update is not None:\n            postfix['update'] = update\n        # Preprocess stats according to datatype\n        for key in stats.keys():\n            # Meter: display both current and average value\n            if isinstance(stats[key], AverageMeter):\n                postfix[key] = stats[key].val\n                postfix[key + '_avg'] = stats[key].avg\n            else:\n                postfix[key] = stats[key]\n        return postfix\n\n\nclass noop_progress_bar(progress_bar):\n    \"\"\"No logging.\"\"\"\n\n    def __init__(self, iterable, epoch=None, prefix=None):\n        super().__init__(iterable, epoch, prefix)\n\n    def __iter__(self):\n        for obj in self.iterable:\n            yield obj\n\n    def log(self, stats):\n        \"\"\"Log intermediate stats according to log_interval.\"\"\"\n        pass\n\n    def print(self, stats):\n        \"\"\"Print end-of-epoch stats.\"\"\"\n        pass\n\n\nclass simple_progress_bar(progress_bar):\n    \"\"\"A minimal logger for non-TTY environments.\"\"\"\n\n    def __init__(self, iterable, epoch=None, prefix=None, log_interval=1000):\n        super().__init__(iterable, epoch, prefix)\n        self.log_interval = log_interval\n        self.stats = None\n\n    def __iter__(self):\n        size = len(self.iterable)\n        for i, obj in enumerate(self.iterable):\n            yield obj\n            if self.stats is not None and i > 0 and \\\n                    self.log_interval is not None and i % self.log_interval == 0:\n                postfix = self._str_commas(self.stats)\n                print('{}:  {:5d} / {:d} {}'.format(self.prefix, i, size, postfix),\n                      flush=True)\n\n    def log(self, stats):\n        \"\"\"Log intermediate stats according to log_interval.\"\"\"\n        self.stats = self._format_stats(stats)\n\n    def print(self, stats):\n        \"\"\"Print end-of-epoch stats.\"\"\"\n        postfix = self._str_pipes(self._format_stats(stats))\n        print('{} | {}'.format(self.prefix, postfix), flush=True)\n\n\nclass tqdm_progress_bar(progress_bar):\n    \"\"\"Log to tqdm.\"\"\"\n\n    def __init__(self, iterable, epoch=None, prefix=None):\n        super().__init__(iterable, epoch, prefix)\n        self.tqdm = tqdm(iterable, self.prefix, leave=False)\n\n    def __iter__(self):\n        return iter(self.tqdm)\n\n    def log(self, stats):\n        \"\"\"Log intermediate stats according to log_interval.\"\"\"\n        self.tqdm.set_postfix(self._format_stats(stats), refresh=False)\n\n    def print(self, stats):\n        \"\"\"Print end-of-epoch stats.\"\"\"\n        postfix = self._str_pipes(self._format_stats(stats))\n        self.tqdm.write('{} | {}'.format(self.tqdm.desc, postfix))\n", "path": "fairseq/progress_bar.py"}]}