| 610 | } |
| 611 | |
| 612 | void Compute(OpKernelContext* context) override { |
| 613 | const Tensor& prefix = context->input(0); |
| 614 | const Tensor& tensor_names = context->input(1); |
| 615 | const Tensor& shape_and_slices = context->input(2); |
| 616 | OP_REQUIRES(context, tensor_names.NumElements() == dtypes_.size(), |
| 617 | errors::InvalidArgument("Got ", tensor_names.NumElements(), |
| 618 | " tensor names, but ", dtypes_.size(), |
| 619 | " expected dtypes.")); |
| 620 | ValidateInputs(false /* not save op */, context, prefix, tensor_names, |
| 621 | shape_and_slices, |
| 622 | 3 /*Prefix, tensor names, shape_and_slices.*/); |
| 623 | if (!context->status().ok()) return; |
| 624 | |
| 625 | const string& prefix_string = prefix.scalar<tstring>()(); |
| 626 | |
| 627 | // Intention: we plan to use the RestoreV2 op as a backward-compatible |
| 628 | // reader as we upgrade to the V2 format. This allows transparent upgrade. |
| 629 | // We here attempt to read a V1 checkpoint, if "prefix_string" does not |
| 630 | // refer to a V2 checkpoint. |
| 631 | Env* env = Env::Default(); |
| 632 | std::vector<string> paths; |
| 633 | if (!env->GetMatchingPaths(MetaFilename(prefix_string), &paths).ok() || |
| 634 | paths.empty()) { |
| 635 | // Cannot find V2's metadata file, so "prefix_string" does not point to a |
| 636 | // V2 checkpoint. Invokes the V1 read path instead. |
| 637 | for (size_t i = 0; i < tensor_names.NumElements(); ++i) { |
| 638 | RestoreTensor(context, &checkpoint::OpenTableTensorSliceReader, |
| 639 | /* preferred_shard */ -1, /* restore_slice */ true, |
| 640 | /* restore_index */ i); |
| 641 | if (!context->status().ok()) { |
| 642 | return; |
| 643 | } |
| 644 | } |
| 645 | return; |
| 646 | } |
| 647 | // If found, invokes the V2 reader. |
| 648 | OP_REQUIRES_OK(context, RestoreTensorsV2(context, prefix, tensor_names, |
| 649 | shape_and_slices, dtypes_)); |
| 650 | } |
| 651 | |
| 652 | private: |
| 653 | // Expected dtypes of the to-restore tensors. |
nothing calls this directly
no test coverage detected