difacto icon indicating copy to clipboard operation
difacto copied to clipboard

save model

Open jamborta opened this issue 9 years ago • 1 comments

is it possible to save the learnt vector and matrix somehow?

jamborta avatar Aug 05 '16 16:08 jamborta

you can use GetUpdater()->Save(bool save_aux, dmlc::Stream *fo) in such as sgd_learner.cc and Save(bool save_aux, dmlc::Stream *fo) should be implemented first eg: (just a draft)

void SGDUpdater::Save(bool save_aux, dmlc::Stream *fo) const {
  int saved = 0;
  for (const auto& it : model_) {
    if (it.second.Empty()) continue;
    int n = param_.V_dim;
        fo->Write(&it.first, sizeof(feaid_t));
    fo->Write(it.second.w, sizeof(real_t));
    if (it.second.V) {
      for (int i = 0; i < n; ++i) {
        fo->Write(it.second.V[i], sizeof(real_t));
      }
    }
    if (save_aux) {
      fo->Write(&(it.second.z), sizeof(real_t));
      fo->Write(&(it.second.sqrt_g), sizeof(real_t));
    }
    saved ++ ;
  }
  LOG(INFO) << "saved " << saved << " kv pairs";
}

CNevd avatar Aug 06 '16 03:08 CNevd