Skip to content
Closed
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
3 changes: 3 additions & 0 deletions common/arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,9 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
{"-b", "--batch-size"}, "N",
string_format("logical maximum batch size (default: %d)", params.n_batch),
[](common_params & params, int value) {
if (value <= 0) {
throw std::invalid_argument("value must be positive");
}
params.n_batch = value;
}
).set_env("LLAMA_ARG_BATCH"));
Expand Down
4 changes: 2 additions & 2 deletions src/llama-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3665,8 +3665,8 @@ llama_context * llama_init_from_model(
return nullptr;
}

if (params.n_batch == 0 && params.n_ubatch == 0) {
LLAMA_LOG_ERROR("%s: n_batch and n_ubatch cannot both be zero\n", __func__);
if (params.n_batch == 0) {
LLAMA_LOG_ERROR("%s: n_batch cannot be zero\n", __func__);
return nullptr;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/test-arg-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ static void test(void) {
argv = {"binary_name", "-ngl", "hello"};
assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));

// batch-size must be positive
argv = {"binary_name", "--batch-size", "0"};
assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));

argv = {"binary_name", "--batch-size", "-1"};
assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));

// wrong value (enum)
argv = {"binary_name", "-sm", "hello"};
assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
Expand Down