Better error message when world size and rank are set as strings (#8316)
Co-authored-by: jiamingy <jm.yuan@outlook.com>
This commit is contained in:
@@ -248,13 +248,23 @@ inline void GenerateFeatureMap(Learner const *learner,
|
||||
|
||||
void XGBBuildInfoDevice(Json* p_info);
|
||||
|
||||
template <typename JT>
|
||||
void TypeCheck(Json const &value, StringView name) {
|
||||
using T = std::remove_const_t<JT> const;
|
||||
if (!IsA<T>(value)) {
|
||||
LOG(FATAL) << "Incorrect type for: `" << name << "`, expecting: `" << T{}.TypeStr()
|
||||
<< "`, got: `" << value.GetValue().TypeStr() << "`.";
|
||||
}
|
||||
}
|
||||
|
||||
template <typename JT>
|
||||
auto const &RequiredArg(Json const &in, std::string const &key, StringView func) {
|
||||
auto const &obj = get<Object const>(in);
|
||||
auto it = obj.find(key);
|
||||
if (it == obj.cend() || IsA<Null>(it->second)) {
|
||||
LOG(FATAL) << "Argument `" << key << "` is required for `" << func << "`";
|
||||
LOG(FATAL) << "Argument `" << key << "` is required for `" << func << "`.";
|
||||
}
|
||||
TypeCheck<JT>(it->second, StringView{key});
|
||||
return get<std::remove_const_t<JT> const>(it->second);
|
||||
}
|
||||
|
||||
@@ -262,7 +272,8 @@ template <typename JT, typename T>
|
||||
auto const &OptionalArg(Json const &in, std::string const &key, T const &dft) {
|
||||
auto const &obj = get<Object const>(in);
|
||||
auto it = obj.find(key);
|
||||
if (it != obj.cend()) {
|
||||
if (it != obj.cend() && !IsA<Null>(it->second)) {
|
||||
TypeCheck<JT>(it->second, StringView{key});
|
||||
return get<std::remove_const_t<JT> const>(it->second);
|
||||
}
|
||||
return dft;
|
||||
|
||||
@@ -17,9 +17,8 @@ class NoOpCommunicator : public Communicator {
|
||||
NoOpCommunicator() : Communicator(1, 0) {}
|
||||
bool IsDistributed() const override { return false; }
|
||||
bool IsFederated() const override { return false; }
|
||||
void AllReduce(void *send_receive_buffer, std::size_t count, DataType data_type,
|
||||
Operation op) override {}
|
||||
void Broadcast(void *send_receive_buffer, std::size_t size, int root) override {}
|
||||
void AllReduce(void *, std::size_t, DataType, Operation) override {}
|
||||
void Broadcast(void *, std::size_t, int) override {}
|
||||
std::string GetProcessorName() override { return ""; }
|
||||
void Print(const std::string &message) override { LOG(CONSOLE) << message; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user