move duplication check to test-arg-parser
This commit is contained in:
parent
056822ec4f
commit
b5dd43555a
2 changed files with 13 additions and 10 deletions
|
@ -673,17 +673,8 @@ std::vector<llama_arg> gpt_params_parser_init(gpt_params & params, llama_example
|
||||||
* - if LLAMA_EXAMPLE_* is set (other than COMMON), we only show the option in the corresponding example
|
* - if LLAMA_EXAMPLE_* is set (other than COMMON), we only show the option in the corresponding example
|
||||||
* - if both {LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_*,} are set, we will prioritize the LLAMA_EXAMPLE_* matching current example
|
* - if both {LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_*,} are set, we will prioritize the LLAMA_EXAMPLE_* matching current example
|
||||||
*/
|
*/
|
||||||
std::unordered_set<std::string> seen_args;
|
|
||||||
auto add_opt = [&](llama_arg arg) {
|
auto add_opt = [&](llama_arg arg) {
|
||||||
if (arg.in_example(ex) || arg.in_example(LLAMA_EXAMPLE_COMMON)) {
|
if (arg.in_example(ex) || arg.in_example(LLAMA_EXAMPLE_COMMON)) {
|
||||||
// make sure there is no argument duplications
|
|
||||||
for (const auto & a : arg.args) {
|
|
||||||
if (seen_args.find(a) == seen_args.end()) {
|
|
||||||
seen_args.insert(a);
|
|
||||||
} else {
|
|
||||||
throw std::runtime_error(format("found duplicated argument in source code: %s", a));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
options.push_back(std::move(arg));
|
options.push_back(std::move(arg));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#undef NDEBUG
|
#undef NDEBUG
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
@ -13,7 +14,18 @@ int main(void) {
|
||||||
printf("test-arg-parser: make sure there is no duplicated arguments in any examples\n\n");
|
printf("test-arg-parser: make sure there is no duplicated arguments in any examples\n\n");
|
||||||
for (int ex = 0; ex < LLAMA_EXAMPLE_COUNT; ex++) {
|
for (int ex = 0; ex < LLAMA_EXAMPLE_COUNT; ex++) {
|
||||||
try {
|
try {
|
||||||
gpt_params_parser_init(params, (enum llama_example)ex);
|
auto options = gpt_params_parser_init(params, (enum llama_example)ex);
|
||||||
|
std::unordered_set<std::string> seen_args;
|
||||||
|
for (const auto & opt : options) {
|
||||||
|
for (const auto & arg : opt.args) {
|
||||||
|
if (seen_args.find(arg) == seen_args.end()) {
|
||||||
|
seen_args.insert(arg);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "test-arg-parser: found different handlers for the same argument: %s", arg);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
printf("%s\n", e.what());
|
printf("%s\n", e.what());
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue