Repository: pytorch
Issue: Attributes not removed by freeze module
Labels: oncall: jit,triaged

## Description
There are still `SetAttr` and `GetAttr` remaining in the graph. Why is freeze module pass not removing them?

## To Reproduce

```python
class AttrMod(torch.nn.Module):
    def __init__(self, x):
        super().__init__()
        self.x = x

    def forward(self, x, y):
        self.x = x
        return self.x + y

x = torch.ones(1,2,3)
s_m = torch.jit.script(AttrMod(x))
print(s_m.graph)
s_m.eval()
f_s_m = torch._C._freeze_module(s_m._c)
f_s_m.dump()
"""
Scripted graph:
graph(%self : __torch__.AttrMod,
      %x.1 : Tensor,
      %y.1 : Tensor):
  %6 : int = prim::Constant[value=1]()
   = prim::SetAttr[name="x"](%self, %x.1)
  %4 : Tensor = prim::GetAttr[name="x"](%self)
  %7 : Tensor = aten::add(%4, %y.1, %6) # repro_ssa.py:29:15
  return (%7)

Frozen module graph:
module __torch__.___torch_mangle_0.AttrMod {
  parameters {
  }
  attributes {
    x = (1,.,.) =
      1  1  1
      1  1  1
    [ CPUFloatType{1,2,3} ]
  }
  methods {
    method forward {
      graph(%self : __torch__.___torch_mangle_0.AttrMod,
            %x.1 : Tensor,
            %y.1 : Tensor):
        %3 : int = prim::Constant[value=1]()
         = prim::SetAttr[name="x"](%self, %x.1)
        %4 : Tensor = prim::GetAttr[name="x"](%self)
        %5 : Tensor = aten::add(%4, %y.1, %3) # repro_ssa.py:29:15
        return (%5)

    }
  }
  submodules {
  }
}
"""

```

-- Update:
We face this issue when scripting Faster RCNN, Mask RCNN, and Keypoint RCNN models. After freeze module, we still see setAttr and getAttr remaining in the graph. One real model use-case for this issue is when attributes of an object or submodule are set in the forward method. Example:

```
class BoxCoder(object):
    def __init__(self, bbox_xform_clip):
        # type: (float) -> None
        self.bbox_xform_clip = bbox_xform_clip

    def decode(self, rel_codes, boxes):
        # type: (Tensor, List[Tensor]) -> Tensor
        boxes_per_image = [b.size(0) for b in boxes]
        boxes = torch.cat(boxes, dim=0)

        pred_ctr_x = torch.clamp(rel_codes[:, 0::4], max=self.bbox_xform_clip)* boxes[:, 2]
        pred_ctr_y = torch.clamp(rel_codes[:, 1::4], max=self.bbox_xform_clip)* boxes[:, 3]

        return torch.stack((pred_ctr_x, pred_ctr_y), dim=2)

class MyModule(torch.nn.Module):
        def __init__(self):
            super(MyModule, self).__init__()

        def forward(self, box_regression, proposals):
            box_coder = BoxCoder(math.log(1000. / 16))
            return box_coder.decode(box_regression, proposals)

    model = MyModule()
    model.eval()
    box_regression = torch.randn([4, 4])
    proposal = [torch.randn(2, 4), torch.randn(2, 4)]

    output = model(box_regression, proposal)
    script_m = torch.jit.script(model)

    script_m.eval()
    f_s_m = torch._C._freeze_module(script_m._c)
    f_s_m.dump()

# module __torch__.___torch_mangle_0.MyModule {
#   parameters {
#   }
#   attributes {
#   }
#   methods {
#     method forward {
#       graph(%self : __torch__.___torch_mangle_0.MyModule,
#             %box_regression.1 : Tensor,
#             %proposals.1 : Tensor):
#         %15 : None = prim::Constant()
#         %14 : int = prim::Constant[value=9223372036854775807]()
#         %13 : int = prim::Constant[value=0]() # pytorch_test.py:13:34
#         %12 : int = prim::Constant[value=4]() # pytorch_test.py:16:49
#         %11 : int = prim::Constant[value=2]() # pytorch_test.py:16:89
#         %10 : int = prim::Constant[value=1]() # pytorch_test.py:17:46
#         %9 : int = prim::Constant[value=3]() # pytorch_test.py:17:89
#         %3 : float = prim::Constant[value=4.1351665567423561]()
#         %box_coder.1 : __torch__.BoxCoder = prim::CreateObject()
#          = prim::SetAttr[name="bbox_xform_clip"](%box_coder.1, %3)
#         %6 : Tensor[] = prim::ListConstruct(%proposals.1)
#         %boxes.4 : Tensor = aten::cat(%6, %13) # pytorch_test.py:14:16
#         %17 : Tensor = aten::slice(%box_regression.1, %13, %13, %14, %10) # pytorch_test.py:16:33
#         %18 : Tensor = aten::slice(%17, %10, %13, %14, %12) # pytorch_test.py:16:33
#         %19 : float = prim::GetAttr[name="bbox_xform_clip"](%box_coder.1)
#         %20 : Tensor = aten::clamp(%18, %15, %19) # pytorch_test.py:16:21
#         %21 : Tensor = aten::slice(%boxes.4, %13, %13, %14, %10) # pytorch_test.py:16:80
#         %22 : Tensor = aten::select(%21, %10, %11) # pytorch_test.py:16:80
#         %pred_ctr_x.1 : Tensor = aten::mul(%20, %22) # pytorch_test.py:16:21
#         %25 : Tensor = aten::slice(%17, %10, %10, %14, %12) # pytorch_test.py:17:33
#         %26 : float = prim::GetAttr[name="bbox_xform_clip"](%box_coder.1)
#         %27 : Tensor = aten::clamp(%25, %15, %26) # pytorch_test.py:17:21
#         %29 : Tensor = aten::select(%21, %10, %9) # pytorch_test.py:17:80
#         %pred_ctr_y.1 : Tensor = aten::mul(%27, %29) # pytorch_test.py:17:21
#         %31 : Tensor[] = prim::ListConstruct(%pred_ctr_x.1, %pred_ctr_y.1)
#         %32 : Tensor = aten::stack(%31, %11) # pytorch_test.py:19:15
#         return (%32)

#     }
#   }
#   submodules {
#   }
# }
```

cc @suo