Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions torch/csrc/jit/passes/constant_pooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ void ConstantPooling(
continue;
}

auto first_node = node->owningGraph()->block()->nodes().front();
if (node != first_node)
node->moveBefore(first_node);

// Check whether the same constant already exists.
auto subit = constants.insert(node);
if (!subit.second) {
// constant exists, replace the uses of node, and destroy it.
auto existing = *subit.first;
node->replaceAllUsesWith(existing);
node->destroy();
continue;
}

// Move the constant definition to the beginning of the graph.
auto first_node = node->owningGraph()->block()->nodes().front();
if (node != first_node)
node->moveBefore(first_node);
}
}

Expand Down