facebookresearch / fairseq

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

Language model example cannot use fairseq-generate #2350

Closed fuzihaofzh closed 2 years ago

fuzihaofzh commented 4 years ago

šŸ› Bug

Language model example fails when using fairseq-generate.

To Reproduce

Follow https://github.com/pytorch/fairseq/blob/master/examples/language_model/README.md Then, use generate command as follows:

fairseq-generate output/data-bin/$DATASET --task language_modeling --path output/models/$EXP/checkpoint_best.pt  --sampling  --beam 1 --sampling-topk 2 --temperature 1 

It says

Traceback (most recent call last):
  File "tools/fairseq/fairseq_cli/generate.py", line 278, in <module>
    cli_main()
  File "tools/fairseq/fairseq_cli/generate.py", line 274, in cli_main
    main(args)
  File "tools/fairseq/fairseq_cli/generate.py", line 38, in main
    return _main(args, sys.stdout)
  File "tools/fairseq/fairseq_cli/generate.py", line 108, in _main
    num_workers=args.num_workers,
  File "/me/tools/fairseq/fairseq/tasks/fairseq_task.py", line 176, in get_batch_iterator
    raise_exception=(not ignore_invalid_inputs),
  File "/me/tools/fairseq/fairseq/data/data_utils.py", line 199, in filter_by_size
    ).format(ignored[0], dataset.size(ignored[0]), max_positions))
Exception: Size of sample #18 is invalid (=788) since max_positions=512, skip this example with --skip-invalid-size-inputs-valid-test

Then, I add --skip-invalid-size-inputs-valid-test to the command and it says:

Traceback (most recent call last):
  File "tools/fairseq/fairseq_cli/generate.py", line 278, in <module>
    cli_main()
  File "tools/fairseq/fairseq_cli/generate.py", line 274, in cli_main
    main(args)
  File "tools/fairseq/fairseq_cli/generate.py", line 38, in main
    return _main(args, sys.stdout)
  File "tools/fairseq/fairseq_cli/generate.py", line 259, in _main
    num_sentences, gen_timer.n, gen_timer.sum, num_sentences / gen_timer.sum, 1. / gen_timer.avg))
ZeroDivisionError: division by zero

How can I use fairseq-generate to generate a language model sentence?

Code sample

Expected behavior

It is expected to generate some senntences.

Environment

Additional context

myleott commented 4 years ago

Are you training a language model? fairseq-generate is primarily for translation. If you want to evaluate perplexity you need to use fairseq-eval-lm: https://github.com/pytorch/fairseq/blob/master/examples/language_model/README.md#3-evaluate

smita181298 commented 4 years ago

šŸ› Bug

Language model example fails when using fairseq-generate.

To Reproduce

Follow https://github.com/pytorch/fairseq/blob/master/examples/language_model/README.md Then, use generate command as follows:

fairseq-generate output/data-bin/$DATASET --task language_modeling --path output/models/$EXP/checkpoint_best.pt  --sampling  --beam 1 --sampling-topk 2 --temperature 1 

It says

Traceback (most recent call last):
  File "tools/fairseq/fairseq_cli/generate.py", line 278, in <module>
    cli_main()
  File "tools/fairseq/fairseq_cli/generate.py", line 274, in cli_main
    main(args)
  File "tools/fairseq/fairseq_cli/generate.py", line 38, in main
    return _main(args, sys.stdout)
  File "tools/fairseq/fairseq_cli/generate.py", line 108, in _main
    num_workers=args.num_workers,
  File "/me/tools/fairseq/fairseq/tasks/fairseq_task.py", line 176, in get_batch_iterator
    raise_exception=(not ignore_invalid_inputs),
  File "/me/tools/fairseq/fairseq/data/data_utils.py", line 199, in filter_by_size
    ).format(ignored[0], dataset.size(ignored[0]), max_positions))
Exception: Size of sample #18 is invalid (=788) since max_positions=512, skip this example with --skip-invalid-size-inputs-valid-test

Then, I add --skip-invalid-size-inputs-valid-test to the command and it says:

Traceback (most recent call last):
  File "tools/fairseq/fairseq_cli/generate.py", line 278, in <module>
    cli_main()
  File "tools/fairseq/fairseq_cli/generate.py", line 274, in cli_main
    main(args)
  File "tools/fairseq/fairseq_cli/generate.py", line 38, in main
    return _main(args, sys.stdout)
  File "tools/fairseq/fairseq_cli/generate.py", line 259, in _main
    num_sentences, gen_timer.n, gen_timer.sum, num_sentences / gen_timer.sum, 1. / gen_timer.avg))
ZeroDivisionError: division by zero

How can I use fairseq-generate to generate a language model sentence?

Code sample

Expected behavior

It is expected to generate some senntences.

Environment

  • fairseq Version (e.g., 1.0 or master): master
  • PyTorch Version (e.g., 1.0) 1.5.1
  • OS (e.g., Linux): CentOS
  • How you installed fairseq (pip, source): pip
  • Build command you used (if compiling from source):
  • Python version: 3.7.7
  • CUDA/cuDNN version: 10.2
  • GPU models and configuration: 1080ti
  • Any other relevant information:

Additional context

I am facing the same issue for abstractive summarization using prophetnet model which uses fairseq-generate. Please help

fuzihaofzh commented 4 years ago

@myleott Thanks for your answer. I want to use language model to generate text in batch not only evaluate.

FadedCosine commented 3 years ago

@fuzihaofzh I am facing the same issue. Have you solved this problem? Thanks.

MovingKyu commented 3 years ago

I am facing the same issue. I am done with evaluation, and would like to generate. Any solution yet?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

stale[bot] commented 2 years ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!