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

Method AddSlice

tensorflow/core/util/tensor_bundle/tensor_bundle.cc:462–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460}
461
462Status BundleWriter::AddSlice(StringPiece full_tensor_key,
463 const TensorShape& full_tensor_shape,
464 const TensorSlice& slice_spec,
465 const Tensor& slice_tensor) {
466 if (!status_.ok()) return status_;
467 CHECK_NE(full_tensor_key, kHeaderEntryKey);
468
469 // If just a singleton full slice, use the regular Add() to be more efficient.
470 if (IsFullSlice(slice_spec, full_tensor_shape)) {
471 return Add(full_tensor_key, slice_tensor);
472 }
473
474 // Inserts/updates the full tensor's metadata entry.
475 //
476 // In the case of a sharded save, MergeBundles() is responsible for merging
477 // the "slices" field of multiple metadata entries corresponding to the same
478 // full tensor.
479 const string full_tensor_key_string(full_tensor_key);
480 BundleEntryProto* full_entry = &entries_[full_tensor_key_string];
481 if (full_entry->dtype() != DT_INVALID) {
482 CHECK_EQ(full_entry->dtype(), slice_tensor.dtype());
483 }
484 if (full_entry->has_shape()) {
485 CHECK(TensorShape(full_entry->shape()) == full_tensor_shape);
486 }
487
488 // Populates dtype, shape, and slices. Intentionally leaving out shard_id and
489 // offset, which do not make sense for this full tensor entry.
490 full_entry->set_dtype(slice_tensor.dtype());
491 full_tensor_shape.AsProto(full_entry->mutable_shape());
492 TensorSliceProto* slice_proto = full_entry->add_slices();
493 slice_spec.AsProto(slice_proto);
494
495 // The slice itself is handled by a regular Add(), which includes adding its
496 // own metadata entry, and writing out the slice's values.
497 const string slice_name =
498 checkpoint::EncodeTensorNameSlice(full_tensor_key_string, slice_spec);
499 status_ = Add(slice_name, slice_tensor);
500 return status_;
501}
502
503Status BundleWriter::AddTensorHeader(StringPiece key, DataType dtype) {
504 if (!status_.ok()) return status_;

Callers 5

TestReadTensorSliceMethod · 0.80
ComputeMethod · 0.80
ComputeMethod · 0.80
ComputeMethod · 0.80
TESTFunction · 0.80

Calls 11

IsFullSliceFunction · 0.85
EncodeTensorNameSliceFunction · 0.85
has_shapeMethod · 0.80
AddFunction · 0.50
TensorShapeClass · 0.50
okMethod · 0.45
dtypeMethod · 0.45
shapeMethod · 0.45
set_dtypeMethod · 0.45
AsProtoMethod · 0.45
mutable_shapeMethod · 0.45

Tested by 2

TestReadTensorSliceMethod · 0.64
TESTFunction · 0.64