Improve: Convert ONNX version of BERT models to FP16

I have found that half-precision has little effect on speech synthesis quality and, depending on the environment, can reduce file size and memory usage by half, so I have decided to use FP16.
This commit is contained in:
tsukumi
2024-12-19 14:51:30 +09:00
parent b843804a75
commit 15af441cba
2 changed files with 5 additions and 5 deletions

View File

@@ -5,7 +5,7 @@
}, },
"deberta-v2-large-japanese-char-wwm-onnx": { "deberta-v2-large-japanese-char-wwm-onnx": {
"repo_id": "tsukumijima/deberta-v2-large-japanese-char-wwm-onnx", "repo_id": "tsukumijima/deberta-v2-large-japanese-char-wwm-onnx",
"files": ["model.onnx"] "files": ["model_fp16.onnx"]
}, },
"chinese-roberta-wwm-ext-large": { "chinese-roberta-wwm-ext-large": {
"repo_id": "hfl/chinese-roberta-wwm-ext-large", "repo_id": "hfl/chinese-roberta-wwm-ext-large",
@@ -13,7 +13,7 @@
}, },
"chinese-roberta-wwm-ext-large-onnx": { "chinese-roberta-wwm-ext-large-onnx": {
"repo_id": "tsukumijima/chinese-roberta-wwm-ext-large-onnx", "repo_id": "tsukumijima/chinese-roberta-wwm-ext-large-onnx",
"files": ["model.onnx"] "files": ["model_fp16.onnx"]
}, },
"deberta-v3-large": { "deberta-v3-large": {
"repo_id": "microsoft/deberta-v3-large", "repo_id": "microsoft/deberta-v3-large",
@@ -21,6 +21,6 @@
}, },
"deberta-v3-large-onnx": { "deberta-v3-large-onnx": {
"repo_id": "tsukumijima/deberta-v3-large-onnx", "repo_id": "tsukumijima/deberta-v3-large-onnx",
"files": ["spm.model", "model.onnx"] "files": ["spm.model", "model_fp16.onnx"]
} }
} }

View File

@@ -82,7 +82,7 @@ def load_model(
model_path = Path( model_path = Path(
hf_hub_download( hf_hub_download(
repo_id=pretrained_model_name_or_path, repo_id=pretrained_model_name_or_path,
filename="model.onnx", filename="model_fp16.onnx",
cache_dir=cache_dir, cache_dir=cache_dir,
revision=revision, revision=revision,
) )
@@ -99,7 +99,7 @@ def load_model(
# pretrained_model_name_or_path にファイルパスが指定された場合: # pretrained_model_name_or_path にファイルパスが指定された場合:
# 既にダウンロード済みという前提のもと、モデルへのローカルパスを model_path に格納する # 既にダウンロード済みという前提のもと、モデルへのローカルパスを model_path に格納する
else: else:
model_path = Path(pretrained_model_name_or_path).resolve() / "model.onnx" model_path = Path(pretrained_model_name_or_path).resolve() / "model_fp16.onnx"
start_time = time.time() start_time = time.time()
sess_options = onnxruntime.SessionOptions() sess_options = onnxruntime.SessionOptions()