Skip to content

Commit 0eb6bb6

Browse files
Onnx推理dml支持 (#556)
* Add files via upload * Add files via upload
1 parent a071f1e commit 0eb6bb6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

infer-web.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,12 +1119,12 @@ def change_info_(ckpt_path):
11191119
from infer_pack.models_onnx import SynthesizerTrnMsNSFsidM
11201120

11211121

1122-
def export_onnx(ModelPath, ExportedPath, MoeVS=True):
1122+
def export_onnx(ModelPath, ExportedPath):
11231123
cpt = torch.load(ModelPath, map_location="cpu")
1124-
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
1125-
hidden_channels = 256 if cpt.get("version","v1")=="v1"else 768#cpt["config"][-2] # hidden_channels,为768Vec做准备
1124+
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0]
1125+
vec_channels = 256 if cpt.get("version","v1")=="v1"else 768
11261126

1127-
test_phone = torch.rand(1, 200, hidden_channels) # hidden unit
1127+
test_phone = torch.rand(1, 200, vec_channels) # hidden unit
11281128
test_phone_lengths = torch.tensor([200]).long() # hidden unit 长度(貌似没啥用)
11291129
test_pitch = torch.randint(size=(1, 200), low=5, high=255) # 基频(单位赫兹)
11301130
test_pitchf = torch.rand(1, 200) # nsf基频
@@ -1160,7 +1160,7 @@ def export_onnx(ModelPath, ExportedPath, MoeVS=True):
11601160
"rnd": [2],
11611161
},
11621162
do_constant_folding=False,
1163-
opset_version=16,
1163+
opset_version=13,
11641164
verbose=False,
11651165
input_names=input_names,
11661166
output_names=output_names,
@@ -1835,11 +1835,10 @@ def export_onnx(ModelPath, ExportedPath, MoeVS=True):
18351835
label=i18n("Onnx输出路径"), value="", interactive=True
18361836
)
18371837
with gr.Row():
1838-
moevs = gr.Checkbox(label=i18n("MoeVS模型"), value=False,visible=False)
18391838
infoOnnx = gr.Label(label="info")
18401839
with gr.Row():
18411840
butOnnx = gr.Button(i18n("导出Onnx模型"), variant="primary")
1842-
butOnnx.click(export_onnx, [ckpt_dir, onnx_dir, moevs], infoOnnx)
1841+
butOnnx.click(export_onnx, [ckpt_dir, onnx_dir], infoOnnx)
18431842

18441843
tab_faq = i18n("常见问题解答")
18451844
with gr.TabItem(tab_faq):

infer_pack/onnx_inference.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import numpy as np
44
import soundfile
55

6-
76
class ContentVec:
87
def __init__(self, vec_path="pretrained/vec-768-layer-12.onnx", device=None):
98
print("load model(s) from {}".format(vec_path))
109
if device == "cpu" or device is None:
1110
providers = ["CPUExecutionProvider"]
1211
elif device == "cuda":
1312
providers = ["CUDAExecutionProvider", "CPUExecutionProvider"]
13+
elif device == "dml":
14+
providers = ["DmlExecutionProvider"]
1415
else:
1516
raise RuntimeError("Unsportted Device")
1617
self.model = onnxruntime.InferenceSession(vec_path, providers=providers)
@@ -68,6 +69,8 @@ def __init__(
6869
providers = ["CPUExecutionProvider"]
6970
elif device == "cuda":
7071
providers = ["CUDAExecutionProvider", "CPUExecutionProvider"]
72+
elif device == "dml":
73+
providers = ["DmlExecutionProvider"]
7174
else:
7275
raise RuntimeError("Unsportted Device")
7376
self.model = onnxruntime.InferenceSession(model_path, providers=providers)

0 commit comments

Comments
 (0)