facebookresearch / fairseq

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

TypeError: cannot unpack non-iterable NoneType object #4737

Open HarryHe11 opened 2 years ago

HarryHe11 commented 2 years ago

🐛 Bug

I met this bug when I try to load a fairseq translation model. I could see the same issue is still open in fairseq GitHub repo. I tried installing torch and torchvision packages as mentioned in the below link but still I am facing the same issue.

To Reproduce

Using your colab tutorial will also produce the same bug.

Using cache found in /root/.cache/torch/hub/pytorch_fairseq_main
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-21-61d0ed709261> in <module>
      1 # Load translation model
      2 # en2ru = torch.hub.load('pytorch/fairseq', 'transformer.wmt19.en-ru.single_model', tokenizer='moses', bpe='fastbpe')
----> 3 ru2en = torch.hub.load('pytorch/fairseq', 'transformer.wmt19.ru-en.single_model', tokenizer='moses', bpe='fastbpe')

7 frames
/usr/local/lib/python3.7/dist-packages/torch/hub.py in load(repo_or_dir, model, source, trust_repo, force_reload, verbose, skip_validation, *args, **kwargs)

/usr/local/lib/python3.7/dist-packages/torch/hub.py in _load_local(hubconf_dir, model, *args, **kwargs)

/usr/local/lib/python3.7/dist-packages/torch/hub.py in _import_module(name, path)
     87     return '[https://github.com/{}/{}/archive/{}.zip](https://github.com/%7B%7D/%7B%7D/archive/%7B%7D.zip)'.format(repo_owner, repo_name, branch)
     88 
---> 89 
     90 def _load_attr_from_module(module, func_name):
     91     # Check if callable is defined in the module

/usr/lib/python3.7/importlib/_bootstrap_external.py in exec_module(self, module)

/usr/lib/python3.7/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

~/.cache/torch/hub/pytorch_fairseq_main/hubconf.py in <module>
     37 
     38 # only do fairseq imports after checking for dependencies
---> 39 from fairseq.hub_utils import (  # noqa; noqa
     40     BPEHubInterface as bpe,
     41     TokenizerHubInterface as tokenizer,

~/.cache/torch/hub/pytorch_fairseq_main/fairseq/__init__.py in <module>
     31 hydra_init()
     32 
---> 33 import fairseq.criterions  # noqa
     34 import fairseq.distributed  # noqa
     35 import fairseq.models  # noqa

~/.cache/torch/hub/pytorch_fairseq_main/fairseq/criterions/__init__.py in <module>
     22     CRITERION_DATACLASS_REGISTRY,
     23 ) = registry.setup_registry(
---> 24     "--criterion", base_class=FairseqCriterion, default="cross_entropy"
     25 )
     26 

TypeError: cannot unpack non-iterable NoneType object

Code sample

Using your colab tutorial will also produce the same bug.

Expected behavior

successfully load the translation model

Environment

iamanigeeit commented 1 year ago

@HarryHe11 Not sure if it's related but my problem went away when installed scikit-learn and scipy.

hkt456 commented 1 year ago

I'm facing the same problem here. @HarryHe11 Have you figured out a solution?

HarryHe11 commented 1 year ago

Not yet man, sorry

Huỳnh Khắc Tâm @.***>于2023年2月5日 周日20:17写道:

I'm facing the same problem here. @HarryHe11 https://github.com/HarryHe11 Have you figured out a solution?

— Reply to this email directly, view it on GitHub https://github.com/facebookresearch/fairseq/issues/4737#issuecomment-1417666851, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQIEVLL3GHDOXZEHQ54AWN3WV6K7BANCNFSM6AAAAAAQQ7N46E . You are receiving this because you were mentioned.Message ID: @.***>

-- Best regards, Haorui He

vstevanoska commented 1 year ago

Just wanted to share what worked for me. Tried the colab tutorial, got the same error. Additionally installed bitarray, sacrebleu and scipy (not 100% certain it's necessary). After restarting the kernel 3-4 more times, it worked.

ajahstudio commented 1 year ago

@HarryHe11 Not sure if it's related but my problem went away when installed scikit-learn and scipy.

Confirmed. Error Resolved after i installed scikit-learn and scipy.

Subarasheese commented 1 year ago

Unfortunately, installing scikit-learn and scipy did not fix this problem in my case.


Traceback (most recent call last):
  File "/home/myuser/mms/fairseq/examples/speech_recognition/new/infer.py", line 21, in <module>
    from examples.speech_recognition.new.decoders.decoder_config import (
  File "/home/myuser/mms/fairseq/examples/speech_recognition/__init__.py", line 1, in <module>
    from . import criterions, models, tasks  # noqa
  File "/home/myuser/mms/fairseq/examples/speech_recognition/criterions/__init__.py", line 15, in <module>
    importlib.import_module(
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/myuser/mms/fairseq/examples/speech_recognition/criterions/cross_entropy_acc.py", line 13, in <module>
    from fairseq import utils
  File "/home/myuser/mms/fairseq/fairseq/__init__.py", line 33, in <module>
    import fairseq.criterions  # noqa
  File "/home/myuser/mms/fairseq/fairseq/criterions/__init__.py", line 18, in <module>
    (
TypeError: cannot unpack non-iterable NoneType object

This problem leads to:


Exception has occurred: FileNotFoundError       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
[Errno 2] No such file or directory: '/tmp/tmphzwlmd_z/hypo.word'
  File "/home/myuser/mms/fairseq/examples/mms/asr/infer/mms_infer.py", line 53, in process
    with open(tmpdir/"hypo.word") as fr:
  File "/home/myuser/mms/convert_dep.py", line 44, in <module>
    mms_infer.process(args)
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmphzwlmd_z/hypo.word'

I am trying to run MMS.

Maverick1983 commented 1 year ago

@HarryHe11 Not sure if it's related but my problem went away when installed scikit-learn and scipy.

Confirm. Working for me.

liku-amare commented 8 months ago

Just wanted to share what worked for me. Tried the colab tutorial, got the same error. Additionally installed bitarray, sacrebleu and scipy (not 100% certain it's necessary). After restarting the kernel 3-4 more times, it worked.

Installing these packages and restarting kernel worked for me too.