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

Method RemoveNodesInternal

tensorflow/core/grappler/utils/graph_view.cc:1288–1372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1286}
1287
1288void MutableGraphView::RemoveNodesInternal(
1289 const std::vector<RenamedOrOverwrittenNode>& renamed_nodes,
1290 const std::vector<bool>& overwritten_name_removed_nodes) {
1291 // Get all nodes overwritten by renamed nodes and remove their fanins.
1292 std::vector<int> overwritten_nodes;
1293 overwritten_nodes.reserve(renamed_nodes.size());
1294 for (const auto& renamed : renamed_nodes) {
1295 if (renamed.overwritten_node_index_ != internal::kMissingIndex) {
1296 auto& node = nodes_[renamed.overwritten_node_index_];
1297 RemoveAllFaninFanoutInternal(&node);
1298 overwritten_nodes.emplace_back(renamed.overwritten_node_index_);
1299 }
1300 }
1301
1302 // Get all nodes explicitly marked for removal and remove their fanins.
1303 std::vector<int> node_indices_to_remove;
1304 node_indices_to_remove.reserve(mutation_.updated_nodes_.size() +
1305 overwritten_nodes.size());
1306 for (int i = 0; i < mutation_.removed_nodes_.size(); ++i) {
1307 if (mutation_.removed_nodes_[i]) {
1308 auto& node = nodes_[i];
1309 RemoveAllFaninFanoutInternal(&node);
1310 node_indices_to_remove.push_back(i);
1311 if (!overwritten_name_removed_nodes[i]) {
1312 node_index_by_name_.erase(node.GetName());
1313 }
1314 }
1315 }
1316 node_indices_to_remove.insert(node_indices_to_remove.end(),
1317 overwritten_nodes.begin(),
1318 overwritten_nodes.end());
1319 std::set<int> sorted_node_indices_to_remove(node_indices_to_remove.begin(),
1320 node_indices_to_remove.end());
1321
1322 // Iterate in descending order so indices stay consistent.
1323 for (auto rit = sorted_node_indices_to_remove.rbegin();
1324 rit != sorted_node_indices_to_remove.rend(); ++rit) {
1325 const int removed_node_index = *rit;
1326 MutableNodeView& last_node = nodes_.back();
1327 if (last_node.node_index_ > removed_node_index) {
1328 last_node.node_index_ = removed_node_index;
1329 for (auto& regular_fanin : last_node.regular_fanins_) {
1330 // Update fanouts of regular fanins with new index.
1331 regular_fanin.node_view()
1332 ->regular_fanouts_by_port_[regular_fanin.index()]
1333 [regular_fanin.fanout_index_]
1334 .node_index_ = removed_node_index;
1335 }
1336 for (auto& controlling_fanin : last_node.controlling_fanins_) {
1337 // Update fanouts of controlling fanins with new index.
1338 controlling_fanin.node_view()
1339 ->controlled_fanouts_[controlling_fanin.fanout_index_]
1340 .node_index_ = removed_node_index;
1341 }
1342 for (auto& regular_fanouts : last_node.regular_fanouts_by_port_) {
1343 for (auto& regular_fanout : regular_fanouts) {
1344 // Update fanins of regular fanouts.
1345 MutableNodeView* fanout_node_view = regular_fanout.node_view();

Callers

nothing calls this directly

Calls 15

graphFunction · 0.85
rbeginMethod · 0.80
rendMethod · 0.80
node_viewMethod · 0.80
pop_backMethod · 0.80
reserveMethod · 0.45
sizeMethod · 0.45
emplace_backMethod · 0.45
push_backMethod · 0.45
eraseMethod · 0.45
GetNameMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected