Revert "[jit] fix tuple alias analysis (#41992)"

This reverts commit 8aa878fc93.
This commit is contained in:
Nikita Shulga 2020-07-24 13:32:00 -07:00
parent 994b37b36e
commit 35ad2d8586
3 changed files with 11 additions and 19 deletions

View file

@ -794,6 +794,9 @@ class TestFreezing(JitTestCase):
expected = m_s.forward(inp)
self.assertEqual(out, expected)
# Check attribute a is preserved. Alias analysis detects that 'a' has output writers.
# In this example, 'a' is not mutated. However, we do not track which sub
# values of a composite ivalue is mutated.
def test_freeze_module_with_aliased_attr2(self):
class FreezeMe(nn.Module):
def __init__(self):
@ -812,6 +815,7 @@ class TestFreezing(JitTestCase):
m_s = torch.jit.script(m)
m_s.eval()
m_f = torch._C._freeze_module(m_s._c)
self.assertTrue(m_f.hasattr('a'))
inp = torch.tensor([5])
out = m_f.forward(inp)
expected = m.forward(inp)

View file

@ -498,7 +498,6 @@ void AliasDb::analyzeImpl(Node* node) {
case prim::tolist:
return analyzeCreator(node);
case prim::TupleConstruct:
return analyzeTupleConstruct(node);
case prim::DictConstruct:
case prim::ListConstruct:
return analyzeContainerConstruct(node);
@ -865,22 +864,6 @@ void AliasDb::analyzeConservative(Node* node) {
}
}
void AliasDb::analyzeTupleConstruct(Node* node) {
TORCH_INTERNAL_ASSERT(node->kind() == prim::TupleConstruct);
// tuples which contain immutable types are immutable
if (!isMutableTypeInternal(node->output())) {
return;
}
giveFreshAlias(node->output());
for (const auto& input : node->inputs()) {
if (isMutableTypeInternal(input)) {
addToContainedElements(input, node->output());
}
}
}
// List or dict or tuple: construct: create an aliasing element for the actual
// container, then mark all inputs as wildcards, since they've gone inside the
// container. Then, add the wildcard sets of appropriate type to the contained
@ -888,7 +871,13 @@ void AliasDb::analyzeTupleConstruct(Node* node) {
void AliasDb::analyzeContainerConstruct(Node* node) {
TORCH_INTERNAL_ASSERT(
node->kind() == prim::ListConstruct ||
node->kind() == prim::DictConstruct);
node->kind() == prim::DictConstruct ||
node->kind() == prim::TupleConstruct);
// tuples which contain immutable types are immutable
if (!isMutableTypeInternal(node->output())) {
return;
}
TORCH_INTERNAL_ASSERT(node->outputs().size() == 1);
auto container = node->output();

View file

@ -194,7 +194,6 @@ class AliasDb {
void analyzeSetAttr(Node* node);
void analyzeConservative(Node* node);
void analyzeContainerConstruct(Node* node);
void analyzeTupleConstruct(Node* node);
bool tryRegisteredAnalysis(Node* node);
/**