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

Method Compute

tensorflow/core/kernels/save_restore_v2_ops.cc:139–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137 }
138
139 void Compute(OpKernelContext* context) override {
140 const Tensor& prefix = context->input(0);
141 const Tensor& tensor_names = context->input(1);
142 const Tensor& shape_and_slices = context->input(2);
143 const int kFixedInputs = 3; // Prefix, tensor names, shape_and_slices.
144 ValidateInputs(true /* is save op */, context, prefix, tensor_names,
145 shape_and_slices, kFixedInputs);
146 if (!context->status().ok()) return;
147
148 const int num_tensors = static_cast<int>(tensor_names.NumElements());
149 const string& prefix_string = prefix.scalar<tstring>()();
150 const auto& tensor_names_flat = tensor_names.flat<tstring>();
151 const auto& shape_and_slices_flat = shape_and_slices.flat<tstring>();
152
153 BundleWriter writer(Env::Default(), prefix_string);
154 OP_REQUIRES_OK(context, writer.status());
155 VLOG(1) << "BundleWriter, prefix_string: " << prefix_string;
156
157 int start_index = 0;
158 if (has_ev_) {
159 start_index = 1;
160 }
161
162 int start_ev_key_index = 0;
163
164 for (int i = start_index; i < num_tensors; ++i) {
165 const string& tensor_name = tensor_names_flat(i);
166 if (tensor_types_[i] == DT_RESOURCE) {
167 auto& handle = HandleFromInput(context, i + kFixedInputs);
168 if (IsHandle<EmbeddingVar<int64, float>>(handle)) {
169 if (ev_key_types_[start_ev_key_index] == DT_INT32) {
170 DumpEvWithGlobalStep<int32, float>(context,
171 i + kFixedInputs, tensor_name, writer, tensor_types_[0]);
172 } else if (ev_key_types_[start_ev_key_index] == DT_INT64) {
173 DumpEvWithGlobalStep<int64, float>(context,
174 i + kFixedInputs, tensor_name, writer, tensor_types_[0]);
175 }
176 } else if (IsHandle<HashTableResource>(handle)) {
177 auto handles = context->input(i + kFixedInputs).flat<ResourceHandle>();
178 int tensible_size = handles.size() - 1;
179 std::vector<core::ScopedUnref> unrefs;
180 HashTable* hashtable;
181 std::vector<TensibleVariable*> tensibles;
182
183 HashTableResource* htr;
184 OP_REQUIRES_OK(context,
185 LookupResource(context, handles(0), &htr));
186 unrefs.emplace_back(htr);
187 hashtable = htr->Internal();
188
189 for (int j = 0; j < tensible_size; j++) {
190 TensibleVariableResource* tvr;
191 OP_REQUIRES_OK(context,
192 LookupResource(context, handles(j + 1), &tvr));
193 unrefs.emplace_back(tvr);
194 tensibles.push_back(tvr->Internal());
195 }
196

Callers

nothing calls this directly

Calls 15

DefaultFunction · 0.85
HandleFromInputFunction · 0.85
LookupResourceFunction · 0.85
handlesClass · 0.85
ParseShapeAndSliceFunction · 0.85
InvalidArgumentFunction · 0.85
SaveHashTableFunction · 0.85
SaveBloomFilterFunction · 0.85
AddSliceMethod · 0.80
ValidateInputsFunction · 0.70
SplitClass · 0.70
inputMethod · 0.45

Tested by

no test coverage detected