RVC-Project / Retrieval-based-Voice-Conversion

in preparation...
MIT License
294 stars 45 forks source link

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

Closed alcoftTAO closed 9 months ago

alcoftTAO commented 9 months ago

I have this error when trying to execute my code.

My code is:

from pathlib import Path
from dotenv import load_dotenv
from scipy.io import wavfile
from rvc.modules.vc.modules import VC
import os
import torch
import json
import ai_config as cfg

vc: VC = VC()

def __load_model__(model_path: str, device: str) -> None:
    vc.config.device = device
    vc.get_vc(model_path)

def LoadModel() -> None:
    if (not cfg.current_data.prompt_order.__contains__("rvc")):
        raise Exception("Model is not in 'prompt_order'.")

    if (vc != None or len(cfg.current_data.rvc_model_path.strip()) == 0):
        return

    device = "cuda" if (torch.cuda.is_available() and cfg.current_data.use_gpu_if_available and cfg.current_data.move_to_gpu.count("rvc") > 0) else "cpu"

    load_dotenv("rvc_env")
    __load_model__(cfg.current_data.rvc_model_path, device)

def __make_rvc__(audio_name: str | Path, protect: float = 0.33, filter_radius: int = 3, method: str = "rmvpe") -> bytes:
    LoadModel()

    if (type(audio_name) == str):
        audio_name = Path(audio_name)

    if (len(cfg.current_data.rvc_index_path.strip()) == 0):
        index_file = None
    else:
        index_file = Path(cfg.current_data.rvc_index_path)

    if (method != "rmvpe" and method != "pm" and method != "harvest" and method != "crepe"):
        raise Exception("RMV method must be 'rmvpe', 'pm', 'harvest' or 'crepe'.")

    tgt_sr, audio_opt, _, _ = vc.vc_single(sid = 0, input_audio_path = audio_name, f0_method = method, index_file = index_file, filter_radius = filter_radius, protect = protect)
    output_file = "tmp_rvc_audio_"
    output_file_id = 0

    while (os.path.exists(output_file + str(output_file_id) + ".wav")):
        output_file_id += 1

    wavfile.write(output_file + str(output_file_id) + ".wav", tgt_sr, audio_opt)
    audio_bytes = b""

    with open(output_file + str(output_file_id) + ".wav", "wb") as f:
        audio_bytes = f.read()
        f.close()

    os.remove(output_file + str(output_file_id) + ".wav")
    return audio_bytes

def MakeRVC(data: str | dict[str]) -> bytes:
    if (type(data) == str):
        try:
            data = json.loads(data)
        except Exception as ex:
            raise Exception("[RVC] Data must be a dictionary or a JSON code. ERROR: " + str(ex))

    ddata = {
        "input": "",
        "protect": 0.33,
        "filter_radius": 3,
        "method": "rmvpe"
    }

    try:
        ddata["input"] = data["input"]
    except:
        raise Exception("Unable to get audio path.")

    try:
        ddata["protect"] = float(data["protect"])
    except:
        pass

    try:
        ddata["filter_radius"] = int(data["filter_radius"])
    except:
        pass

    try:
        ddata["method"] = data["method"]
    except:
        pass

    return __make_rvc__(ddata["input"], ddata["protect"], ddata["filter_radius"], ddata["method"])

The traceback is:

Traceback (most recent call last):
  File "/home/alcoft/Projects/Multilang/TAO_I4.0/LibI4/Python_AI/ai_server_all.py", line 1, in <module>
    import ai_server
  File "/home/alcoft/Projects/Multilang/TAO_I4.0/LibI4/Python_AI/ai_server.py", line 9, in <module>
    import chatbot_all as cb
  File "/home/alcoft/Projects/Multilang/TAO_I4.0/LibI4/Python_AI/chatbot_all.py", line 14, in <module>
    import Inference.RVC_inference as rvc
  File "/home/alcoft/Projects/Multilang/TAO_I4.0/LibI4/Python_AI/Inference/RVC_inference.py", line 4, in <module>
    from rvc.modules.vc.modules import VC
  File "/home/alcoft/.local/lib/python3.11/site-packages/rvc/modules/vc/modules.py", line 21, in <module>
    from rvc.modules.vc.utils import *
  File "/home/alcoft/.local/lib/python3.11/site-packages/rvc/modules/vc/utils.py", line 3, in <module>
    from fairseq import checkpoint_utils
  File "/home/alcoft/.local/lib/python3.11/site-packages/fairseq/__init__.py", line 20, in <module>
    from fairseq.distributed import utils as distributed_utils
  File "/home/alcoft/.local/lib/python3.11/site-packages/fairseq/distributed/__init__.py", line 7, in <module>
    from .fully_sharded_data_parallel import (
  File "/home/alcoft/.local/lib/python3.11/site-packages/fairseq/distributed/fully_sharded_data_parallel.py", line 10, in <module>
    from fairseq.dataclass.configs import DistributedTrainingConfig
  File "/home/alcoft/.local/lib/python3.11/site-packages/fairseq/dataclass/__init__.py", line 6, in <module>
    from .configs import FairseqDataclass
  File "/home/alcoft/.local/lib/python3.11/site-packages/fairseq/dataclass/configs.py", line 1104, in <module>
    @dataclass
     ^^^^^^^^^
  File "/usr/lib/python3.11/dataclasses.py", line 1230, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/usr/lib/python3.11/dataclasses.py", line 1220, 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

Can anyone help me fix this error?

Tps-F commented 9 months ago

You are using python 3.11, right? https://github.com/RVC-Project/Retrieval-based-Voice-Conversion/blob/develop/pyproject.toml#L14-L15 Comment out L14 and uncomment L15 and install again.

alcoftTAO commented 9 months ago

I ran the command:

pip uninstall fairseq
pip install git+https://github.com/Tps-F/fairseq.git@main

And it works now, thanks for the help!

IS-FIELD commented 5 months ago

Hi, I met the same problem whith this issue, but I can't just download the version that suits python 11.

$ pip install git+https://github.com/Tps-F/fairseq.git@main DEPRECATION: Loading egg at d:\anaconda3\lib\site-packages\d2l-1.0.3-py3.11.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at https://github.com/pypa/pip/issues/12330 Looking in indexes: https://mirrors.aliyun.com/pypi/simple/ Collecting git+https://github.com/Tps-F/fairseq.git@main Cloning https://github.com/Tps-F/fairseq.git (to revision main) to c:\users\32304\appdata\local\temp\pip-req-build-5t6j7b7i Running command git clone --filter=blob:none --quiet https://github.com/Tps-F/fairseq.git 'C:\Users\32304\AppData\Local\Temp\pip-req-build-5t6j7b7i' Resolved https://github.com/Tps-F/fairseq.git to commit ff08af27e302625a27d3502b0791a9367c8af0c7 Running command git submodule update --init --recursive -q Installing build dependencies: started Installing build dependencies: still running... Installing build dependencies: finished with status 'canceled' ERROR: Operation cancelled by user