internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: facebookresearch/fairseq

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


Discussion:
cffi is a dependency for installing PyTorch from source [1] and they recommend installing the conda package (rather than the pip one), so we probably shouldn't additionally add the pip version to requirements.txt.

[1] https://github.com/pytorch/pytorch#from-source
Actually, the conda version seems to satisfy pip (i.e., it won't get installed twice), so it probably can't hurt to add it.

Resolving patch:
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
 


Test patch:
Repository: facebookresearch/fairseq

Issue:
Can't generate target sequence with more than 200 tokens
There is hardcoded (hidded) limit of maxlen=200 tokens in SequenceGenerator constructor that can't be increased in generate.py not interactive.py scripts.

It's strange since training with default parameters analyzes 1024 target positions.

Should we pass --max-target-positions value to SequenceGenerator constructor?

The limit can't be increased by --max-len-a and --max-len-b arguments. It can only be lowered per sentence which is understandable.

Does it make sense to maybe create new --max-sequence-len command line argument?


Discussion:
Good catch, we should adjust the default maxlen to be the decoder's max positions, rather than a fixed value of 200. Will submit a fix shortly.

Resolving patch:
diff --git a/fairseq/sequence_generator.py b/fairseq/sequence_generator.py
--- a/fairseq/sequence_generator.py
+++ b/fairseq/sequence_generator.py
@@ -17,7 +17,7 @@
 
 
 class SequenceGenerator(object):
-    def __init__(self, models, beam_size=1, minlen=1, maxlen=200,
+    def __init__(self, models, beam_size=1, minlen=1, maxlen=None,
                  stop_early=True, normalize_scores=True, len_penalty=1,
                  unk_penalty=0, retain_dropout=False):
         """Generates translations of a given source sentence.
@@ -40,7 +40,8 @@ def __init__(self, models, beam_size=1, minlen=1, maxlen=200,
         self.vocab_size = len(models[0].dst_dict)
         self.beam_size = beam_size
         self.minlen = minlen
-        self.maxlen = min(maxlen, *[m.max_decoder_positions() for m in self.models])
+        max_decoder_len = min([m.max_decoder_positions() for m in self.models])
+        self.maxlen = max_decoder_len if maxlen is None else min(maxlen, max_decoder_len)
         self.stop_early = stop_early
         self.normalize_scores = normalize_scores
         self.len_penalty = len_penalty


Test patch:
Repository: facebookresearch/fairseq

Issue:
Unable to run interactive.py for a pretrained model. 
When running the interactive.py script i run into the following error:

```python interactive.py  --path $MODEL_DIR/model.pt $MODEL_DIR  --beam 5
Namespace(beam=5, cpu=False, data='wmt14.en-fr.fconv-py', gen_subset='test', lenpen=1, log_format=None, log_interval=1000, max_len_a=0, max_len_b=200, max_sentences=None, max_source_positions=1024, max_target_positions=1024, max_tokens=6000, nbest=1, no_beamable_mm=False, no_early_stop=False, no_progress_bar=False, num_shards=1, path=['wmt14.en-fr.fconv-py/model.pt'], prefix_size=0, quiet=False, remove_bpe=None, replace_unk=None, sampling=False, score_reference=False, seed=1, shard_id=0, skip_invalid_size_inputs_valid_test=False, source_lang=None, target_lang=None, unkpen=0, unnormalized=False)
| loading model(s) from wmt14.en-fr.fconv-py/model.pt
Traceback (most recent call last):
  File "interactive.py", line 83, in <module>
    main(args)
  File "interactive.py", line 28, in main
    models, model_args = utils.load_ensemble_for_inference(args.path, data_dir=args.data)
  File "/workspace/fairseq/fairseq/utils.py", line 149, in load_ensemble_for_inference
    model = models.build_model(args, src_dict, dst_dict)
  File "/workspace/fairseq/fairseq/models/__init__.py", line 23, in build_model
    return ARCH_MODEL_REGISTRY[args.arch].build_model(args, src_dict, dst_dict)
  File "/workspace/fairseq/fairseq/models/fconv.py", line 62, in build_model
    if args.encoder_embed_path:
AttributeError: 'Namespace' object has no attribute 'encoder_embed_path'

Any idea on what I'm doing incorrectly?


Discussion:
I met the same question when running generate.py  on a pretrained model.

I found that https://github.com/pytorch/fairseq/pull/151 . 

When we trained the old model there was no parameter "encoder_embed_path".

Resolving patch:
diff --git a/fairseq/models/fconv.py b/fairseq/models/fconv.py
--- a/fairseq/models/fconv.py
+++ b/fairseq/models/fconv.py
@@ -57,6 +57,10 @@ def build_model(cls, args, src_dict, dst_dict):
             args.max_target_positions = args.max_positions
         if not hasattr(args, 'share_input_output_embed'):
             args.share_input_output_embed = False
+        if not hasattr(args, 'encoder_embed_path'):
+            args.encoder_embed_path = None
+        if not hasattr(args, 'decoder_embed_path'):
+            args.decoder_embed_path = None
 
         encoder_embed_dict = None
         if args.encoder_embed_path:
diff --git a/fairseq/models/lstm.py b/fairseq/models/lstm.py
--- a/fairseq/models/lstm.py
+++ b/fairseq/models/lstm.py
@@ -56,6 +56,10 @@ def add_args(parser):
     @classmethod
     def build_model(cls, args, src_dict, dst_dict):
         """Build a new model instance."""
+        if not hasattr(args, 'encoder_embed_path'):
+            args.encoder_embed_path = None
+        if not hasattr(args, 'decoder_embed_path'):
+            args.decoder_embed_path = None
 
         encoder_embed_dict = None
         if args.encoder_embed_path:


Test patch:
Repository: facebookresearch/fairseq

Issue:
Assertion Error in preprocessing of FAIR Sequence-to-Sequence Toolkit for Story Generation
when I run 
$ TEXT=examples/stories/writingPrompts
$ python preprocess.py --source-lang wp_source --target-lang wp_target \
  --trainpref $TEXT/train --validpref $TEXT/valid --testpref $TEXT/test \
  --destdir data-bin/writingPrompts --thresholdtgt 10 --thresholdsrc 10

I get an AssertionError:
Traceback (most recent call last):
  File "preprocess.py", line 201, in <module>
    main(args)
  File "preprocess.py", line 101, in main
    padding_factor=args.padding_factor,
  File "/home/username/workspace/benchmarking-tools/fairseq/fairseq/data/dictionary.py", line 137, in finalize
    assert len(new_count) == self.nspecial or min(new_count[self.nspecial:]) >= threshold
AssertionError

Upon inspection i see that min(new_count[self.nspecial:]) is 0


Discussion:

Resolving patch:
diff --git a/fairseq/data/dictionary.py b/fairseq/data/dictionary.py
--- a/fairseq/data/dictionary.py
+++ b/fairseq/data/dictionary.py
@@ -133,7 +133,6 @@ def finalize(self, threshold=-1, nwords=-1, padding_factor=8):
                 i += 1
                 threshold_nwords += 1
 
-        assert len(new_count) == self.nspecial or min(new_count[self.nspecial:]) >= threshold
         assert len(new_symbols) % padding_factor == 0
         assert len(new_symbols) == len(new_indices)
 


Test patch:
Repository: facebookresearch/fairseq

Issue:
Size Mismatch in AdaptiveSoftmax when targets are not specified
Following up on #212 , I'm updating `sequence_generator.py` to generate text from a pre-trained language model (initially trained with adaptive softmax). When computing log probabilities, and the targets are set to none, I receive a size mismatch exception in the line below, possibly because the dictionary size is smaller than the adaptive softmax cut-off: 

https://github.com/pytorch/fairseq/blob/388c520be21752cacb9fe3b1712038f32e0e9a5f/fairseq/modules/adaptive_softmax.py#L126

I imagine this could be solved by some sort of truncation to the output of tail[i].input


Discussion:
Why is the dictionary size smaller than the cutoff for adaptive softmax? Isn't the adaptive softmax cutoff's last bin value the size of the dictionary? 
I'm checking now, but I don't think this is the case, the last cut-off is an upper bound on the vocabulary size: https://github.com/pytorch/fairseq/blob/388c520be21752cacb9fe3b1712038f32e0e9a5f/fairseq/modules/adaptive_softmax.py#L23
@amrsharaf how come your dictionary is smaller than the adaptive softmax? its true that if you specify adaptive softmax cutoff of 500,000 and your vocab size is 5,000 then you will get an adaptive softmax of size 500k, where only the first 5k is useful. you can work around that by taking the first ```vocab_size``` columns from what is returned by adaptive softmax, but in general the idea was that you should create adaptive softmax cutoffs that are compatible with your vocab size. we can put some assert to make sure that vocab size is at least as big as the last specified cutoff
That's true, I should have made the max cut-off == vocab size, I just used the same hyperparameters from the wikitext README tutorial, it'd be helpful to add the assert statement or just an if statement like this: 

`if vocab_size < cutoff[-1]: cutoff[-1] = vocab_size`

Resolving patch:
diff --git a/fairseq/modules/adaptive_softmax.py b/fairseq/modules/adaptive_softmax.py
--- a/fairseq/modules/adaptive_softmax.py
+++ b/fairseq/modules/adaptive_softmax.py
@@ -22,6 +22,9 @@ def __init__(self, vocab_size, input_dim, cutoff, dropout):
 
         if vocab_size > cutoff[-1]:
             cutoff = cutoff + [vocab_size]
+        else:
+            assert vocab_size == cutoff[
+                -1], 'cannot specify cutoff smaller than vocab size'
 
         output_dim = cutoff[0] + len(cutoff) - 1
 


Test patch:
Repository: facebookresearch/fairseq

Issue:
Combine outputs of bidirectional encoder
It seems to me that the `view` method in the following function incorrectly mixes the outputs of different samples in a batch. In other words, I expect that `combine_bidir(outs)[:, 0, :].contiguous().view(-1)` to be exactly the same as `outs[:, 0, :].contiguous().view(-1)`. I tested the function with some random tensors and couldn't confirm it. Please let me know if something is wrong with my reasoning. Thank you.

https://github.com/pytorch/fairseq/blob/f7f2dd01ea141cc3303d6735e0fdcf8402b1557b/fairseq/models/lstm.py#L222-L231


Discussion:

Resolving patch:
diff --git a/fairseq/models/lstm.py b/fairseq/models/lstm.py
--- a/fairseq/models/lstm.py
+++ b/fairseq/models/lstm.py
@@ -222,10 +222,7 @@ def forward(self, src_tokens, src_lengths):
         if self.bidirectional:
 
             def combine_bidir(outs):
-                return torch.cat([
-                    torch.cat([outs[2 * i], outs[2 * i + 1]], dim=0).view(1, bsz, self.output_units)
-                    for i in range(self.num_layers)
-                ], dim=0)
+                return outs.view(self.num_layers, 2, bsz, -1).transpose(1, 2).contiguous().view(self.num_layers, bsz, -1)
 
             final_hiddens = combine_bidir(final_hiddens)
             final_cells = combine_bidir(final_cells)


Test patch:
Repository: facebookresearch/fairseq

Issue:
Uninitialised bias parameters in RelPositionMultiHeadedAttention
## 🐛 Bug

The (u, v) bias terms in the MHA layer with relative position encodings are defined using `torch.Tensor`s:
https://github.com/facebookresearch/fairseq/blob/4fe8583396191c22011350248119db98ec1b5cb8/fairseq/modules/espnet_multihead_attention.py#L127-L128

Since `torch.Tensor` creates an un-initialised tensor, its use results in non-deterministic behaviour, poor initialisation, and nans if you have an unlucky init:
```python
>>>import torch
>>> torch.Tensor(1, 1).sum()
tensor(0.)
>>> torch.Tensor(10, 10).sum()
tensor(4.9312e-38)
>>> torch.Tensor(100, 100).sum()
tensor(nan)
```
Section 3.3 of the referenced paper [Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context](https://arxiv.org/pdf/1901.02860.pdf) does not specify the initialisation for the bias terms. Since `torch.Tensor` is typically populated with zeros, setting the initialisation to `torch.zeros` should provide a fix that is close to the intended behaviour.



Discussion:

Resolving patch:
diff --git a/fairseq/modules/espnet_multihead_attention.py b/fairseq/modules/espnet_multihead_attention.py
--- a/fairseq/modules/espnet_multihead_attention.py
+++ b/fairseq/modules/espnet_multihead_attention.py
@@ -124,8 +124,8 @@ def __init__(self, n_feat, n_head, dropout, zero_triu=False):
         self.linear_pos = nn.Linear(n_feat, n_feat, bias=False)
         # these two learnable bias are used in matrix c and matrix d
         # as described in https://arxiv.org/abs/1901.02860 Section 3.3
-        self.pos_bias_u = nn.Parameter(torch.Tensor(self.h, self.d_k))
-        self.pos_bias_v = nn.Parameter(torch.Tensor(self.h, self.d_k))
+        self.pos_bias_u = nn.Parameter(torch.zeros(self.h, self.d_k))
+        self.pos_bias_v = nn.Parameter(torch.zeros(self.h, self.d_k))
         torch.nn.init.xavier_uniform_(self.pos_bias_u)
         torch.nn.init.xavier_uniform_(self.pos_bias_v)
 


Test patch:
Repository: facebookresearch/fairseq

Issue:
[fairseq] Guard call to `shape_as_tensor` with `is_in_onnx_export()`
This is a no-op in eager and in ONNX export, but it's better for other
tracers if this is preserved as shapes directly instead of converted to
a tensor.

There is a little annoying code duplication with
`torch.jit.is_scripting()`, which is unforunately necessary because we
didn't implement compile-time short circuiting correctly in TorchScript
lol.



Discussion:

Resolving patch:
diff --git a/fairseq/modules/sinusoidal_positional_embedding.py b/fairseq/modules/sinusoidal_positional_embedding.py
--- a/fairseq/modules/sinusoidal_positional_embedding.py
+++ b/fairseq/modules/sinusoidal_positional_embedding.py
@@ -97,7 +97,7 @@ def forward(
         if self.onnx_trace:
             flat_embeddings = self.weights.detach().index_select(0, positions.view(-1))
             embedding_shape = torch.cat(
-                (bsz.view(1), seq_len.view(1), torch.tensor([-1], dtype=torch.long))
+                (bsz, seq_len, torch.tensor([-1], dtype=torch.long))
             )
             embeddings = torch.onnx.operators.reshape_from_tensor_shape(
                 flat_embeddings, embedding_shape


Test patch:
Repository: facebookresearch/fairseq

Issue:
[fairseq] Guard call to `shape_as_tensor` with `is_in_onnx_export()`
This is a no-op in eager and in ONNX export, but it's better for other
tracers if this is preserved as shapes directly instead of converted to
a tensor.

There is a little annoying code duplication with
`torch.jit.is_scripting()`, which is unforunately necessary because we
didn't implement compile-time short circuiting correctly in TorchScript
lol.



Discussion:

Resolving patch:
diff --git a/fairseq/modules/sinusoidal_positional_embedding.py b/fairseq/modules/sinusoidal_positional_embedding.py
--- a/fairseq/modules/sinusoidal_positional_embedding.py
+++ b/fairseq/modules/sinusoidal_positional_embedding.py
@@ -65,12 +65,7 @@ def forward(
         positions: Optional[Any] = None,
     ):
         """Input is expected to be of size [bsz x seqlen]."""
-        if torch.jit.is_scripting():
-            bspair = torch.onnx.operators.shape_as_tensor(input)
-        elif torch.onnx.is_in_onnx_export():
-            bspair = torch.onnx.operators.shape_as_tensor(input)
-        else:
-            bspair = input.size()
+        bspair = torch.onnx.operators.shape_as_tensor(input)
         bsz, seq_len = bspair[0], bspair[1]
         max_pos = self.padding_idx + 1 + seq_len
         if self.weights is None or max_pos > self.weights.size(0):
@@ -97,7 +92,7 @@ def forward(
         if self.onnx_trace:
             flat_embeddings = self.weights.detach().index_select(0, positions.view(-1))
             embedding_shape = torch.cat(
-                (bsz, seq_len, torch.tensor([-1], dtype=torch.long))
+                (bsz.view(1), seq_len.view(1), torch.tensor([-1], dtype=torch.long))
             )
             embeddings = torch.onnx.operators.reshape_from_tensor_shape(
                 flat_embeddings, embedding_shape


Test patch:
Repository: facebookresearch/fairseq

Issue:
[MMS ASR] The doc for calc WER/CER can be unclear
As the doc says:

> $ ls /path/to/manifest
> dev.tsv
> dev.wrd
> dev.ltr
> dev.uid
> 
> \# dev.tsv each line contains <audio>  <number_of_sample>
> $ cat dev.tsv
> /
> /path/to/audio_1  180000
> /path/to/audio_2  200000
> 
> $ cat dev.ltr
> t h i s | i s | o n e |
> t h i s | i s | t w o |
> 
> $ cat dev.wrd
> this is one
> this is two
> 
> $ cat dev.uid
> audio_1
> audio_2

There are several points that can lead to misunderstanding. Is the  /path/to/audio_1 indicates a directory or a wav file? What does the number of samples mean? 


Discussion:

Resolving patch:
diff --git a/examples/mms/misc/get_sample_size.py b/examples/mms/misc/get_sample_size.py
new file mode 100644
--- /dev/null
+++ b/examples/mms/misc/get_sample_size.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python -u
+# Copyright (c) Facebook, Inc. and its affiliates.
+#
+# This source code is licensed under the MIT license found in the
+# LICENSE file in the root directory of this source tree.
+
+"""
+Usage:
+    $ python misc/get_sample_size.py <input_file> > <output_file>
+    
+    <input_file> contains list of wav files
+    $ cat <input_file>
+      /path/to/audio_1.wav
+      /path/to/audio_2.wav
+
+    <output_file> contains list of wav files paired with their number of samples
+    $ cat <output_file>
+      /path/to/audio_1.wav    180000
+      /path/to/audio_2.wav    120000
+"""
+import sys
+import soundfile as sf
+
+if __name__ == "__main__":
+    files = sys.argv[1]
+    with open(files) as fr:
+        for fi in fr:
+            fi = fi.strip()
+            print(f'{fi}\t{sf.SoundFile(fi).frames}')


Test patch:
Repository: ManageIQ/integration_tests

Issue:
Fix enable db script
There were some helpful changes made in a [recent upstream commit](https://github.com/ManageIQ/cfme/pull/1246), including explicit noninteractive support for db configuration in the appliance_console, and logging.

We should fix up `scripts/enable_internal_db.py` and the related rb template to take advantage of the impending goodness.



Discussion:

Resolving patch:
diff --git a/scripts/enable_internal_db.py b/scripts/enable_internal_db.py
--- a/scripts/enable_internal_db.py
+++ b/scripts/enable_internal_db.py
@@ -1,12 +1,14 @@
 #!/usr/bin/env python
 
-"""
-SSH in to a running appliance and set up an internal DB
+"""SSH in to a running appliance and set up an internal DB.
 
 An optional region can be specified (default 0), and the script
 will use the first available unpartitioned disk as the data volume
 for postgresql.
 
+Running this script against an already configured appliance is
+unsupported, hilarity may ensue.
+
 """
 
 import argparse
@@ -59,15 +61,6 @@ def main():
         print 'Enabling DB failed with error:'
         print out
         sys.exit(1)
-
-    # set up the DB region, reboot
-    print 'Setting up DB with region %s' % args.region
-    status, out = client.run_rake_command(
-        'evm:db:region -- --region %s' % args.region)
-    if status != 0:
-        print 'DB polutation failed with error:'
-        print out
-        sys.exit(1)
     else:
         print 'Rebooting appliance'
         client.run_command('reboot')


Test patch:
Repository: ManageIQ/integration_tests

Issue:
Model up yaml configs from the DB
Various yaml configs are stored in the database, including the one we'll most likely want to imspect, which is the vmdb config.

The schema, for our purposes, is two fields in the `configurations` table, `typ` and `settings`. The interface that I'm leaning toward is configurations[typ] = dictified_yaml(settings), if that makes sense. 

So, for example, if we wanted to see whether or not to get a list of public images from ec2, the lookup would be `configurations['vmdb']['ems_refresh']['ec2']['get_public_images']`



Discussion:

Resolving patch:
diff --git a/fixtures/cfmedb.py b/fixtures/cfmedb.py
--- a/fixtures/cfmedb.py
+++ b/fixtures/cfmedb.py
@@ -70,3 +70,13 @@ def test_that_tries_for_db(db_session):
     Session = sessionmaker(bind=db.engine)
     return Session()
 
+@pytest.fixture
+def db_yamls(db_session):
+    '''Returns the yamls from the db configuration table as a dict'''
+
+    import db
+    import yaml
+    configs = db_session.query(db.Configuration.typ, db.Configuration.settings)
+    data = {name: yaml.load(settings) for name, settings in configs}
+
+    return data


Test patch: