Skip to content

Commit a725ee6

Browse files
yxf0314gitlawr
authored andcommitted
fix:Restrict CUDA_VISIBLE_DEVICES environment variable setting to faster-whisper models only.
1 parent 4fc7f7d commit a725ee6

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

vox_box/cmd/start.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from vox_box.config import Config
88
from vox_box.server.model import ModelInstance
99
from vox_box.server.server import Server
10-
from vox_box.utils.model import parse_and_set_cuda_visible_devices
10+
from vox_box.utils.model import preconfigure_faster_whisper_env
1111

1212

1313
logger = logging.getLogger(__name__)
@@ -92,7 +92,7 @@ def run(args: argparse.Namespace):
9292
try:
9393
cfg = parse_args(args)
9494
setup_logging(cfg.debug)
95-
parse_and_set_cuda_visible_devices(cfg)
95+
preconfigure_faster_whisper_env(cfg)
9696

9797
logger.info("Starting with arguments: %s", args._get_kwargs())
9898

vox_box/utils/model.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import logging
22
import os
3+
import re
34
import time
4-
from typing import Dict
5+
from typing import Dict, Optional
56

67
from vox_box.config import Config
78

@@ -24,11 +25,28 @@ def create_model_dict(id: str, **kwargs) -> Dict:
2425
return d
2526

2627

27-
def parse_and_set_cuda_visible_devices(cfg: Config):
28+
def preconfigure_faster_whisper_env(cfg: Config):
2829
"""
29-
Parse CUDA device in format cuda:1 and set CUDA_VISIBLE_DEVICES accordingly.
30+
Due to faster-whisper's problematic handling of device parameters, CUDA_VISIBLE_DEVICES requires special configuration.
31+
There are 3 methods to specify the GPU device for faster-whisper models:
32+
1. Manually set `CUDA_VISIBLE_DEVICES={gpu_index}` and use "--device cuda:0" in CLI parameters.
33+
2. If env `IS_FASTER_WHISPER` is unset AND the model path/name contains "faster-whisper", CUDA_VISIBLE_DEVICES will be set based on the GPU selector's device choice.
34+
3. When `IS_FASTER_WHISPER=True`, CUDA_VISIBLE_DEVICES will be set based on the GPU selector's device choice.
3035
"""
31-
if cfg.device.startswith("cuda:"):
36+
is_faster_whisper: Optional[bool] = None
37+
if os.getenv("IS_FASTER_WHISPER"):
38+
is_faster_whisper = os.getenv("IS_FASTER_WHISPER") in ("true", "1", "yes", "y")
39+
40+
if is_faster_whisper is False:
41+
return
42+
43+
# If unset is_faster_whisper, check if the model name contains "faster-whisper"
44+
if is_faster_whisper is None and re.search(
45+
r"faster.*whisper", cfg.model, re.IGNORECASE
46+
):
47+
is_faster_whisper = True
48+
49+
if is_faster_whisper is True and cfg.device.startswith("cuda:"):
3250
device_index = cfg.device.split(":")[1]
3351
if device_index.isdigit():
3452
os.environ["CUDA_VISIBLE_DEVICES"] = device_index

0 commit comments

Comments
 (0)