mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-24 23:54:56 +08:00
Remove unused subgraph vmap api (#52512)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52512 This API is not used at all, and is tricky to maintain. When we were using it last we ran into lifetime issues when using `Value *` as the key. In hind sight, we should have been using `value->unique()`, but regardless, this not being used and should be removed. Test Plan: Imported from OSS Reviewed By: navahgar Differential Revision: D26696695 Pulled By: eellison fbshipit-source-id: 97ed92e88ecab0085fabbac46573611666bf2420
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b1284cfbfb
commit
dbbe21dfd7
@ -38,61 +38,6 @@ TEST(SubgraphUtilsTest, Basic) {
|
||||
ASSERT_EQ(originalNodes.size(), newNodes.size());
|
||||
}
|
||||
|
||||
TEST(SubgraphUtilsTest, Vmap) {
|
||||
auto graph = std::make_shared<Graph>();
|
||||
|
||||
std::unordered_map<std::string, Value*> parse_map;
|
||||
parseIR(
|
||||
R"IR(
|
||||
graph(%a : Tensor, %b : Tensor, %c : Tensor):
|
||||
%x : Tensor = aten::tanh(%a)
|
||||
%y : Tensor = aten::mul(%a, %b)
|
||||
|
||||
%p : Tensor = aten::div(%c, %b)
|
||||
%q : Tensor = aten::mul(%p, %a)
|
||||
return (%x, %y, %q))IR",
|
||||
&*graph,
|
||||
parse_map);
|
||||
|
||||
std::unordered_map<Value*, Value*> vmap1;
|
||||
|
||||
Node* subgraph1 = SubgraphUtils::createSingletonSubgraph(
|
||||
parse_map.at("y")->node(), prim::DifferentiableGraph);
|
||||
SubgraphUtils::mergeNodeIntoSubgraph(
|
||||
parse_map.at("x")->node(), subgraph1, vmap1);
|
||||
// vmap should have two entries: a mapping for the '%x' value - the output of
|
||||
// the node we merged in, and a mapping for the '%a' value - the input of the
|
||||
// node.
|
||||
ASSERT_EQ(vmap1.size(), 2);
|
||||
|
||||
// Check that after mergeNodeIntoSubgraph we can still access the node
|
||||
// corresponding to the original node "%x = aten::tanh(%a)".
|
||||
//
|
||||
// Note that parse_map["x"] points to a destroyed Value after the
|
||||
// mergeNodeIntoSubgraph call - we cannot access its content anymore, but
|
||||
// still can use it as a key in the value map to find the value it was moved
|
||||
// to.
|
||||
Node* new_tanh = vmap1.at(parse_map.at("x"))->node();
|
||||
ASSERT_TRUE(new_tanh->kind() == aten::tanh);
|
||||
|
||||
Node* subgraph2 = SubgraphUtils::createSingletonSubgraph(
|
||||
parse_map["q"]->node(), prim::DifferentiableGraph);
|
||||
SubgraphUtils::mergeNodeIntoSubgraph(parse_map.at("p")->node(), subgraph2);
|
||||
|
||||
std::unordered_map<Value*, Value*> vmap2;
|
||||
Value* new_tanh_out = new_tanh->output();
|
||||
SubgraphUtils::mergeNodeIntoSubgraph(subgraph1, subgraph2, vmap2);
|
||||
// vmap should have 6 entries, since we moved 4 values into the graph (the
|
||||
// values correspond to the original values '%a', '%b', '%x', and '%y').
|
||||
// and we map the node outputs for '%x' and '%y'
|
||||
ASSERT_EQ(vmap2.size(), 6);
|
||||
|
||||
// Check that after mergeNodeIntoSubgraph we can still access the node
|
||||
// corresponding to the original node, even if the toMerge node had a subgraph
|
||||
// as well
|
||||
ASSERT_TRUE(vmap2.at(new_tanh_out)->node()->kind() == aten::tanh);
|
||||
}
|
||||
|
||||
TEST(SubgraphUtilsTest, GraphName) {
|
||||
auto graph = std::make_shared<Graph>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user