Improve parameter validation (#6769)

* Add quotes to unused parameters.
* Check for whitespace.
This commit is contained in:
Jiaming Yuan
2021-03-20 01:56:55 +08:00
committed by GitHub
parent 23b4165a6b
commit f6fe15d11f
3 changed files with 14 additions and 7 deletions

View File

@@ -537,15 +537,18 @@ class LearnerConfiguration : public Learner {
}
}
// FIXME(trivialfis): Make eval_metric a training parameter.
keys.emplace_back(kEvalMetric);
keys.emplace_back("verbosity");
keys.emplace_back("num_output_group");
std::sort(keys.begin(), keys.end());
std::vector<std::string> provided;
for (auto const &kv : cfg_) {
// FIXME(trivialfis): Make eval_metric a training parameter.
if (std::any_of(kv.first.cbegin(), kv.first.cend(),
[](char ch) { return std::isspace(ch); })) {
LOG(FATAL) << "Invalid parameter \"" << kv.first << "\" contains whitespace.";
}
provided.push_back(kv.first);
}
std::sort(provided.begin(), provided.end());
@@ -557,9 +560,9 @@ class LearnerConfiguration : public Learner {
std::stringstream ss;
ss << "\nParameters: { ";
for (size_t i = 0; i < diff.size() - 1; ++i) {
ss << diff[i] << ", ";
ss << "\"" << diff[i] << "\", ";
}
ss << diff.back();
ss << "\"" << diff.back() << "\"";
ss << R"W( } might not be used.
This may not be accurate due to some parameters are only used in language bindings but