dynamo crashes on optimizer initialization
Labels: module: optimizer, triaged, oncall: pt2

### 🐛 Describe the bug

Below gives a `NotImplementedError: ListIteratorVariable() has no type` error

However @mlazos suggested a simple workaround to move `opt = torch.optim.Adam(m.parameters(), lr=0.01)` out of the  `train()` function and that fixed it 

```python
import torch
import torch._inductor.config as config
config.trace.enabled = True
torch._dynamo.config.verbose=True

class HelloModule(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = torch.nn.Linear(1, 1).cuda()

    def forward(self, x):
        x = self.linear(x)
        x_2 = torch.relu(x)
        y = torch.relu(x_2)
        return x_2 + y

m = HelloModule()

@torch.compile
def f():
    opt = torch.optim.Adam(m.parameters(), lr=0.01)
    for i in range(5):
        opt.zero_grad()
        out = m(torch.ones(1).to(device='cuda:0'))
        loss = out.sum()
        loss.backward()
        opt.step()

f()
```


### Error logs

```
(nightly) ubuntu@ip-172-31-39-186:~/test$ python hello.py 
/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_inductor/compile_fx.py:89: UserWarning: TensorFloat32 tensor cores for float32 matrix multiplication available but not enabled. Consider setting `torch.set_float32_matmul_precision('high')` for better performance.
  warnings.warn(
[2023-02-04 01:34:10,325] torch._inductor.debug: [WARNING] model__0_inference_0 debug trace: /home/ubuntu/test/torch_compile_debug/run_2023_02_04_01_34_10_324777/aot_torchinductor/model__0_inference_0.0
Traceback (most recent call last):
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 324, in _compile
    out_code = transform_code_object(code, transform)
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/bytecode_transformation.py", line 339, in transform_code_object
    transformations(instructions, code_options)
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 311, in transform
    tracer.run()
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1715, in run
    super().run()
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 564, in run
    and self.step()
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 527, in step
    getattr(self, inst.opname)(inst)
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 333, in wrapper
    return inner_fn(self, inst)
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 990, in CALL_FUNCTION
    self.call_function(fn, args, {})
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 461, in call_function
    self.push(fn.call_function(self, args, kwargs))
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/variables/builtin.py", line 322, in call_function
    result = handler(tx, *args, **kwargs)
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/variables/builtin.py", line 571, in call_isinstance
    arg_type = arg.python_type()
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/variables/base.py", line 146, in python_type
    raise NotImplementedError(f"{self} has no type")
NotImplementedError: ListIteratorVariable() has no type

from user code:
   File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/optim/optimizer.py", line 162, in <graph break in __init__>
    if isinstance(params, torch.Tensor):


You can suppress this exception and fall back to eager by setting:
    torch._dynamo.config.suppress_errors = True


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ubuntu/test/hello.py", line 64, in <module>
    f()
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 209, in _fn
    return fn(*args, **kwargs)
  File "/home/ubuntu/test/hello.py", line 54, in f
    opt = torch.optim.Adam(m.parameters(), lr=0.01)
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/optim/adam.py", line 33, in __init__
    super(Adam, self).__init__(params, defaults)
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/optim/optimizer.py", line 157, in __init__
    self._optimizer_step_pre_hooks: Dict[int, Callable] = OrderedDict()
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/optim/optimizer.py", line 158, in <graph break in __init__>
    self._optimizer_step_post_hooks: Dict[int, Callable] = OrderedDict()
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/optim/optimizer.py", line 160, in <graph break in __init__>
    self._patch_step_function()
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 330, in catch_errors
    return callback(frame, cache_size, hooks)
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 404, in _convert_frame
    result = inner_convert(frame, cache_size, hooks)
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 104, in _fn
    return fn(*args, **kwargs)
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 262, in _convert_frame_assert
    return _compile(
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 163, in time_wrapper
    r = func(*args, **kwargs)
  File "/opt/conda/envs/nightly/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 394, in _compile
    raise InternalTorchDynamoError() from e
torch._dynamo.exc.InternalTorchDynamoError
```



### Minified repro

n

### Versions

n

cc @vincentqb @jbschlosser @albanD @janeyx99 @ezyang @soumith @wconstab @ngimel @bdhirsh