facebookresearch / fairseq

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

Dataclass error while importing Fairseq in Python 3.11 #5012

Open usaraj opened 1 year ago

usaraj commented 1 year ago

πŸ› Bug

FaValueError: mutable default <class 'fairseq.dataclass.configs.CommonConfig'> for field common is not allowed: use default_factory

To Reproduce

Steps to reproduce the behavior (always include the command you ran): 1, pip install fairseq==0.12.2

  1. from fairseq import *

Trace:

Traceback (most recent call last): File "", line 1, in File "/home/a1bharat/fairseq/fairseq/init.py", line 20, in from fairseq.distributed import utils as distributed_utils File "/home/a1bharat/fairseq/fairseq/distributed/init.py", line 7, in from .legacy_distributed_data_parallel import LegacyDistributedDataParallel File "/home/a1bharat/fairseq/fairseq/distributed/legacy_distributed_data_parallel.py", line 23, in from fairseq.distributed import utils File "/home/a1bharat/fairseq/fairseq/distributed/utils.py", line 22, in from fairseq.dataclass.configs import DistributedTrainingConfig, FairseqConfig File "/home/a1bharat/fairseq/fairseq/dataclass/init.py", line 6, in from .configs import FairseqDataclass File "/home/a1bharat/fairseq/fairseq/dataclass/configs.py", line 906, in @dataclass ^^^^^^^^^ File "/usr/lib/python3.11/dataclasses.py", line 1220, in dataclass return wrap(cls) ^^^^^^^^^ File "/usr/lib/python3.11/dataclasses.py", line 1210, in wrap return _process_class(cls, init, repr, eq, order, unsafe_hash, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/dataclasses.py", line 958, in _process_class cls_fields.append(_get_field(cls, name, type, kw_only)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/dataclasses.py", line 815, in _get_field raise ValueError(f'mutable default {type(f.default)} for field ' ValueError: mutable default <class 'fairseq.dataclass.configs.CommonConfig'> for field common is not allowed: use default_factory

Code sample

Environment

Additional context

VarunGumma commented 1 year ago

Is Pytorch supporting python 3.11?

EmreOzkose commented 1 year ago

Hi, is there any progress on this issue?

EmreOzkose commented 1 year ago

I created another conda environment with python 3.9, and didn't face with this error.

VarunGumma commented 1 year ago

@EmreOzkose Yes, Pytorch2.0 supports Python 3.11

Birch-san commented 1 year ago

https://github.com/facebookresearch/fairseq/blob/176cd934982212a4f75e0669ee81b834ee71dbb0/fairseq/dataclass/configs.py#L1129

I assume it wants something like this:

@dataclass
class FairseqConfig(FairseqDataclass):
-     common: CommonConfig = CommonConfig()
+     common: CommonConfig = field(default_factory=CommonConfig)
conan1024hao commented 1 year ago

same problem

ashesfall commented 1 year ago

Experiencing this with 3.11.2.

Muskan19577 commented 1 year ago

I am also facing the same issue. any way to resolve this?

ashesfall commented 1 year ago

@Muskan19577 I had to move back to python 3.9

thyripian commented 1 year ago

I have this same issue running Python 3.11.3, and the config.py modifications suggested did not resolve the issue. Looks like the issues migrated to the hydra module, based on the traceback. Please advise. Traceback below.

fairseq_error_traceback

bit-scientist commented 11 months ago

getting the same ValeError iwth Python 3.11.4. Any suggestions?

One-sixth commented 11 months ago

The official fix is too slow, I made a fix version myself. You can install it using the following command. v0.12.3. I conducted a simple test and found no abnormalities.

pip install git+https://github.com/One-sixth/fairseq.git
kabyanil commented 10 months ago

This issue still exists on the official release. I'm using Python 3.11.

zhiqu22 commented 9 months ago

This issue still exists on the official release. I'm using Python 3.11.

Same error with Python 3.11.5

MrGutarLed commented 9 months ago

Same error with Python 3.11

JingThree3 commented 9 months ago

Same error with Python 3.11.6 πŸ˜₯

aikow commented 9 months ago

The changes to dataclasses are an official change that was introduced in python 3.11, meaning all 3.11.x and higher won't work. This will need to get changed in fairseq's codebase, and isnt dependent on the exact python 3.11.x version

Y-H-Joe commented 8 months ago
Python 3.11.4 (main, Jul  5 2023, 14:15:25) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fairseq
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/users/nus/zyh/anaconda3/lib/python3.11/site-packages/fairseq/__init__.py", line 20, in <module>
    from fairseq.distributed import utils as distributed_utils
  File "/home/users/nus/zyh/anaconda3/lib/python3.11/site-packages/fairseq/distributed/__init__.py", line 7, in <module>
    from .fully_sharded_data_parallel import (
  File "/home/users/nus/zyh/anaconda3/lib/python3.11/site-packages/fairseq/distributed/fully_sharded_data_parallel.py", line 10, in <module>
    from fairseq.dataclass.configs import DistributedTrainingConfig
  File "/home/users/nus/zyh/anaconda3/lib/python3.11/site-packages/fairseq/dataclass/__init__.py", line 6, in <module>
    from .configs import FairseqDataclass
  File "/home/users/nus/zyh/anaconda3/lib/python3.11/site-packages/fairseq/dataclass/configs.py", line 1104, in <module>
    @dataclass
     ^^^^^^^^^
  File "/home/users/nus/zyh/anaconda3/lib/python3.11/dataclasses.py", line 1230, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/home/users/nus/zyh/anaconda3/lib/python3.11/dataclasses.py", line 1220, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/users/nus/zyh/anaconda3/lib/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/users/nus/zyh/anaconda3/lib/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'fairseq.dataclass.configs.CommonConfig'> for field common is not allowed: use default_factory
CircuitCM commented 7 months ago

I'm confused. Why is this still not fixed? Will it break backwards compatibility?

liyaodev commented 6 months ago

I have encountered these problems, and here is my solution: Windows11 environment

pip install git+https://github.com/liyaodev/fairseq.git

or, download fairseq-0.12.3.1-cp311-cp311-linux_x86_64.whl

pip install./fairseq-0.12.3.1-cp311-cp311-linux_x86_64.whl

WSL2(Ubuntu22.04) environment(my local use)

pip install git+https://github.com/liyaodev/fairseq.git

or, download fairseq-0.12.3.1-cp311-cp311-linux_x86_64.whl

pip install./fairseq-0.12.3.1-cp311-cp311-linux_x86_64.whl

there's a little tip, best use hydra-core==1.3.2 omegaconf==2.3.0

VarunGumma commented 6 months ago

Alternately, you can use my fork of fairseq which supports Python 3.11, Knowledge Distillation, Adapters a few more interesting fixes.

vxnuaj commented 5 months ago

!!! this issue needs attention.

Can't use python 3.11.2,

ValueError: mutable default <class 'fairseq.dataclass.configs.CommonConfig'> for field common is not allowed: use default_factory

4ka0 commented 5 months ago

This same error is being output with Python 3.12.0.

Fmstrat commented 3 months ago

Figured since it's April now, I'd throw in my two cents. Still not working.

yjyuanjin commented 3 months ago

https://github.com/facebookresearch/fairseq/blob/176cd934982212a4f75e0669ee81b834ee71dbb0/fairseq/dataclass/configs.py#L1129

I assume it wants something like this:

@dataclass
class FairseqConfig(FairseqDataclass):
-     common: CommonConfig = CommonConfig()
+     common: CommonConfig = field(default_factory=CommonConfig)

Thanks, it work for me. I change all the error place like your suggestion.

last-fisherman commented 3 months ago

@liyaodev, could you please tell me what the exact name of the package you mentioned would be for Windows?

liyaodev commented 3 months ago

@liyaodev, could you please tell me what the exact name of the package you mentioned would be for Windows?

Windows 11 Professional

snoop2head commented 2 months ago

Not working in CentOS, Python 3.11

tavyscrolls commented 2 months ago

So uh, still not working in Python 3.12 πŸ˜… Compile from source fixes tho

ZeaMays14142 commented 2 months ago

problem still up and critical

ZeaMays14142 commented 2 months ago

I have encountered these problems, and here is my solution: Windows11 environment

pip install git+https://github.com/liyaodev/fairseq.git

or, download fairseq-0.12.3.1-cp311-cp311-linux_x86_64.whl

pip install./fairseq-0.12.3.1-cp311-cp311-linux_x86_64.whl

WSL2(Ubuntu22.04) environment(my local use)

pip install git+https://github.com/liyaodev/fairseq.git

or, download fairseq-0.12.3.1-cp311-cp311-linux_x86_64.whl

pip install./fairseq-0.12.3.1-cp311-cp311-linux_x86_64.whl

there's a little tip, best use hydra-core==1.3.2 omegaconf==2.3.0

does this still work?

neph-64 commented 1 month ago

This is what I get.

Traceback (most recent call last):
  File "C:\Users\neph\rvc-tts-webui\app.py", line 12, in <module>
    from fairseq import checkpoint_utils
  File "C:\Users\neph\rvc-tts-webui\venv\Lib\site-packages\fairseq\__init__.py", line 20, in <module>
    from fairseq.distributed import utils as distributed_utils
  File "C:\Users\neph\rvc-tts-webui\venv\Lib\site-packages\fairseq\distributed\__init__.py", line 7, in <module>
    from .fully_sharded_data_parallel import (
  File "C:\Users\neph\rvc-tts-webui\venv\Lib\site-packages\fairseq\distributed\fully_sharded_data_parallel.py", line 10, in <module>
    from fairseq.dataclass.configs import DistributedTrainingConfig
  File "C:\Users\neph\rvc-tts-webui\venv\Lib\site-packages\fairseq\dataclass\__init__.py", line 6, in <module>
    from .configs import FairseqDataclass
  File "C:\Users\neph\rvc-tts-webui\venv\Lib\site-packages\fairseq\dataclass\configs.py", line 1104, in <module>
    @dataclass
     ^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1008.0_x64__qbz5n2kfra8p0\Lib\dataclasses.py", line 1268, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1008.0_x64__qbz5n2kfra8p0\Lib\dataclasses.py", line 1258, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1008.0_x64__qbz5n2kfra8p0\Lib\dataclasses.py", line 994, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1008.0_x64__qbz5n2kfra8p0\Lib\dataclasses.py", line 852, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'fairseq.dataclass.configs.CommonConfig'> for field common is not allowed: use default_factory
(venv) PS C:\Users\neph\rvc-tts-webui> pip install git+https://github.com/liyaodev/fairseq.git
Collecting git+https://github.com/liyaodev/fairseq.git
  Cloning https://github.com/liyaodev/fairseq.git to c:\users\neph\appdata\local\temp\pip-req-build-ktcozen9
  Running command git clone --filter=blob:none --quiet https://github.com/liyaodev/fairseq.git 'C:\Users\neph\AppData\Local\Temp\pip-req-build-ktcozen9'
  Resolved https://github.com/liyaodev/fairseq.git to commit b963eac7a04c539ad59fb1e23277f2ff7ee29e74
  Running command git submodule update --init --recursive -q
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  Γ— Getting requirements to build wheel did not run successfully.
  β”‚ exit code: 1
  ╰─> [18 lines of output]
      Traceback (most recent call last):
        File "C:\Users\neph\rvc-tts-webui\venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "C:\Users\neph\rvc-tts-webui\venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\neph\rvc-tts-webui\venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\neph\AppData\Local\Temp\pip-build-env-1tdzldxr\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\neph\AppData\Local\Temp\pip-build-env-1tdzldxr\overlay\Lib\site-packages\setuptools\build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "C:\Users\neph\AppData\Local\Temp\pip-build-env-1tdzldxr\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 246, in <module>
      OSError: [WinError 1314] Dem Client fehlt ein erforderliches Recht: '..\\examples' -> 'fairseq\\examples'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

Γ— Getting requirements to build wheel did not run successfully.
β”‚ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
sh1zooo commented 1 month ago

This is my first answer on any forum, besides, my English is bad. Sorry, guys. Somehow it worked.

  1. Run cmd as administrator(!) - (Running cmd as an administrator fixes the error [WinError 1314])

  2. Write this to the console:

    git clone https://github.com/pytorch/fairseq
    cd fairseq
    pip install --editable ./
  3. Next, you may encounter the error "1 required argument is missing, containing only the keyword: 'recursive_guard'". You will need to change the Python version to 3.12.3 or lower. In version 3.12.4, this error will be displayed

JackismyShephard commented 2 weeks ago

I have encountered these problems, and here is my solution: Windows11 environment

pip install git+https://github.com/liyaodev/fairseq.git

or, download fairseq-0.12.3.1-cp311-cp311-linux_x86_64.whl

pip install./fairseq-0.12.3.1-cp311-cp311-linux_x86_64.whl

WSL2(Ubuntu22.04) environment(my local use)

pip install git+https://github.com/liyaodev/fairseq.git

or, download fairseq-0.12.3.1-cp311-cp311-linux_x86_64.whl

pip install./fairseq-0.12.3.1-cp311-cp311-linux_x86_64.whl

there's a little tip, best use hydra-core==1.3.2 omegaconf==2.3.0

does this still work?

This does not work for me on Windows 11. I am getting OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\Jacki\AppData\Local\Temp\pip-build-env-x3uaf2ep\overlay\Lib\site-packages\torch\lib\shm

Geremia commented 6 days ago

@yjyuanjin Your patch didn't work for me. I'm using Python 3.11 on Linux.