MCPcopy Create free account
hub / github.com/catboost/catboost / TryLoadProgress

Method TryLoadProgress

catboost/private/libs/algo/learn_context.cpp:374–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

372}
373
374bool TLearnContext::TryLoadProgress(std::function<bool(IInputStream*)> onLoadSnapshot) {
375 if (!OutputOptions.SaveSnapshot() || !NFs::Exists(Files.SnapshotFile)) {
376 return false;
377 }
378 try {
379 TProgressHelper(ToString(ETaskType::CPU)).CheckedLoad(
380 Files.SnapshotFile,
381 [&](TIFStream* in) {
382 if (!onLoadSnapshot(in)) {
383 return;
384 }
385 // use progress copy to avoid partial deserialization of corrupted progress file
386 THolder<TLearnProgress> learnProgressRestored = MakeHolder<TLearnProgress>(*LearnProgress);
387 TProfileInfoData ProfileRestored;
388
389 // fail here does nothing with real LearnProgress
390 ::LoadMany(in, *learnProgressRestored, ProfileRestored);
391
392 const bool paramsCompatible = NCatboostOptions::IsParamsCompatible(
393 learnProgressRestored->SerializedTrainParams,
394 LearnProgress->SerializedTrainParams);
395 CATBOOST_DEBUG_LOG
396 << LabeledOutput(learnProgressRestored->SerializedTrainParams) << ' '
397 << LabeledOutput(LearnProgress->SerializedTrainParams) << Endl;
398 CB_ENSURE(paramsCompatible, "Current training params differ from the params saved in snapshot");
399
400 const bool poolCompatible
401 = (learnProgressRestored->LearnAndTestQuantizedFeaturesCheckSum
402 == LearnProgress->LearnAndTestQuantizedFeaturesCheckSum);
403 CB_ENSURE(
404 poolCompatible,
405 "Current learn and test datasets differ from the datasets used for snapshot "
406 << LabeledOutput(learnProgressRestored->LearnAndTestQuantizedFeaturesCheckSum) << ' '
407 << LabeledOutput(LearnProgress->LearnAndTestQuantizedFeaturesCheckSum)
408 );
409
410 LearnProgress = std::move(learnProgressRestored);
411 Profile.InitProfileInfo(std::move(ProfileRestored));
412 LearnProgress->SerializedTrainParams = ToString(Params); // substitute real
413 CATBOOST_INFO_LOG << "Loaded progress file containing " << LearnProgress->TreeStruct.size()
414 << " trees" << Endl;
415 }
416 );
417 return true;
418 } catch(const TCatBoostException& e) {
419 ythrow TCatBoostException() << "Can't load progress from snapshot file: " << Files.SnapshotFile
420 << " : " << e.what();
421 } catch (...) {
422 CATBOOST_WARNING_LOG << "Can't load progress from snapshot file: " << Files.SnapshotFile
423 << " exception: " << CurrentExceptionMessage() << Endl;
424 return false;
425 }
426}
427
428TLearnProgress::TLearnProgress() : Rand(0) {
429}

Callers 1

TrainFunction · 0.80

Calls 10

TProgressHelperClass · 0.85
LoadManyFunction · 0.85
CurrentExceptionMessageFunction · 0.85
SaveSnapshotMethod · 0.80
CheckedLoadMethod · 0.80
InitProfileInfoMethod · 0.80
ToStringFunction · 0.50
moveFunction · 0.50
sizeMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected