Repository: pytorch
Issue: torch_function mode explodes with torch.compile
Labels: triaged,module: __torch_function__,oncall: pt2,module: dynamo,module: pt2-dispatcher

I'd expect it to gracefully fall back to eager-mode?
```py
class Mul2ModeF(torch.overrides.TorchFunctionMode):
    def __torch_function__(cls, func, types, args=(), kwargs=None):
        if kwargs is None:
            kwargs = {}
        out = func(*args, **kwargs)
        return out * 2

@torch.compile(backend="aot_eager")
def f(x):
    return x.view(-1)

x = torch.ones(3, device='cuda')
with Mul2ModeF():
    y = f(x)
```
gives:
```
Traceback (most recent call last):
  File "/home/rzou/dev/nightly/bar.py", line 68, in <module>
    y = f(x)
        ^^^^
  File "/home/rzou/dev/nightly/env/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 501, in _fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/rzou/dev/nightly/env/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 667, in catch_errors
    return callback(frame, cache_entry, hooks, frame_state)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rzou/dev/nightly/env/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 730, in _convert_frame
    result = inner_convert(frame, cache_entry, hooks, frame_state)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rzou/dev/nightly/env/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 383, in _convert_frame_assert
    compiled_product = _compile(
                       ^^^^^^^^^
  File "/home/rzou/dev/nightly/env/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 665, in _compile
    raise InternalTorchDynamoError(str(e)).with_traceback(
  File "/home/rzou/dev/nightly/env/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 646, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rzou/dev/nightly/env/lib/python3.11/site-packages/torch/_dynamo/utils.py", line 242, in time_wrapper
    with torch.profiler.record_function(f"{key} (dynamo_timed)"):
  File "/home/rzou/dev/nightly/env/lib/python3.11/site-packages/torch/autograd/profiler.py", line 605, in __enter__
    self.record = torch.ops.profiler._record_function_enter_new(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rzou/dev/nightly/env/lib/python3.11/site-packages/torch/_ops.py", line 755, in __call__
    return self._op(*args, **(kwargs or {}))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rzou/dev/nightly/bar.py", line 53, in __torch_function__
    return out * 2
           ~~~~^~~
torch._dynamo.exc.InternalTorchDynamoError: '__mul__' is not implemented for __torch__.torch.classes.profiler._RecordFunction


You can suppress this exception and fall back to eager by setting:
    import torch._dynamo
    torch._dynamo.config.suppress_errors = True
```

cc @hameerabbasi @rgommers @peterbell10 @ezyang @msaroufim @wconstab @bdhirsh @anijain2305 @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @aakhundov @kadeng