| 372 | } |
| 373 | |
| 374 | bool 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 | |
| 428 | TLearnProgress::TLearnProgress() : Rand(0) { |
| 429 | } |
no test coverage detected