MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / RestoreHashTable

Function RestoreHashTable

tensorflow/core/kernels/save_restore_tensor.cc:569–634  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

567}
568
569void RestoreHashTable(
570 std::function<void(std::function<void()>)> runner,
571 BundleReader* reader, HashTable* table,
572 const std::vector<TensibleVariable*>& tensibles,
573 const string& table_name, const std::vector<string>& tensibles_name,
574 int64 slice_beg, int64 slice_length, int64 slice_size,
575 std::function<void(Status)> done) {
576 LOG(INFO) << "Restore";
577 table->Clear([=](Status st) {
578 if (!st.ok()) {
579 done(st);
580 return;
581 }
582 std::vector<TensorSliceProto> table_slices;
583 std::vector<std::vector<TensorSliceProto>> tensible_slices(tensibles.size());
584 if (tensibles.size() != tensibles_name.size()) {
585 done(errors::FailedPrecondition("Tensible Size is not equal to names"));
586 return;
587 }
588
589 Status res = LookupSliceInfo(
590 reader, table_name, tensibles_name, &table_slices, &tensible_slices);
591 if (!res.ok()) {
592 done(res);
593 return;
594 }
595
596 std::vector<RestoreHashTableSlice> slices;
597 BuildRestoreSlice(table_slices, slice_beg, slice_length, &slices);
598
599 mutex* mu = new mutex;
600 auto insert_table = std::bind(
601 InsertTable, reader, table, tensibles, table_name,
602 tensibles_name, table_slices, tensible_slices, std::placeholders::_1,
603 mu, slice_beg, slice_length, slice_size, nullptr);
604
605 auto after_add_table = [=](Status st) {
606 delete mu;
607 if (!st.ok()) {
608 done(st);
609 return;
610 };
611 std::set<TensibleVariable*> restored_variable(
612 tensibles.begin(), tensibles.end());
613 std::vector<TensibleVariable*> vars = table->Tensibles();
614 StatusCollector* stc = new StatusCollector(vars.size(), done);
615 for (auto&& tensible : vars) {
616 if (restored_variable.find(tensible) != restored_variable.end()) {
617 tensible->Pad(table->Size(), stc->AddStatusFunc());
618 } else {
619 tensible->Resize(table->Size(), stc->AddStatusFunc());
620 }
621 }
622 LOG(INFO) << "Restore Done";
623 stc->Start();
624 };
625 StatusCollector* stc = new StatusCollector(slices.size(), after_add_table);
626 for (auto s : slices) {

Callers 1

ComputeAsyncMethod · 0.85

Calls 15

FailedPreconditionFunction · 0.85
LookupSliceInfoFunction · 0.85
BuildRestoreSliceFunction · 0.85
AddStatusFuncMethod · 0.80
AddStatusMethod · 0.80
ClearMethod · 0.45
okMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45
PadMethod · 0.45

Tested by

no test coverage detected