RVC-Project / RVC-Project/Retrieval-based-Voice-Conversion-WebUI

在执行ONNX导出时无法处理rmvpe.py中的Encoder BN

Open
#2,483 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
38.4k
Forks
5.3k
PR merge metrics
No merged PRs in 30d

Description

Hi:
我正在尝试将vc_single()函数封装成一个torch.nn.Module模型类,现在已经做到了,实现的notebook在这里
可问题是,当我尝试把这个Pipeline使用torch.onnx.export导出为ONNX模型时,它抛出了如下的错误:

RuntimeError: Cannot insert a Tensor that requires grad as a constant. Consider making it a parameter or input, or detaching the gradient
Tensor:
0.6670
[ torch.cuda.HalfTensor{1} ]

通过观察StackTrace我发现报错的代码在此处:

File ~/Retrieval-based-Voice-Conversion-WebUI-main/infer/lib/rmvpe.py:244, in Encoder.forward(self, x)
  [242](https://vscode-remote+ssh-002dremote-002bconnect-002enmb1-002eseetacloud-002ecom.vscode-resource.vscode-cdn.net/root/Retrieval-based-Voice-Conversion-WebUI-main/~/Retrieval-based-Voice-Conversion-WebUI-main/infer/lib/rmvpe.py:242) def forward(self, x: torch.Tensor):
  [243](https://vscode-remote+ssh-002dremote-002bconnect-002enmb1-002eseetacloud-002ecom.vscode-resource.vscode-cdn.net/root/Retrieval-based-Voice-Conversion-WebUI-main/~/Retrieval-based-Voice-Conversion-WebUI-main/infer/lib/rmvpe.py:243)     concat_tensors: List[torch.Tensor] = []
--> [244](https://vscode-remote+ssh-002dremote-002bconnect-002enmb1-002eseetacloud-002ecom.vscode-resource.vscode-cdn.net/root/Retrieval-based-Voice-Conversion-WebUI-main/~/Retrieval-based-Voice-Conversion-WebUI-main/infer/lib/rmvpe.py:244)     x = self.bn(x)
  [245](https://vscode-remote+ssh-002dremote-002bconnect-002enmb1-002eseetacloud-002ecom.vscode-resource.vscode-cdn.net/root/Retrieval-based-Voice-Conversion-WebUI-main/~/Retrieval-based-Voice-Conversion-WebUI-main/infer/lib/rmvpe.py:245)     for i, layer in enumerate(self.layers):
  [246](https://vscode-remote+ssh-002dremote-002bconnect-002enmb1-002eseetacloud-002ecom.vscode-resource.vscode-cdn.net/root/Retrieval-based-Voice-Conversion-WebUI-main/~/Retrieval-based-Voice-Conversion-WebUI-main/infer/lib/rmvpe.py:246)         t, x = layer(x)

请问有什么办法可以解决此问题吗?因为从Encoder类的定义上看似乎没看出哪里有问题

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the POC_Torch.ipynb reproduction and inspect infer/lib/rmvpe.py, especially Encoder.forward() at the self.bn(x) call and the surrounding Encoder initialization. Run the torch.onnx.export path from the notebook and trace how the BN state is registered; done means the pipeline exports without the reported requires-grad constant error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.