mirror of
https://github.com/zebrajr/tensorflow.git
synced 2025-12-07 00:20:20 +01:00
Replace protobuf CopyFrom with assignment
PiperOrigin-RevId: 157534272
This commit is contained in:
parent
96698f7fdc
commit
9501c41041
|
|
@ -2253,7 +2253,7 @@ static bool ExtendSessionGraphHelper(TF_Session* session, TF_Status* status) {
|
|||
const auto num_nodes = graph.num_node_ids();
|
||||
if (session->last_num_graph_nodes < num_nodes) {
|
||||
GraphDef graph_def;
|
||||
graph_def.mutable_versions()->CopyFrom(graph.versions());
|
||||
*graph_def.mutable_versions() = graph.versions();
|
||||
// Fill graph_def with nodes with ids in the range
|
||||
// [session->last_num_graph_nodes, num_nodes), that is the nodes
|
||||
// added since the last TF_SessionRun() call.
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ Status ConvertSessionBundleToSavedModelBundle(
|
|||
saved_model_bundle->session = std::move(session_bundle.session);
|
||||
|
||||
// Copy the meta graph def from the SessionBundle to the SavedModelBundle.
|
||||
saved_model_bundle->meta_graph_def.CopyFrom(session_bundle.meta_graph_def);
|
||||
saved_model_bundle->meta_graph_def = session_bundle.meta_graph_def;
|
||||
|
||||
// Convert signatures from session-bundle to signature-defs in
|
||||
// saved-model-bundle.
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ GraphTransferUtils::BuildRemoteFusedGraphExecuteInfo(
|
|||
execute_info.set_executor_name("build_hexagon_remote_fused_graph_executor");
|
||||
|
||||
// copy graph
|
||||
execute_info.mutable_remote_graph()->CopyFrom(graph_def);
|
||||
*execute_info.mutable_remote_graph() = graph_def;
|
||||
|
||||
for (const std::pair<string, Tensor>& input : inputs) {
|
||||
execute_info.add_graph_input_node_name(input.first);
|
||||
|
|
|
|||
|
|
@ -405,7 +405,7 @@ static void VersionTest(const VersionDef& versions, const string& error) {
|
|||
{
|
||||
// Prepare an empty checkpoint with some version information
|
||||
SavedTensorSlices sts;
|
||||
sts.mutable_meta()->mutable_versions()->CopyFrom(versions);
|
||||
*sts.mutable_meta()->mutable_versions() = versions;
|
||||
string contents;
|
||||
EXPECT_TRUE(sts.SerializeToString(&contents));
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ Status FoldBatchNorms(const GraphDef& input_graph_def,
|
|||
new_nodes->push_back(input_node);
|
||||
|
||||
NodeDef new_conv_node;
|
||||
new_conv_node.CopyFrom(conv_node);
|
||||
new_conv_node = conv_node;
|
||||
new_conv_node.set_name(mul_node.name());
|
||||
new_nodes->push_back(new_conv_node);
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ Status ReplaceSendRecvs(const GraphDef& original_graph_def,
|
|||
}
|
||||
}
|
||||
NodeDef new_node;
|
||||
new_node.CopyFrom(node);
|
||||
new_node = node;
|
||||
new_node.mutable_input()->Clear();
|
||||
for (const string& old_input : node.input()) {
|
||||
string input_prefix;
|
||||
|
|
@ -84,12 +84,12 @@ Status ReplaceSendRecvs(const GraphDef& original_graph_def,
|
|||
string removed_node_name = entry.second;
|
||||
const NodeDef* removed_node = original_map[removed_node_name];
|
||||
NodeDef new_node;
|
||||
new_node.CopyFrom(*removed_node);
|
||||
new_node = *removed_node;
|
||||
nodes_to_add.push_back(new_node);
|
||||
}
|
||||
|
||||
for (const NodeDef& node : nodes_to_add) {
|
||||
output_graph_def->mutable_node()->Add()->CopyFrom(node);
|
||||
*output_graph_def->mutable_node()->Add() = node;
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ Status FreezeRequantizationRanges(const GraphDef& input_graph_def,
|
|||
inputs_to_rename[node.name() + ":1"] = max_node->name() + ":0";
|
||||
} else {
|
||||
NodeDef* new_node = frozen_graph_def.mutable_node()->Add();
|
||||
new_node->CopyFrom(node);
|
||||
*new_node = node;
|
||||
}
|
||||
}
|
||||
return RenameNodeInputs(frozen_graph_def, inputs_to_rename,
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ Status InsertLogging(const GraphDef& input_graph_def,
|
|||
GraphDef logged_graph_def;
|
||||
for (const NodeDef& node : input_graph_def.node()) {
|
||||
NodeDef* new_node = logged_graph_def.mutable_node()->Add();
|
||||
new_node->CopyFrom(node);
|
||||
*new_node = node;
|
||||
if (node_outputs[node.name()].empty()) {
|
||||
// There were no outputs found to this node, so skip it.
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -337,15 +337,14 @@ Status QuantizePlaceholders(const GraphDef& input_graph_def,
|
|||
placeholder_graph_def.Clear();
|
||||
for (const NodeDef& node : input_graph_def.node()) {
|
||||
if (node.op() != "Placeholder") {
|
||||
(placeholder_graph_def.mutable_node()->Add())->CopyFrom(node);
|
||||
*(placeholder_graph_def.mutable_node()->Add()) = node;
|
||||
} else {
|
||||
string namespace_prefix = node.name() + "_eightbit";
|
||||
|
||||
NodeDef quantized_placeholder;
|
||||
quantized_placeholder.CopyFrom(node);
|
||||
quantized_placeholder = node;
|
||||
SetNodeAttr("dtype", DT_QUINT8, &quantized_placeholder);
|
||||
(placeholder_graph_def.mutable_node()->Add())
|
||||
->CopyFrom(quantized_placeholder);
|
||||
*(placeholder_graph_def.mutable_node()->Add()) = quantized_placeholder;
|
||||
|
||||
NodeDef min_node;
|
||||
min_node.set_op("Const");
|
||||
|
|
@ -354,7 +353,7 @@ Status QuantizePlaceholders(const GraphDef& input_graph_def,
|
|||
Tensor min_tensor(DT_FLOAT, {});
|
||||
min_tensor.flat<float>()(0) = input_min;
|
||||
SetNodeTensorAttr<float>("value", min_tensor, &min_node);
|
||||
(placeholder_graph_def.mutable_node()->Add())->CopyFrom(min_node);
|
||||
*(placeholder_graph_def.mutable_node()->Add()) = min_node;
|
||||
|
||||
NodeDef max_node;
|
||||
max_node.set_op("Const");
|
||||
|
|
@ -363,7 +362,7 @@ Status QuantizePlaceholders(const GraphDef& input_graph_def,
|
|||
Tensor max_tensor(DT_FLOAT, {});
|
||||
max_tensor.flat<float>()(0) = input_max;
|
||||
SetNodeTensorAttr<float>("value", max_tensor, &max_node);
|
||||
(placeholder_graph_def.mutable_node()->Add())->CopyFrom(max_node);
|
||||
*(placeholder_graph_def.mutable_node()->Add()) = max_node;
|
||||
|
||||
const string rename_suffix = "__RENAMED_PLACEHOLDER__";
|
||||
NodeDef dequantize_node;
|
||||
|
|
@ -374,7 +373,7 @@ Status QuantizePlaceholders(const GraphDef& input_graph_def,
|
|||
AddNodeInput(node.name() + rename_suffix, &dequantize_node);
|
||||
AddNodeInput(min_node.name(), &dequantize_node);
|
||||
AddNodeInput(max_node.name(), &dequantize_node);
|
||||
(placeholder_graph_def.mutable_node()->Add())->CopyFrom(dequantize_node);
|
||||
*(placeholder_graph_def.mutable_node()->Add()) = dequantize_node;
|
||||
|
||||
// First make sure that any internal references to the old placeholder
|
||||
// now point to the dequantize result.
|
||||
|
|
@ -519,7 +518,7 @@ Status MergeAdjacentRequantizes(const GraphDef& input_graph_def,
|
|||
new_nodes->push_back(fake_requantize_max_node);
|
||||
|
||||
NodeDef requantize_node;
|
||||
requantize_node.CopyFrom(fake_requantize_node);
|
||||
requantize_node = fake_requantize_node;
|
||||
requantize_node.mutable_input()->Clear();
|
||||
AddNodeInput(original_op_node.name() + ":0", &requantize_node);
|
||||
AddNodeInput(original_op_node.name() + ":1", &requantize_node);
|
||||
|
|
@ -568,7 +567,7 @@ Status HoistFakeQuants(const GraphDef& input_graph_def,
|
|||
current_match = current_match.inputs[0];
|
||||
}
|
||||
NodeDef new_fake_quant_node;
|
||||
new_fake_quant_node.CopyFrom(fake_quant_node);
|
||||
new_fake_quant_node = fake_quant_node;
|
||||
new_fake_quant_node.set_name(fake_quant_node.name() + "_hoisted");
|
||||
new_fake_quant_node.set_input(
|
||||
0, linear_nodes[linear_nodes.size() - 2].input(0));
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ Status RemoveAttribute(const GraphDef& input_graph_def,
|
|||
output_graph_def->Clear();
|
||||
for (const NodeDef& node : input_graph_def.node()) {
|
||||
NodeDef* new_node = output_graph_def->mutable_node()->Add();
|
||||
new_node->CopyFrom(node);
|
||||
*new_node = node;
|
||||
if (((op_name == "*") || (op_name == node.op())) &&
|
||||
(node.attr().count(attribute_name))) {
|
||||
new_node->mutable_attr()->erase(attribute_name);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ Status RemoveDevice(const GraphDef& input_graph_def,
|
|||
output_graph_def->Clear();
|
||||
for (const NodeDef& node : input_graph_def.node()) {
|
||||
NodeDef* new_node = output_graph_def->mutable_node()->Add();
|
||||
new_node->CopyFrom(node);
|
||||
*new_node = node;
|
||||
new_node->set_device("");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ Status RenameAttribute(const GraphDef& input_graph_def,
|
|||
output_graph_def->Clear();
|
||||
for (const NodeDef& node : input_graph_def.node()) {
|
||||
NodeDef* new_node = output_graph_def->mutable_node()->Add();
|
||||
new_node->CopyFrom(node);
|
||||
*new_node = node;
|
||||
if (((op_name == "*") || (op_name == node.op())) &&
|
||||
(node.attr().count(old_attribute_name))) {
|
||||
AttrValue attribute_value = node.attr().at(old_attribute_name);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ Status RenameOp(const GraphDef& input_graph_def,
|
|||
output_graph_def->Clear();
|
||||
for (const NodeDef& node : input_graph_def.node()) {
|
||||
NodeDef* new_node = output_graph_def->mutable_node()->Add();
|
||||
new_node->CopyFrom(node);
|
||||
*new_node = node;
|
||||
if (node.op() == old_op_name) {
|
||||
new_node->set_op(new_op_name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ Status SetDevice(const GraphDef& input_graph_def,
|
|||
output_graph_def->Clear();
|
||||
for (const NodeDef& node : input_graph_def.node()) {
|
||||
NodeDef* new_node = output_graph_def->mutable_node()->Add();
|
||||
new_node->CopyFrom(node);
|
||||
*new_node = node;
|
||||
if (!if_default || (node.device().empty())) {
|
||||
new_node->set_device(new_device);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ Status StripUnusedNodes(const GraphDef& input_graph_def,
|
|||
if (input_nodes.count(node.name())) {
|
||||
NodeDef placeholder_node;
|
||||
if (node.op() == "Placeholder") {
|
||||
placeholder_node.CopyFrom(node);
|
||||
placeholder_node = node;
|
||||
} else {
|
||||
placeholder_node.set_op("Placeholder");
|
||||
placeholder_node.set_name(node.name());
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ Status TransformGraph(const std::vector<string>& inputs,
|
|||
}
|
||||
}
|
||||
// Copy over the library from the original input graph.
|
||||
transformed_graph_def.mutable_library()->CopyFrom(graph_def->library());
|
||||
*transformed_graph_def.mutable_library() = graph_def->library();
|
||||
TF_RETURN_IF_ERROR(IsGraphValid(transformed_graph_def));
|
||||
|
||||
*graph_def = transformed_graph_def;
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ void CopyNodeAttr(const NodeDef& source, const string& source_key,
|
|||
const string& dest_key, NodeDef* dest) {
|
||||
CHECK_NE(0, source.attr().count(source_key))
|
||||
<< "No key '" << source_key << "' found in " << source.DebugString();
|
||||
(*(dest->mutable_attr()))[dest_key].CopyFrom(source.attr().at(source_key));
|
||||
(*(dest->mutable_attr()))[dest_key] = source.attr().at(source_key);
|
||||
}
|
||||
|
||||
Tensor GetNodeTensorAttr(const NodeDef& node, const string& key) {
|
||||
|
|
@ -162,7 +162,7 @@ void FilterGraphDef(const GraphDef& input_graph_def,
|
|||
output_graph_def->mutable_node()->Clear();
|
||||
for (const NodeDef& node : input_graph_def.node()) {
|
||||
if (selector(node)) {
|
||||
output_graph_def->mutable_node()->Add()->CopyFrom(node);
|
||||
*output_graph_def->mutable_node()->Add() = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -173,7 +173,7 @@ void RemoveAttributes(const GraphDef& input_graph_def,
|
|||
output_graph_def->mutable_node()->Clear();
|
||||
for (const NodeDef& node : input_graph_def.node()) {
|
||||
NodeDef* new_node = output_graph_def->mutable_node()->Add();
|
||||
new_node->CopyFrom(node);
|
||||
*new_node = node;
|
||||
for (const string& attribute : attributes) {
|
||||
new_node->mutable_attr()->erase(attribute);
|
||||
}
|
||||
|
|
@ -237,7 +237,7 @@ Status SortByExecutionOrder(const GraphDef& input_graph_def,
|
|||
ready.pop_back();
|
||||
++processed;
|
||||
const NodeDef& node_def(input_graph_def.node(o));
|
||||
output_graph_def->mutable_node()->Add()->CopyFrom(node_def);
|
||||
*output_graph_def->mutable_node()->Add() = node_def;
|
||||
|
||||
// Update pending_count for outputs.
|
||||
for (size_t i = 0; i < outputs[o].size(); ++i) {
|
||||
|
|
@ -446,18 +446,18 @@ Status ReplaceMatchingOpTypes(
|
|||
MatchedNodesAsArray(*match, &old_nodes);
|
||||
for (const NodeDef& old_node : old_nodes) {
|
||||
NodeDef* added_node = output_graph_def->mutable_node()->Add();
|
||||
added_node->CopyFrom(old_node);
|
||||
*added_node = old_node;
|
||||
}
|
||||
} else {
|
||||
for (const NodeDef& new_node : new_nodes) {
|
||||
NodeDef* added_node = output_graph_def->mutable_node()->Add();
|
||||
added_node->CopyFrom(new_node);
|
||||
*added_node = new_node;
|
||||
}
|
||||
}
|
||||
} else if (!matched_nodes.count(input_node.name())) {
|
||||
// This node isn't part of any match, so just copy it over.
|
||||
NodeDef* added_node = output_graph_def->mutable_node()->Add();
|
||||
added_node->CopyFrom(input_node);
|
||||
*added_node = input_node;
|
||||
} else {
|
||||
// Do nothing, because this is an internal part of a matching subgraph,
|
||||
// and so will have been replaced by a new replacement subgraph.
|
||||
|
|
@ -481,7 +481,7 @@ Status RenameNodeInputs(const GraphDef& input_graph_def,
|
|||
output_graph_def->Clear();
|
||||
for (const NodeDef& node : input_graph_def.node()) {
|
||||
NodeDef* new_node = output_graph_def->mutable_node()->Add();
|
||||
new_node->CopyFrom(node);
|
||||
*new_node = node;
|
||||
new_node->mutable_input()->Clear();
|
||||
for (const string& input_name : node.input()) {
|
||||
std::set<string> already_visited;
|
||||
|
|
|
|||
|
|
@ -438,7 +438,7 @@ class TransformUtilsTest : public ::testing::Test {
|
|||
const std::set<string>& output_nodes,
|
||||
std::vector<NodeDef>* new_nodes) {
|
||||
NodeDef original_copy;
|
||||
original_copy.CopyFrom(match.node);
|
||||
original_copy = match.node;
|
||||
const string original_name = match.node.name();
|
||||
original_copy.set_name(original_name + "_before_identity");
|
||||
new_nodes->push_back(original_copy);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user