Skip to content

Commit 7e9c8e0

Browse files
author
Braulio
committed
examples: use -dev/--device and WHISPER_ARG_DEVICE
Align device selection naming with llama.cpp.
1 parent d9b7613 commit 7e9c8e0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

examples/cli/cli.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct whisper_params {
7777
bool log_score = false;
7878
bool use_gpu = true;
7979
bool flash_attn = true;
80+
int32_t gpu_device = 0;
8081
bool suppress_nst = false;
8182
bool carry_initial_prompt = false;
8283

@@ -129,6 +130,10 @@ static char * requires_value_error(const std::string & arg) {
129130
}
130131

131132
static bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
133+
if (const char * env_device = std::getenv("WHISPER_ARG_DEVICE")) {
134+
params.gpu_device = std::stoi(env_device);
135+
}
136+
132137
for (int i = 1; i < argc; i++) {
133138
std::string arg = argv[i];
134139

@@ -195,6 +200,7 @@ static bool whisper_params_parse(int argc, char ** argv, whisper_params & params
195200
else if (arg == "-dtw" || arg == "--dtw") { params.dtw = ARGV_NEXT; }
196201
else if (arg == "-ls" || arg == "--log-score") { params.log_score = true; }
197202
else if (arg == "-ng" || arg == "--no-gpu") { params.use_gpu = false; }
203+
else if (arg == "-dev" || arg == "--device") { params.gpu_device = std::stoi(ARGV_NEXT); }
198204
else if (arg == "-fa" || arg == "--flash-attn") { params.flash_attn = true; }
199205
else if (arg == "-nfa" || arg == "--no-flash-attn") { params.flash_attn = false; }
200206
else if (arg == "-sns" || arg == "--suppress-nst") { params.suppress_nst = true; }
@@ -276,6 +282,7 @@ static void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params
276282
fprintf(stderr, " -dtw MODEL --dtw MODEL [%-7s] compute token-level timestamps\n", params.dtw.c_str());
277283
fprintf(stderr, " -ls, --log-score [%-7s] log best decoder scores of tokens\n", params.log_score?"true":"false");
278284
fprintf(stderr, " -ng, --no-gpu [%-7s] disable GPU\n", params.use_gpu ? "false" : "true");
285+
fprintf(stderr, " -dev N, --device N [%-7d] GPU device ID (default: 0)\n", params.gpu_device);
279286
fprintf(stderr, " -fa, --flash-attn [%-7s] enable flash attention\n", params.flash_attn ? "true" : "false");
280287
fprintf(stderr, " -nfa, --no-flash-attn [%-7s] disable flash attention\n", params.flash_attn ? "false" : "true");
281288
fprintf(stderr, " -sns, --suppress-nst [%-7s] suppress non-speech tokens\n", params.suppress_nst ? "true" : "false");
@@ -1003,6 +1010,7 @@ int main(int argc, char ** argv) {
10031010
struct whisper_context_params cparams = whisper_context_default_params();
10041011

10051012
cparams.use_gpu = params.use_gpu;
1013+
cparams.gpu_device = params.gpu_device;
10061014
cparams.flash_attn = params.flash_attn;
10071015

10081016
if (!params.dtw.empty()) {

examples/server/server.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct whisper_params {
102102
bool no_timestamps = false;
103103
bool use_gpu = true;
104104
bool flash_attn = true;
105+
int32_t gpu_device = 0;
105106
bool suppress_nst = false;
106107
bool no_context = true;
107108
bool no_language_probabilities = false;
@@ -177,6 +178,7 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
177178
fprintf(stderr, " -sns, --suppress-nst [%-7s] suppress non-speech tokens\n", params.suppress_nst ? "true" : "false");
178179
fprintf(stderr, " -nth N, --no-speech-thold N [%-7.2f] no speech threshold\n", params.no_speech_thold);
179180
fprintf(stderr, " -ng, --no-gpu [%-7s] do not use gpu\n", params.use_gpu ? "false" : "true");
181+
fprintf(stderr, " -dev N, --device N [%-7d] GPU device ID (default: 0)\n", params.gpu_device);
180182
fprintf(stderr, " -fa, --flash-attn [%-7s] enable flash attention\n", params.flash_attn ? "true" : "false");
181183
fprintf(stderr, " -nfa, --no-flash-attn [%-7s] disable flash attention\n", params.flash_attn ? "false" : "true");
182184
fprintf(stderr, " -nlp, --no-language-probabilities [%-7s] exclude language probabilities from verbose_json output\n", params.no_language_probabilities ? "true" : "false");
@@ -196,6 +198,10 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
196198
}
197199

198200
bool whisper_params_parse(int argc, char ** argv, whisper_params & params, server_params & sparams) {
201+
if (const char * env_device = std::getenv("WHISPER_ARG_DEVICE")) {
202+
params.gpu_device = std::stoi(env_device);
203+
}
204+
199205
for (int i = 1; i < argc; i++) {
200206
std::string arg = argv[i];
201207

@@ -235,6 +241,7 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params, serve
235241
else if (arg == "-oved" || arg == "--ov-e-device") { params.openvino_encode_device = argv[++i]; }
236242
else if (arg == "-dtw" || arg == "--dtw") { params.dtw = argv[++i]; }
237243
else if (arg == "-ng" || arg == "--no-gpu") { params.use_gpu = false; }
244+
else if (arg == "-dev" || arg == "--device") { params.gpu_device = std::stoi(argv[++i]); }
238245
else if (arg == "-fa" || arg == "--flash-attn") { params.flash_attn = true; }
239246
else if (arg == "-nfa" || arg == "--no-flash-attn") { params.flash_attn = false; }
240247
else if (arg == "-sns" || arg == "--suppress-nst") { params.suppress_nst = true; }
@@ -638,6 +645,7 @@ int main(int argc, char ** argv) {
638645
struct whisper_context_params cparams = whisper_context_default_params();
639646

640647
cparams.use_gpu = params.use_gpu;
648+
cparams.gpu_device = params.gpu_device;
641649
cparams.flash_attn = params.flash_attn;
642650

643651
if (!params.dtw.empty()) {

0 commit comments

Comments
 (0)