Cannot export models which access int/float stored as module attributes (they get unspecialized into inputs, which makes export choke)
Labels: triaged, oncall: pt2, module: dynamo, module: export

### 🐛 Describe the bug

```python
import torch
import torch._dynamo as torchdynamo

class Foo(torch.nn.Module):
    def __init__(
        self,
        input_dim,
    ):
        super().__init__()
        self.torch_module = torch.nn.LayerNorm(
            input_dim, eps=1e-5, elementwise_affine=True
        )

    def forward(self, input):
        output = torch.nn.functional.layer_norm(
            input,
            self.torch_module.normalized_shape,
            self.torch_module.weight,
            self.torch_module.bias,
            self.torch_module.eps,
        ).type_as(input)
        return output

mod = Foo(128)
inp = torch.randn(3, 128)
gm, _ = torchdynamo.export(mod, inp, aten_graph=True, tracing_mode="symbolic")
print(gm.graph)
```
Above snippet fails with following error:
```
RuntimeError                              Traceback (most recent call last)
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/utils.py in run_node(output_graph, node, args, kwargs, nnmodule)
   1185         if op == "call_function":
-> 1186             return node.target(*args, **kwargs)
   1187         elif op == "call_method":
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/nn/functional.py in layer_norm(input, normalized_shape, weight, bias, eps)
   2514         )
-> 2515     return torch.layer_norm(input, normalized_shape, weight, bias, eps, torch.backends.cudnn.enabled)
   2516 
RuntimeError: tried to get Double out of SymFloat

The above exception was the direct cause of the following exception:
RuntimeError                              Traceback (most recent call last)
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/utils.py in get_fake_value(node, tx)
   1143         with tx.fake_mode, enable_python_dispatcher():
-> 1144             return wrap_fake_exception(
   1145                 lambda: run_node(tx.output, node, args, kwargs, nnmodule)
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/utils.py in wrap_fake_exception(fn)
    805     try:
--> 806         return fn()
    807     except UnsupportedFakeTensorException as e:
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/utils.py in <lambda>()
   1144             return wrap_fake_exception(
-> 1145                 lambda: run_node(tx.output, node, args, kwargs, nnmodule)
   1146             )
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/utils.py in run_node(output_graph, node, args, kwargs, nnmodule)
   1197     except Exception as e:
-> 1198         raise RuntimeError(
   1199             f"Failed running {op} {node.target}(*{args}, **{kwargs}):\n{e}\n(scroll up for backtrace)"
RuntimeError: Failed running call_function <function layer_norm at 0x7fb50495c5e0>(*(FakeTensor(FakeTensor(..., device='meta', size=(s0, s1)), cpu), (128,), FakeTensor(Parameter(FakeTensor(..., device='meta', size=(128,), requires_grad=True)), cpu), FakeTensor(Parameter(FakeTensor(..., device='meta', size=(128,), requires_grad=True)), cpu), FakeTensor(FakeTensor(..., device='meta', size=()), cpu)), **{}):
tried to get Double out of SymFloat
(scroll up for backtrace)

The above exception was the direct cause of the following exception:
TorchRuntimeError                         Traceback (most recent call last)
<ipython-input-33-58348d11309a> in <module>
     24 mod = Foo(128)
     25 inp = torch.randn(3, 128)
---> 26 gm, _ = torchdynamo.export(mod, inp, aten_graph=True, tracing_mode="symbolic")
     27 print(gm.graph)
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/eval_frame.py in export(f, aten_graph, decomposition_table, tracing_mode, *args, **kwargs)
    602         )(f)
    603         # TODO(voz): We may have instances of `f` that mutate inputs, we should track sideffects and reject.
--> 604         result_traced = opt_f(*args, **kwargs)
    605     remove_from_cache(f)
    606 
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/nn/modules/module.py in _call_impl(self, *args, **kwargs)
   1486                 or _global_backward_pre_hooks or _global_backward_hooks
   1487                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1488             return forward_call(*args, **kwargs)
   1489         # Do not call functions when jit is used
   1490         full_backward_hooks, non_full_backward_hooks = [], []
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/eval_frame.py in forward(self, *args, **kwargs)
     80 
     81     def forward(self, *args, **kwargs):
---> 82         return self.dynamo_ctx(self._orig_mod.forward)(*args, **kwargs)
     83 
     84 
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/eval_frame.py in _fn(*args, **kwargs)
    209             dynamic_ctx.__enter__()
    210             try:
--> 211                 return fn(*args, **kwargs)
    212             finally:
    213                 set_eval_frame(prior)
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/eval_frame.py in catch_errors(frame, cache_size)
    330 
    331         with compile_lock:
--> 332             return callback(frame, cache_size, hooks)
    333 
    334     catch_errors._torchdynamo_orig_callable = callback  # type: ignore[attr-defined]
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/convert_frame.py in _fn(*args, **kwargs)
    101         torch.fx.graph_module._forward_from_src = fx_forward_from_src_skip_result
    102         try:
--> 103             return fn(*args, **kwargs)
    104         finally:
    105             torch._C._set_grad_enabled(prior_grad_mode)
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/convert_frame.py in _convert_frame_assert(frame, cache_size, hooks)
    259         initial_grad_state = torch.is_grad_enabled()
    260 
--> 261         return _compile(
    262             frame.f_code,
    263             frame.f_globals,
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/utils.py in time_wrapper(*args, **kwargs)
    160                 compilation_metrics[key] = []
    161             t0 = time.time()
--> 162             r = func(*args, **kwargs)
    163             time_spent = time.time() - t0
    164             # print(f"Dynamo timer: key={key}, latency={latency:.2f} sec")
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/convert_frame.py in _compile(code, globals, locals, builtins, compiler_fn, one_graph, export, hooks, frame)
    321         for attempt in itertools.count():
    322             try:
--> 323                 out_code = transform_code_object(code, transform)
    324                 orig_code_map[out_code] = code
    325                 break
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/bytecode_transformation.py in transform_code_object(code, transformations, safe)
    337     propagate_line_nums(instructions)
    338 
--> 339     transformations(instructions, code_options)
    340 
    341     fix_vars(instructions, code_options)
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/convert_frame.py in transform(instructions, code_options)
    308             mutated_closure_cell_contents,
    309         )
--> 310         tracer.run()
    311         output = tracer.output
    312         assert output is not None
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/symbolic_convert.py in run(self)
   1713     def run(self):
   1714         _step_logger()(logging.INFO, f"torchdynamo start tracing {self.f_code.co_name}")
-> 1715         super().run()
   1716 
   1717     def match_nested_cell(self, name, cell):
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/symbolic_convert.py in run(self)
    562                 self.instruction_pointer is not None
    563                 and not self.output.should_exit
--> 564                 and self.step()
    565             ):
    566                 pass
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/symbolic_convert.py in step(self)
    525             if not hasattr(self, inst.opname):
    526                 unimplemented(f"missing: {inst.opname}")
--> 527             getattr(self, inst.opname)(inst)
    528 
    529             return inst.opname != "RETURN_VALUE"
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/symbolic_convert.py in wrapper(self, inst)
    331             reason = None
    332             try:
--> 333                 return inner_fn(self, inst)
    334             except Unsupported as excp:
    335                 if self.has_backedge() and self.should_compile_partial_graph():
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/symbolic_convert.py in CALL_FUNCTION(self, inst)
    988         args = self.popn(inst.argval)
    989         fn = self.pop()
--> 990         self.call_function(fn, args, {})
    991 
    992     @break_graph_if_unsupported(push=1)
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/symbolic_convert.py in call_function(self, fn, args, kwargs)
    459             for x in itertools.chain(args, kwargs.values())
    460         )
--> 461         self.push(fn.call_function(self, args, kwargs))
    462 
    463     def update_locals_and_stack(self, oldvar: VariableTracker, newvar: VariableTracker):
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/variables/torch.py in call_function(self, tx, args, kwargs)
    469                     fn_ = sym_sqrt
    470 
--> 471             tensor_variable = wrap_fx_proxy(
    472                 tx=tx,
    473                 proxy=tx.output.create_proxy(
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/variables/builder.py in wrap_fx_proxy(tx, proxy, example_value, **options)
    754 
    755 def wrap_fx_proxy(tx, proxy, example_value=None, **options):
--> 756     return wrap_fx_proxy_cls(
    757         target_cls=TensorVariable,
    758         tx=tx,
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/variables/builder.py in wrap_fx_proxy_cls(target_cls, tx, proxy, example_value, ignore_subclass, **options)
    789     with preserve_rng_state():
    790         if example_value is None:
--> 791             example_value = get_fake_value(proxy.node, tx)
    792 
    793         # Handle recursive calls here
/mnt/xarfuse/uid-245563/fcd20915-seed-nspid4026531836_cgpid15299599-ns-4026531840/torch/_dynamo/utils.py in get_fake_value(node, tx)
   1163         ):
   1164             unimplemented("guard on data-dependent symbolic int/float")
-> 1165         raise TorchRuntimeError() from e
   1166 
   1167 
TorchRuntimeError: 

from user code:
   File "<ipython-input-33-58348d11309a>", line 15, in forward
    output = torch.nn.functional.layer_norm(

Set torch._dynamo.config.verbose=True for more information


You can suppress this exception and fall back to eager by setting:
    torch._dynamo.config.suppress_errors = True
```

### Versions

master 

cc @ezyang @soumith @msaroufim @wconstab @ngimel @bdhirsh @mlazos @voznesenskym @yanboliang @penguinwu @anijain2305 @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @desertfire