facebookresearch / fairseq

Facebook AI Research Sequence-to-Sequence Toolkit written in Python.
MIT License
30.13k stars 6.36k forks source link

PadDataset does not have pad_length (multilingual_language_modeling) #4209

Open afcruzs-ms opened 2 years ago

afcruzs-ms commented 2 years ago

🐛 Bug

On multilingual_language_modeling.py the method build_dataset_for_inference creates an instance of PadDataset and passes pad_length = max_seq_len as an argument. However, on pad_dataset.py the constructor of PadDataset does not have the argument pad_length.

To Reproduce

Steps to reproduce the behavior (always include the command you ran):

  1. Try to run the example at fairseq/examples/xglm/ Stack trace:
    Traceback (most recent call last):
    File "go.py", line 75, in <module>
    predict = COPA_eval(example["premise"], example["choice1"], example["choice2"])
    File "go.py", line 69, in COPA_eval
    lprob1 = get_logprobs(prompt + "\n" + alternative1).sum()
    File "go.py", line 63, in get_logprobs
    return lm.score(prompt, replace_newlines_with_eos=True)['positional_scores']
    File "/home/ancruzsa/fairseq/fairseq/hub_utils.py", line 139, in score
    return self.score(
    File "/home/ancruzsa/fairseq/fairseq/hub_utils.py", line 153, in score
    for hypos in self.generate(
    File "/home/ancruzsa/fairseq/fairseq/hub_utils.py", line 187, in generate
    for batch in self._build_batches(tokenized_sentences, skip_invalid_size_inputs):
    File "/home/ancruzsa/fairseq/fairseq/hub_utils.py", line 275, in _build_batches
    dataset=self.task.build_dataset_for_inference(tokens, lengths),
    File "/home/ancruzsa/fairseq/fairseq/tasks/multilingual_language_modeling.py", line 533, in build_dataset_for_inference
    "src_tokens": PadDataset(
    TypeError: __init__() got an unexpected keyword argument 'pad_length'

Code sample

Example at fairseq/examples/xglm/, however this is also broken. See #4210 to be able to get the stacktrace above.

Expected behavior

Calling build_dataset_for_inference should not fail this way.

Environment

Additional context

todpole3 commented 2 years ago

@afcruzs-ms Would you please close this issue if the problem has been solved? Thanks!