Tracker for torch._numpy errors under dynamo
Labels: triaged, module: numpy, module: dynamo

### 🐛 Describe the bug

This issue is to collect failures observed in https://github.com/pytorch/pytorch/pull/110401 when trying to run torch._numpy tests under Dynamo:

1. `array.tolist()`. Repro:

```
import torch
import numpy as np

def fn(value):
    x = np.array([0])
    # x = torch.as_tensor([0])    # this works
    return x.tolist()

opt_fn = torch.compile(fn)

x = np.array([1, 2, 3])
print("compiled: ", opt_fn(x))
``` 

yields

```
Traceback (most recent call last):
  File "arr.py", line 14, in <module>
    print("compiled: ", opt_fn(x))
  File "/home/ev-br/repos/pytorch/torch/_dynamo/eval_frame.py", line 401, in _fn
    return fn(*args, **kwargs)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/eval_frame.py", line 549, in catch_errors
    return callback(frame, cache_entry, hooks, frame_state)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/convert_frame.py", line 683, in _convert_frame
    result = inner_convert(frame, cache_entry, hooks, frame_state)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/convert_frame.py", line 148, in _fn
    return fn(*args, **kwargs)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/convert_frame.py", line 402, in _convert_frame_assert
    return _compile(
  File "/home/ev-br/repos/pytorch/torch/_dynamo/convert_frame.py", line 610, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/utils.py", line 221, in time_wrapper
    r = func(*args, **kwargs)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/convert_frame.py", line 527, in compile_inner
    out_code = transform_code_object(code, transform)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/bytecode_transformation.py", line 1028, in transform_code_object
    transformations(instructions, code_options)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/convert_frame.py", line 497, in transform
    tracer.run()
  File "/home/ev-br/repos/pytorch/torch/_dynamo/symbolic_convert.py", line 2102, in run
    super().run()
  File "/home/ev-br/repos/pytorch/torch/_dynamo/symbolic_convert.py", line 742, in run
    and self.step()
  File "/home/ev-br/repos/pytorch/torch/_dynamo/symbolic_convert.py", line 705, in step
    getattr(self, inst.opname)(inst)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/symbolic_convert.py", line 405, in wrapper
    return inner_fn(self, inst)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/symbolic_convert.py", line 1138, in CALL_FUNCTION
    self.call_function(fn, args, {})
  File "/home/ev-br/repos/pytorch/torch/_dynamo/symbolic_convert.py", line 577, in call_function
    self.push(fn.call_function(self, args, kwargs))
  File "/home/ev-br/repos/pytorch/torch/_dynamo/variables/misc.py", line 648, in call_function
    return self.obj.call_method(tx, self.name, args, kwargs).add_options(self)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/variables/tensor.py", line 1086, in call_method
    return NumpyNdarrayVariable.create(tx, proxy, **options)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/variables/tensor.py", line 1000, in create
    return wrap_fx_proxy_cls(
  File "/home/ev-br/repos/pytorch/torch/_dynamo/variables/builder.py", line 1404, in wrap_fx_proxy_cls
    example_value = get_fake_value(proxy.node, tx)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/utils.py", line 1422, in get_fake_value
    raise TorchRuntimeError(str(e)).with_traceback(e.__traceback__) from None
  File "/home/ev-br/repos/pytorch/torch/_dynamo/utils.py", line 1383, in get_fake_value
    return wrap_fake_exception(
  File "/home/ev-br/repos/pytorch/torch/_dynamo/utils.py", line 952, in wrap_fake_exception
    return fn()
  File "/home/ev-br/repos/pytorch/torch/_dynamo/utils.py", line 1384, in <lambda>
    lambda: run_node(tx.output, node, args, kwargs, nnmodule)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/utils.py", line 1483, in run_node
    raise RuntimeError(fn_str + str(e)).with_traceback(e.__traceback__) from e
  File "/home/ev-br/repos/pytorch/torch/_dynamo/utils.py", line 1462, in run_node
    return node.target(*args, **kwargs)
  File "/home/ev-br/repos/pytorch/torch/_dynamo/utils.py", line 1799, in __call__
    out = method_callable(*args[1:], **kwargs)
  File "/home/ev-br/repos/pytorch/torch/_numpy/_ndarray.py", line 345, in tolist
    return self.tensor.tolist()
torch._dynamo.exc.TorchRuntimeError: Failed running call_function <Wrapped method <original tolist>>(*(FakeTensor(..., size=(1,), dtype=torch.int64),), **{}):
.tolist() is not supported for tensor subclasses, got FakeTensor

```

-------------------------------------------------

2.  `np.typecodes` is a `Dict[Str, Str]` is not compiled at all

```
import torch
import numpy as np

def fn():
    return np.typecodes["AllInteger"]

cnts = torch._dynamo.testing.CompileCounter()
opt_fn = torch._dynamo.optimize(cnts)(fn)

print(torch._numpy.typecodes['AllInteger'])
print(fn())
print(opt_fn())
print(cnts.frame_count)
```

yields

```
Bbhil
bBhHiIlLqQpP
bBhHiIlLqQpP
0
```

The problem is that's `np.typecodes` does not contain tensors, is not traced and dynamo simply falls back to eager numpy. 


cc @mruberry @rgommers @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @chenyang78 @aakhundov @kadeng