Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正: cpu_num_threadsが未指定または0の場合に、論理コア数の半分をコアに渡すようにする #1113

Merged
merged 6 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ python run.py --output_log_utf8

#### CPU スレッド数を指定する

CPU スレッド数が未指定の場合は、論理コア数の半分か物理コア数が使われます。(殆どの CPU で、これは全体の処理能力の半分です)
CPU スレッド数が未指定の場合は、論理コア数の半分が使われます。(殆どの CPU で、これは全体の処理能力の半分です)
もし IaaS 上で実行していたり、専用サーバーで実行している場合など、
エンジンが使う処理能力を調節したい場合は、CPU スレッド数を指定することで実現できます。

Expand Down
18 changes: 18 additions & 0 deletions test/test_core_utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from unittest import TestCase
from unittest.mock import patch

from voicevox_engine.utility.core_utility import get_half_logical_cores


class TestHalfLogicalCores(TestCase):
@patch("os.cpu_count", return_value=8)
def test_half_logical_cores_even(self, mock_cpu_count):
self.assertEqual(get_half_logical_cores(), 4)

@patch("os.cpu_count", return_value=9)
def test_half_logical_cores_odd(self, mock_cpu_count):
self.assertEqual(get_half_logical_cores(), 4)

@patch("os.cpu_count", return_value=None)
def test_half_logical_cores_none(self, mock_cpu_count):
self.assertEqual(get_half_logical_cores(), 0)
7 changes: 4 additions & 3 deletions voicevox_engine/core/core_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import List, Optional

from ..tts_pipeline.tts_engine import CoreAdapter
from ..utility.core_utility import get_half_logical_cores
from ..utility.path_utility import engine_root, get_save_dir
from .core_wrapper import CoreWrapper, load_runtime_lib

Expand Down Expand Up @@ -35,7 +36,7 @@ def initialize_cores(
None のとき、voicevox_dir、カレントディレクトリになる
cpu_num_threads: int, optional, default=None
音声ライブラリが、推論に用いるCPUスレッド数を設定する
Noneのとき、ライブラリ側の挙動により論理コア数の半分か、物理コア数が指定される
Noneのとき、論理コア数の半分が指定される
enable_mock: bool, optional, default=True
コア読み込みに失敗したとき、代わりにmockを使用するかどうか
load_all_models: bool, optional, default=False
Expand All @@ -44,10 +45,10 @@ def initialize_cores(
if cpu_num_threads == 0 or cpu_num_threads is None:
sigprogramming marked this conversation as resolved.
Show resolved Hide resolved
print(
"Warning: cpu_num_threads is set to 0. "
+ "( The library leaves the decision to the synthesis runtime )",
+ "Setting it to half of the logical cores.",
file=sys.stderr,
)
cpu_num_threads = 0
cpu_num_threads = get_half_logical_cores()

# ディレクトリを設定する
# 引数による指定を反映する
Expand Down
8 changes: 8 additions & 0 deletions voicevox_engine/utility/core_utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os


def get_half_logical_cores() -> int:
logical_cores = os.cpu_count()
if logical_cores is None:
return 0
return logical_cores // 2
Loading