Drop saving binary format for memory snapshot. (#6513)
This commit is contained in:
@@ -874,40 +874,16 @@ class LearnerIO : public LearnerConfiguration {
|
||||
}
|
||||
|
||||
void Save(dmlc::Stream* fo) const override {
|
||||
if (generic_parameters_.enable_experimental_json_serialization) {
|
||||
Json memory_snapshot{Object()};
|
||||
memory_snapshot["Model"] = Object();
|
||||
auto &model = memory_snapshot["Model"];
|
||||
this->SaveModel(&model);
|
||||
memory_snapshot["Config"] = Object();
|
||||
auto &config = memory_snapshot["Config"];
|
||||
this->SaveConfig(&config);
|
||||
std::string out_str;
|
||||
Json::Dump(memory_snapshot, &out_str);
|
||||
fo->Write(out_str.c_str(), out_str.size());
|
||||
} else {
|
||||
std::string binary_buf;
|
||||
common::MemoryBufferStream s(&binary_buf);
|
||||
this->SaveModel(&s);
|
||||
Json config{ Object() };
|
||||
// Do not use std::size_t as it's not portable.
|
||||
int64_t const json_offset = binary_buf.size();
|
||||
this->SaveConfig(&config);
|
||||
std::string config_str;
|
||||
Json::Dump(config, &config_str);
|
||||
// concatonate the model and config at final output, it's a temporary solution for
|
||||
// continuing support for binary model format
|
||||
fo->Write(&serialisation_header_[0], serialisation_header_.size());
|
||||
if (DMLC_IO_NO_ENDIAN_SWAP) {
|
||||
fo->Write(&json_offset, sizeof(json_offset));
|
||||
} else {
|
||||
auto x = json_offset;
|
||||
dmlc::ByteSwap(&x, sizeof(x), 1);
|
||||
fo->Write(&x, sizeof(json_offset));
|
||||
}
|
||||
fo->Write(&binary_buf[0], binary_buf.size());
|
||||
fo->Write(&config_str[0], config_str.size());
|
||||
}
|
||||
Json memory_snapshot{Object()};
|
||||
memory_snapshot["Model"] = Object();
|
||||
auto &model = memory_snapshot["Model"];
|
||||
this->SaveModel(&model);
|
||||
memory_snapshot["Config"] = Object();
|
||||
auto &config = memory_snapshot["Config"];
|
||||
this->SaveConfig(&config);
|
||||
std::string out_str;
|
||||
Json::Dump(memory_snapshot, &out_str);
|
||||
fo->Write(out_str.c_str(), out_str.size());
|
||||
}
|
||||
|
||||
void Load(dmlc::Stream* fi) override {
|
||||
|
||||
Reference in New Issue
Block a user