Skip to content

Conversation

@mallocfree009
Copy link

voice-changerにお世話になっております。mallocfree009です。

RTX5000シリーズで動作ができなかったので、いくつか必要な対応をいれてある程度うごくところまでもっていってみました。
ご多忙の中恐縮ですが、ご都合のよいときにプルリクの採用をご検討いただけるかご検討いただければ幸いです。

実装・動作確認環境

  • OS: Windows11 23H2
  • CPU: Ryzen 7 5700X
  • GPU: NVIDIA GeForce RTX 5060 Ti or RTX 3070
  • CUDA Toolkit 12.8
  • cuDNN 9.8.0
  • venv環境:
    作成方法: py -3.10 -m venv venv
    Python: 3.10.11
    pip: 23.0.1

実装後確認内容

変更後動作確認した内容は以下です。

  • server側の起動で、ブラウザアクセスした状態で以下を確認
    • GPU/CPU環境でマイクから音声変換してスピーカー出力することを確認
    • GPU環境でRVCv2のpth,indexファイルをアップロードして、そのボイスを使い、マイクから音声変換してスピーカー出力することを確認
    • そのRVCv2ボイスをonnxに変換し、再度アップロードし、そのボイスでマイクから音声変換してスピーカー出力することを確認

RTX5000シリーズはCUDA12.8以降でないと動作せずtorchを2.7.0+cu128以降にアップする必要があり、torchのアップデートとそれに関連するパッケージについても調整を入れる必要がありました。

プルリクを採用するにあたっては、以下のようなプロジェクトの方針を鑑みて確認・調整すべき項目があります

  • fairseqの更新が止まっておりtorch2.6.0以降には対応できてない問題への対処の調整
  • requirements.txtの運用方法の変更についてのご確認

fairseqの更新が止まっておりtorch2.6.0以降には対応できてない問題への対処の調整

fairseqは以前の依存関係ではrequirements.txtに指定されていませんでしたが、別途明記しないと利用できなくなりました。
そのため明記して追加するようにしましたがpipのデフォルトのリポジトリからインストールされるfairseqの最新バージョンでは下記エラーがでて正常に動作させることができません。

2025-05-02 13:06:16 | WARNING | infer.modules.vc.modules | Traceback (most recent call last):
  File "V:\ai\voice-changer\infer\modules\vc\modules.py", line 170, in vc_single
    self.hubert_model = load_hubert(self.config)
  File "V:\ai\voice-changer\infer\modules\vc\utils.py", line 23, in load_hubert
    models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
  File "V:\ai\voice-changer\runtime\lib\site-packages\fairseq\checkpoint_utils.py", line 425, in load_model_ensemble_and_task
    state = load_checkpoint_to_cpu(filename, arg_overrides)
  File "V:\ai\voice-changer\runtime\lib\site-packages\fairseq\checkpoint_utils.py", line 315, in load_checkpoint_to_cpu
    state = torch.load(f, map_location=torch.device("cpu"))
  File "V:\ai\voice-changer\runtime\lib\site-packages\torch\serialization.py", line 1524, in load
    raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
_pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint.
        (1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
        (2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.
        WeightsUnpickler error: Unsupported global: GLOBAL fairseq.data.dictionary.Dictionary was not an allowed global by default. Please use `torch.serialization.add_safe_globals([fairseq.data.dictionary.Dictionary])` or the `torch.serialization.safe_globals([fairseq.data.dictionary.Dictionary])` context manager to allowlist this global if you trust this class/function.

PyTorch 2.6からの変更の影響で、これまでどおりの挙動をさせるにはfairseqパッケージ内のtorch.load()に引数weights_only=Falseを明示的に指定するよう修正する必要がありました。

このエラーについてはruntime\lib\site-packages\fairseq\checkpoint_utils.py(316)付近を以下のように書き換えると問題なくなりました。

    with open(local_path, "rb") as f:
        # state = torch.load(f, map_location=torch.device("cpu")) #MallocFree
        state = torch.load(f, map_location=torch.device("cpu"), weights_only=False) #MallocFree

ただfairseqは開発が停止しておりフルスクラッチで作り直したfairseq2が開発・推奨されています。
fairseq2にすると影響が大きいと思われるので一旦fairseqを私のGitHubのアカウントでフォークして、そこのtorch.load()について
修正を行い、そちらを参照してインストールするようにしています。

この状態で問題なく動作はしているようにみえます。

ただこのままだと例えば私がユーザーに危険が及ぶような変更をgitリポジトリに加えた場合(そんなことをするつもりは全くありませんが・・・)に、ユーザーに悪い影響がでてしまうのでgithubのリポジトリをw-okadaさんのGitHubアカウントでフォークして利用するように変更して、安全な状態を確保するほうがプロジェクトの運営上は安全かと思います。

プルリクの採用をご検討の場合は、どのような方針でfairseqを扱うかご決定いただければと思います。

requirements.txtの運用方法の変更についてのご確認

requirements.txtのバージョン更新のための整理を行うことが今回の対応の主な作業となりましたが、torchがCPUのみの運用であるか、どのGPUか、CUDAバージョンは何かにより適切なものをインストールする必要がある観点から、分割するほうが良いかとおもい変更しています。

開発時の運用がかわるので合わせてドキュメントも調整してみました。

これはどういった運用が理想的か価値観の違いにより判断が変わるかと思います。
この運用ではなく、他の運用のほうがいいなどある場合がありますので適宜調整いただく必要あるかと思います。

ご多忙の中恐縮ですが、ご都合のよいときにご検討いただければ幸いです。

@github-actions
Copy link
Contributor

github-actions bot commented May 17, 2025

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@mallocfree009
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@miguilimzero
Copy link

Hello, when using your patch, I'm getting:

The conflict is caused by:
    fairseq 0.12.2+dev.mf1 depends on omegaconf<2.1
    hydra-core 1.0.7 depends on omegaconf<2.1 and >=2.0.5

@miguilimzero
Copy link

I managed to fix the error by downgrading pip to 24.0 with pip install pip==24.0 (mine was on 25.1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants