From b3de5207267ac9dfba7f4924de0135bf6b22a45c Mon Sep 17 00:00:00 2001 From: eliranwong Date: Tue, 28 May 2024 08:59:56 +0100 Subject: [PATCH 1/2] accelerate with AMD GPUs --- src/python_run/piper/__main__.py | 8 +++++-- src/python_run/piper/http_server.py | 8 +++++-- src/python_run/piper/voice.py | 34 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/python_run/piper/__main__.py b/src/python_run/piper/__main__.py index 15109f8e..a5bada97 100644 --- a/src/python_run/piper/__main__.py +++ b/src/python_run/piper/__main__.py @@ -48,7 +48,11 @@ def main() -> None: "--noise-w", "--noise_w", type=float, help="Phoneme width noise" ) # - parser.add_argument("--cuda", action="store_true", help="Use GPU") + parser.add_argument("--cuda", action="store_true", help="Use Nvidia GPU") + # + parser.add_argument("--migraphx", action="store_true", help="Use AMD GPU") + # + parser.add_argument("--rocm", action="store_true", help="Use ROCm-enabled GPU") # parser.add_argument( "--sentence-silence", @@ -105,7 +109,7 @@ def main() -> None: args.model, args.config = find_voice(args.model, args.data_dir) # Load voice - voice = PiperVoice.load(args.model, config_path=args.config, use_cuda=args.cuda) + voice = PiperVoice.load(args.model, config_path=args.config, use_cuda=args.cuda, use_rocm=args.rocm, use_migraphx=args.migraphx) synthesize_args = { "speaker_id": args.speaker, "length_scale": args.length_scale, diff --git a/src/python_run/piper/http_server.py b/src/python_run/piper/http_server.py index 84abb566..fa80fb9f 100644 --- a/src/python_run/piper/http_server.py +++ b/src/python_run/piper/http_server.py @@ -33,7 +33,11 @@ def main() -> None: "--noise-w", "--noise_w", type=float, help="Phoneme width noise" ) # - parser.add_argument("--cuda", action="store_true", help="Use GPU") + parser.add_argument("--cuda", action="store_true", help="Use Nvidia GPU") + # + parser.add_argument("--migraphx", action="store_true", help="Use AMD GPU") + # + parser.add_argument("--rocm", action="store_true", help="Use ROCm-enabled GPU") # parser.add_argument( "--sentence-silence", @@ -90,7 +94,7 @@ def main() -> None: args.model, args.config = find_voice(args.model, args.data_dir) # Load voice - voice = PiperVoice.load(args.model, config_path=args.config, use_cuda=args.cuda) + voice = PiperVoice.load(args.model, config_path=args.config, use_cuda=args.cuda, use_rocm=args.rocm, use_migraphx=args.migraphx) synthesize_args = { "speaker_id": args.speaker, "length_scale": args.length_scale, diff --git a/src/python_run/piper/voice.py b/src/python_run/piper/voice.py index 0360c273..66258714 100644 --- a/src/python_run/piper/voice.py +++ b/src/python_run/piper/voice.py @@ -26,6 +26,8 @@ def load( model_path: Union[str, Path], config_path: Optional[Union[str, Path]] = None, use_cuda: bool = False, + use_rocm: bool = False, + use_migraphx: bool = False, ) -> "PiperVoice": """Load an ONNX model and config.""" if config_path is None: @@ -42,6 +44,38 @@ def load( {"cudnn_conv_algo_search": "HEURISTIC"}, ) ] + elif use_rocm: + """ + To support ROCm-enabled GPUs via 'ROCMExecutionProvider' or 'MIGraphXExecutionProvider': + 1. Install piper-tts + > pip install piper-tts + 2. Uninstall onnxruntime + > pip uninstall onnxruntime + 3. Install onnxruntime-rocm + > pip3 install https://repo.radeon.com/rocm/manylinux/rocm-rel-6.0.2/onnxruntime_rocm-inference-1.17.0-cp310-cp310-linux_x86_64.whl + Remarks: Wheel files that support different ROCm versions are available at: https://repo.radeon.com/rocm/manylinux + + To verify: + > python3 + $ onnxruntime + $ onnxruntime.get_available_providers() + Output: + ``` + ['MIGraphXExecutionProvider', 'ROCMExecutionProvider', 'CPUExecutionProvider'] + ``` + + To accelerate with AMD GPUs: + > piper --migraphx + + To accelerate with ROCm-enabled GPUs: + > piper --rocm + + Remarks: Tested on Ubuntu 22.04.4 + Kernel 6.6.32 + ROCm 6.0.2 + Setup notes are available at: https://github.com/eliranwong/MultiAMDGPU_AIDev_Ubuntu/tree/main + """ + providers = ["ROCMExecutionProvider", "CPUExecutionProvider"] + elif use_migraphx: + providers = ["MIGraphXExecutionProvider", "CPUExecutionProvider"] else: providers = ["CPUExecutionProvider"] From e13fb666b5c178ef1463ee382e08ec82eca6a40d Mon Sep 17 00:00:00 2001 From: eliranwong Date: Tue, 28 May 2024 09:45:23 +0100 Subject: [PATCH 2/2] revised notes --- src/python_run/piper/voice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_run/piper/voice.py b/src/python_run/piper/voice.py index 66258714..4a27055b 100644 --- a/src/python_run/piper/voice.py +++ b/src/python_run/piper/voice.py @@ -52,12 +52,12 @@ def load( 2. Uninstall onnxruntime > pip uninstall onnxruntime 3. Install onnxruntime-rocm - > pip3 install https://repo.radeon.com/rocm/manylinux/rocm-rel-6.0.2/onnxruntime_rocm-inference-1.17.0-cp310-cp310-linux_x86_64.whl + > pip3 install https://repo.radeon.com/rocm/manylinux/rocm-rel-6.0.2/onnxruntime_rocm-inference-1.17.0-cp310-cp310-linux_x86_64.whl --no-cache-dir Remarks: Wheel files that support different ROCm versions are available at: https://repo.radeon.com/rocm/manylinux To verify: > python3 - $ onnxruntime + $ import onnxruntime $ onnxruntime.get_available_providers() Output: ```