| 139 | } |
| 140 | |
| 141 | void TensorSliceReader::LoadShard(int shard) const { |
| 142 | CHECK_LT(shard, sss_.size()); |
| 143 | if (sss_[shard] || !status_.ok()) { |
| 144 | return; // Already loaded, or invalid. |
| 145 | } |
| 146 | string value; |
| 147 | SavedTensorSlices sts; |
| 148 | const string fname = fnames_[shard]; |
| 149 | VLOG(1) << "Reading meta data from file " << fname << "..."; |
| 150 | Table* table; |
| 151 | Status s = open_function_(fname, &table); |
| 152 | if (!s.ok()) { |
| 153 | status_ = errors::DataLoss("Unable to open table file ", fname, ": ", |
| 154 | s.ToString()); |
| 155 | return; |
| 156 | } |
| 157 | sss_[shard].reset(table); |
| 158 | if (!(table->Get(kSavedTensorSlicesKey, &value) && |
| 159 | ParseProtoUnlimited(&sts, value))) { |
| 160 | status_ = errors::Internal( |
| 161 | "Failed to find the saved tensor slices at the beginning of the " |
| 162 | "checkpoint file: ", |
| 163 | fname); |
| 164 | return; |
| 165 | } |
| 166 | status_ = CheckVersions(sts.meta().versions(), TF_CHECKPOINT_VERSION, |
| 167 | TF_CHECKPOINT_VERSION_MIN_PRODUCER, "Checkpoint", |
| 168 | "checkpoint"); |
| 169 | if (!status_.ok()) return; |
| 170 | for (const SavedSliceMeta& ssm : sts.meta().tensor()) { |
| 171 | TensorShape ssm_shape; |
| 172 | status_ = TensorShape::BuildTensorShapeBase(ssm.shape(), &ssm_shape); |
| 173 | if (!status_.ok()) return; |
| 174 | for (const TensorSliceProto& tsp : ssm.slice()) { |
| 175 | TensorSlice ss_slice; |
| 176 | status_ = TensorSlice::BuildTensorSlice(tsp, &ss_slice); |
| 177 | if (!status_.ok()) return; |
| 178 | status_ = RegisterTensorSlice(ssm.name(), ssm_shape, ssm.type(), fname, |
| 179 | ss_slice, &tensors_); |
| 180 | if (!status_.ok()) return; |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | void TensorSliceReader::LoadAllShards() const { |
| 186 | VLOG(1) << "Loading all shards for " << filepattern_; |
nothing calls this directly
no test coverage detected