Pytorch2.0 compile error
Labels: triaged, oncall: pt2

### 🐛 Describe the bug

  I can run the code normally in eager mode, but it raises an error when compiling:
``` File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 118, in __call__
    return self.dynamo_ctx(self._orig_mod.__call__)(*args, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 254, in _fn
    return fn(*args, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1533, in _call_impl
    return forward_call(*args, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/nn/parallel/distributed.py", line 1129, in forward
    output = self._run_ddp_forward(*inputs, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/nn/parallel/distributed.py", line 1083, in _run_ddp_forward
    return self.module(*inputs[0], **kwargs[0])  # type: ignore[index]
  File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1533, in _call_impl
    return forward_call(*args, **kwargs)
  File "/tmp/amlt_code/code/model/crab/clip.py", line 52, in forward
    image_embeddings = self.encode_image(image)
  File "/tmp/amlt_code/code/model/crab/clip.py", line 53, in <resume in forward>
    text_embeddings = self.encode_text(text, text_attention_mask)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 388, in catch_errors
    return hijacked_callback(frame, cache_size, hooks)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 406, in _convert_frame
    result = inner_convert(frame, cache_size, hooks)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 105, in _fn
    return fn(*args, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 263, in _convert_frame_assert
    return _compile(
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 164, in time_wrapper
    r = func(*args, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 326, in _compile
    out_code = transform_code_object(code, transform)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/bytecode_transformation.py", line 530, in transform_code_object
    transformations(instructions, code_options)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 313, in transform
    tracer.run()
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1840, in run
    super().run()
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 597, in run
    and self.step()
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 560, in step
    getattr(self, inst.opname)(inst)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1919, in RETURN_VALUE
    self.output.compile_subgraph(
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/output_graph.py", line 569, in compile_subgraph
    self.compile_and_call_fx_graph(tx, pass2.graph_output_vars(), root)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/output_graph.py", line 615, in compile_and_call_fx_graph
    compiled_fn = self.call_user_compiler(gm)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 164, in time_wrapper
    r = func(*args, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/output_graph.py", line 701, in call_user_compiler
    raise BackendCompilerFailed(self.compiler_fn, e).with_traceback(
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/output_graph.py", line 697, in call_user_compiler
    compiled_fn = compiler_fn(gm, self.fake_example_inputs())
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/backends/distributed.py", line 202, in compile_fn
    return self.backend_compile_fn(gm, example_inputs)
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/debug_utils.py", line 1064, in debug_wrapper
    compiled_gm = compiler_fn(gm, example_inputs)
  File "/opt/conda/lib/python3.10/site-packages/torch/__init__.py", line 1382, in __call__
    return compile_fx(model_, inputs_, config_patches=self.config)
  File "/opt/conda/lib/python3.10/site-packages/torch/_inductor/compile_fx.py", line 488, in compile_fx
    return aot_autograd(
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/backends/common.py", line 48, in compiler_fn
    cg = aot_module_simplified(gm, example_inputs, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/_functorch/aot_autograd.py", line 2873, in aot_module_simplified
    compiled_fn = create_aot_dispatcher_function(
  File "/opt/conda/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 164, in time_wrapper
    r = func(*args, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/_functorch/aot_autograd.py", line 2554, in create_aot_dispatcher_function
    compiled_fn = compiler_fn(flat_fn, fake_flat_args, aot_config)
  File "/opt/conda/lib/python3.10/site-packages/torch/_functorch/aot_autograd.py", line 1694, in aot_wrapper_dedupe
    fw_metadata = run_functionalized_fw_and_collect_metadata(
  File "/opt/conda/lib/python3.10/site-packages/torch/_functorch/aot_autograd.py", line 616, in inner
    flat_f_outs = f(*flat_f_args)
  File "/opt/conda/lib/python3.10/site-packages/torch/_functorch/aot_autograd.py", line 2836, in functional_call
    out = Interpreter(mod).run(*args[params_len:], **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/fx/interpreter.py", line 137, in run
    self.env[node] = self.run_node(node)
  File "/opt/conda/lib/python3.10/site-packages/torch/fx/interpreter.py", line 179, in run_node
    return getattr(self, n.op)(n.target, args, kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/fx/interpreter.py", line 251, in call_function
    return target(*args, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/distributed/distributed_c10d.py", line 1492, in wrapper
    return func(*args, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/distributed/distributed_c10d.py", line 2489, in all_gather
    work = default_pg.allgather([tensor_list], [tensor])
  File "/opt/conda/lib/python3.10/site-packages/torch/utils/_stats.py", line 20, in wrapper
    return fn(*args, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 1057, in __torch_dispatch__
    return self.dispatch(func, types, args, kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 1136, in dispatch
    args, kwargs = self.validate_and_convert_non_fake_tensors(
  File "/opt/conda/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 1290, in validate_and_convert_non_fake_tensors
    return tree_map_only(
  File "/opt/conda/lib/python3.10/site-packages/torch/utils/_pytree.py", line 266, in tree_map_only
    return tree_map(map_only(ty)(fn), pytree)
  File "/opt/conda/lib/python3.10/site-packages/torch/utils/_pytree.py", line 196, in tree_map
    return tree_unflatten([fn(i) for i in flat_args], spec)
  File "/opt/conda/lib/python3.10/site-packages/torch/utils/_pytree.py", line 196, in <listcomp>
    return tree_unflatten([fn(i) for i in flat_args], spec)
  File "/opt/conda/lib/python3.10/site-packages/torch/utils/_pytree.py", line 247, in inner
    return f(x)
  File "/opt/conda/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 1282, in validate
    raise Exception(
torch._dynamo.exc.BackendCompilerFailed: backend='compile_fn' raised:
Exception: Please convert all Tensors to FakeTensors first or instantiate FakeTensorMode with 'allow_non_fake_inputs'. Found in c10d.allgather_.default(*([[_to_functional_tensor(FakeTensor(FakeTensor(..., device='meta', size=(128, 512)), cuda:0),
       device='cuda:0'), _to_functional_tensor(FakeTensor(FakeTensor(..., device='meta', size=(128, 512)), cuda:0),
       device='cuda:0'), _to_functional_tensor(FakeTensor(FakeTensor(..., device='meta', size=(128, 512)), cuda:0),
       device='cuda:0'), _to_functional_tensor(FakeTensor(FakeTensor(..., device='meta', size=(128, 512)), cuda:0),
       device='cuda:0'), _to_functional_tensor(FakeTensor(FakeTensor(..., device='meta', size=(128, 512)), cuda:0),
       device='cuda:0'), _to_functional_tensor(FakeTensor(FakeTensor(..., device='meta', size=(128, 512)), cuda:0),
       device='cuda:0'), _to_functional_tensor(FakeTensor(FakeTensor(..., device='meta', size=(128, 512)), cuda:0),
       device='cuda:0'), _to_functional_tensor(FakeTensor(FakeTensor(..., device='meta', size=(128, 512)), cuda:0),
       device='cuda:0')]], [FakeTensor(FakeTensor(..., device='meta', size=(128, 512)), cuda:0)], <torch.ScriptObject object at 0x7f54973871f0>, -1), **{}) 

While executing %all_gather : [#users=0] = call_function[target=torch.distributed.distributed_c10d.all_gather](args = ([%ones_like, %ones_like_1, %ones_like_2, %ones_like_3, %ones_like_4, %ones_like_5, %ones_like_6, %ones_like_7], %normalize), kwargs = {async_op: False})
Original traceback:
  File "/tmp/amlt_code/code/model/crab/clip.py", line 57, in <resume in forward>
    return self.criterion(
  File "/tmp/amlt_code/code/model/modules/clip_loss.py", line 29, in forward
    image_embed_all, text_embed_all = all_gather_batch([image_embed, text_embed])
  File "/tmp/amlt_code/code/utils/dist.py", line 58, in all_gather_batch
    dist.all_gather(tensor_all, tensor, async_op=False)  # performance opt



You can suppress this exception and fall back to eager by setting:
    torch._dynamo.config.suppress_errors = True
```

### Versions

Collecting environment information...
PyTorch version: 2.1.0.dev20230309+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.5 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: version 3.25.0
Libc version: glibc-2.31

Python version: 3.10.9 (main, Jan 11 2023, 15:21:40) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-4.15.0-197-generic-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration:
GPU 0: Tesla V100-SXM2-32GB
GPU 1: Tesla V100-SXM2-32GB
GPU 2: Tesla V100-SXM2-32GB
GPU 3: Tesla V100-SXM2-32GB

Nvidia driver version: 470.141.03
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.7.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   46 bits physical, 48 bits virtual
CPU(s):                          96
On-line CPU(s) list:             0-95
Thread(s) per core:              2
Core(s) per socket:              24
Socket(s):                       2
NUMA node(s):                    2
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           85
Model name:                      Intel(R) Xeon(R) Platinum 8160 CPU @ 2.10GHz
Stepping:                        4
CPU MHz:                         2959.349
BogoMIPS:                        4200.00
Virtualization:                  VT-x
L1d cache:                       1.5 MiB
L1i cache:                       1.5 MiB
L2 cache:                        48 MiB
L3 cache:                        66 MiB
NUMA node0 CPU(s):               0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94
NUMA node1 CPU(s):               1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95
Vulnerability Itlb multihit:     KVM: Mitigation: Split huge pages
Vulnerability L1tf:              Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Mmio stale data:   Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT vulnerable
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts pku ospke md_clear flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] numpy==1.23.5
[pip3] pytorch-triton==2.0.0+b8b470bc59
[pip3] torch==2.1.0.dev20230309+cu118
[pip3] torchaudio==2.0.0.dev20230309+cu118
[pip3] torchvision==0.15.0.dev20230309+cu118
[conda] mkl                       2023.0.0         h6d00ec8_25399
[conda] mkldnn                    0.16.1                        0    mingfeima
[conda] numpy                     1.23.5                   pypi_0    pypi
[conda] pytorch-triton            2.0.0+b8b470bc59          pypi_0    pypi
[conda] torch                     2.1.0.dev20230309+cu118          pypi_0    pypi
[conda] torchaudio                2.0.0.dev20230309+cu118          pypi_0    pypi
[conda] torchvision               0.15.0.dev20230309+cu118          pypi_0    pypi

cc @ezyang @msaroufim @wconstab @ngimel @bdhirsh @anijain2305 @soumith