Repository: facebookresearch/fairseq

Issue:
Error in fairseq/data.py
Excuse me. I got an error when I pull the new repository

Can anyone help me?


```
Traceback (most recent call last):
  File "pretrain_discriminator.py", line 11, in <module>
    from gan import trainer
  File "/home/playma/Research/fairseq-py/gan/trainer.py", line 1, in <module>
    from fairseq import data, utils
  File "/home/playma/Research/fairseq-py/fairseq/data.py", line 24
    if len(glob.glob(os.path.join(data_dir, f'{split}.*-*.*.bin'))) < 2:
                                                               ^
SyntaxError: invalid syntax
```


Discussion:
Ah, it's using the new string format syntax introduced in Python 3.6 [1]. I'll revert that.

[1] https://docs.python.org/3/whatsnew/3.6.html#pep-498-formatted-string-literals
Thanks 

Resolving patch:
diff --git a/fairseq/data.py b/fairseq/data.py
--- a/fairseq/data.py
+++ b/fairseq/data.py
@@ -21,7 +21,7 @@
 
 def has_binary_files(data_dir, splits):
     for split in splits:
-        if len(glob.glob(os.path.join(data_dir, f'{split}.*-*.*.bin'))) < 2:
+        if len(glob.glob(os.path.join(data_dir, '{}.*-*.*.bin'.format(split)))) < 2:
             return False
     return True
 
@@ -107,8 +107,8 @@ def load_raw_text_dataset(path, load_splits, src=None, dst=None):
 
     # Load dataset from raw text files
     for split in load_splits:
-        src_path = os.path.join(path, f'{split}.{src}')
-        dst_path = os.path.join(path, f'{split}.{dst}')
+        src_path = os.path.join(path, '{}.{}'.format(split, src))
+        dst_path = os.path.join(path, '{}.{}'.format(split, dst))
         dataset.splits[split] = LanguagePairDataset(
             IndexedRawTextDataset(src_path, src_dict),
             IndexedRawTextDataset(dst_path, dst_dict),
diff --git a/fairseq/progress_bar.py b/fairseq/progress_bar.py
--- a/fairseq/progress_bar.py
+++ b/fairseq/progress_bar.py
@@ -27,9 +27,9 @@ def __init__(self, iterable, epoch=None, prefix=None):
         self.epoch = epoch
         self.prefix = ''
         if epoch is not None:
-            self.prefix += f'| epoch {epoch:03d}'
+            self.prefix += '| epoch {:03d}'.format(epoch)
         if prefix is not None:
-            self.prefix += f' | {prefix}'
+            self.prefix += ' | {}'.format(prefix)
 
     def __enter__(self):
         return self
@@ -90,7 +90,7 @@ def __iter__(self):
                     self.log_interval is not None and i % self.log_interval == 0:
                 update = self.epoch + float(i / size) if self.epoch is not None else None
                 stats = self._format_stats(self.stats, epoch=self.epoch, update=update)
-                print("sweep_log: " + json.dumps(stats), flush=True)
+                print('sweep_log: ' + json.dumps(stats), flush=True)
 
     def log(self, stats):
         """Log intermediate stats according to log_interval."""
@@ -152,7 +152,8 @@ def __iter__(self):
             if self.stats is not None and i > 0 and \
                     self.log_interval is not None and i % self.log_interval == 0:
                 postfix = self._str_commas(self.stats)
-                print(f'{self.prefix}:  {i:5d} / {size:d} {postfix}', flush=True)
+                print('{}:  {:5d} / {:d} {}'.format(self.prefix, i, size, postfix),
+                      flush=True)
 
     def log(self, stats):
         """Log intermediate stats according to log_interval."""
@@ -161,7 +162,7 @@ def log(self, stats):
     def print(self, stats):
         """Print end-of-epoch stats."""
         postfix = self._str_pipes(self._format_stats(stats))
-        print(f'{self.prefix} | {postfix}', flush=True)
+        print('{} | {}'.format(self.prefix, postfix), flush=True)
 
 
 class tqdm_progress_bar(progress_bar):
@@ -181,4 +182,4 @@ def log(self, stats):
     def print(self, stats):
         """Print end-of-epoch stats."""
         postfix = self._str_pipes(self._format_stats(stats))
-        self.tqdm.write(f'{self.tqdm.desc} | {postfix}')
+        self.tqdm.write('{} | {}'.format(self.tqdm.desc, postfix))


Test patch: