Repository: pytorch
Issue: torch._dynamo.exc.Unsupported: call_method UserDefinedObjectVariable(set) __contains__
Labels: triaged,oncall: pt2,module: dynamo

### 🐛 Describe the bug

```
import functools
import torch
import torch.utils._device


old_device_constructors_ = torch.utils._device._device_constructors()

@functools.lru_cache(1)
def origin_device_constructors():
    global old_device_constructors_
    return old_device_constructors_

torch.utils._device._device_constructors = origin_device_constructors

@torch.compile(fullgraph=True)
def split(x):
    return x.split(4, 0)

x = torch.zeros(12)
res = split(x)

with torch.device("cpu"):
    cpu_res = split(x)

for res, cpu_res in zip(res, cpu_res):
    print(torch.equal(res, cpu_res))
```

### Error logs

```  
File "/workspace/test.py", line 23, in <module>
    cpu_res = split(x)
  File "/workspace/pytorch/torch/_dynamo/eval_frame.py", line 556, in _fn
    return fn(*args, **kwargs)
  File "/workspace/pytorch/torch/_dynamo/convert_frame.py", line 1401, in __call__
    return self._torchdynamo_orig_callable(
  File "/workspace/pytorch/torch/_dynamo/convert_frame.py", line 549, in __call__
    return _compile(
  File "/workspace/pytorch/torch/_dynamo/convert_frame.py", line 982, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "/workspace/pytorch/torch/_dynamo/convert_frame.py", line 712, in compile_inner
    return _compile_inner(code, one_graph, hooks, transform)
  File "/workspace/pytorch/torch/_utils_internal.py", line 95, in wrapper_function
    return function(*args, **kwargs)
  File "/workspace/pytorch/torch/_dynamo/convert_frame.py", line 747, in _compile_inner
    out_code = transform_code_object(code, transform)
  File "/workspace/pytorch/torch/_dynamo/bytecode_transformation.py", line 1348, in transform_code_object
    transformations(instructions, code_options)
  File "/workspace/pytorch/torch/_dynamo/convert_frame.py", line 233, in _fn
    return fn(*args, **kwargs)
  File "/workspace/pytorch/torch/_dynamo/convert_frame.py", line 664, in transform
    tracer.run()
  File "/workspace/pytorch/torch/_dynamo/symbolic_convert.py", line 2843, in run
    super().run()
  File "/workspace/pytorch/torch/_dynamo/symbolic_convert.py", line 1034, in run
    while self.step():
  File "/workspace/pytorch/torch/_dynamo/symbolic_convert.py", line 946, in step
    self.dispatch_table[inst.opcode](self, inst)
  File "/workspace/pytorch/torch/_dynamo/symbolic_convert.py", line 641, in wrapper
    return inner_fn(self, inst)
  File "/workspace/pytorch/torch/_dynamo/symbolic_convert.py", line 1638, in CALL_FUNCTION
    self.call_function(fn, args, {})
  File "/workspace/pytorch/torch/_dynamo/symbolic_convert.py", line 879, in call_function
    self.push(fn.call_function(self, args, kwargs))  # type: ignore[arg-type]
  File "/workspace/pytorch/torch/_dynamo/variables/misc.py", line 1032, in call_function
    return self.obj.call_method(tx, self.name, args, kwargs)
  File "/workspace/pytorch/torch/_dynamo/variables/tensor.py", line 566, in call_method
    return dispatch_torch_function(
  File "/workspace/pytorch/torch/_dynamo/variables/torch_function.py", line 543, in dispatch_torch_function
    res = tx.symbolic_torch_function_state.call_torch_function_mode(
  File "/workspace/pytorch/torch/_dynamo/variables/torch_function.py", line 274, in call_torch_function_mode
    return cur_mode.call_torch_function(tx, fn, types, args, kwargs)
  File "/workspace/pytorch/torch/_dynamo/variables/torch_function.py", line 392, in call_torch_function
    return call_torch_function(
  File "/workspace/pytorch/torch/_dynamo/variables/torch_function.py", line 506, in call_torch_function
    return tx.inline_user_function_return(torch_function_var, tf_args, {})
  File "/workspace/pytorch/torch/_dynamo/symbolic_convert.py", line 885, in inline_user_function_return
    return InliningInstructionTranslator.inline_call(self, fn, args, kwargs)
  File "/workspace/pytorch/torch/_dynamo/symbolic_convert.py", line 3047, in inline_call
    return cls.inline_call_(parent, func, args, kwargs)
  File "/workspace/pytorch/torch/_dynamo/symbolic_convert.py", line 3173, in inline_call_
    tracer.run()
  File "/workspace/pytorch/torch/_dynamo/symbolic_convert.py", line 1034, in run
    while self.step():
  File "/workspace/pytorch/torch/_dynamo/symbolic_convert.py", line 946, in step
    self.dispatch_table[inst.opcode](self, inst)
  File "/workspace/pytorch/torch/_dynamo/symbolic_convert.py", line 2139, in CONTAINS_OP
    self.push(right.call_method(self, "__contains__", [left], {}))
  File "/workspace/pytorch/torch/_dynamo/variables/user_defined.py", line 825, in call_method
    return super().call_method(tx, name, args, kwargs)
  File "/workspace/pytorch/torch/_dynamo/variables/base.py", line 424, in call_method
    unimplemented(f"call_method {self} {name} {args} {kwargs}")
  File "/workspace/pytorch/torch/_dynamo/exc.py", line 313, in unimplemented
    raise Unsupported(msg, case_name=case_name)
torch._dynamo.exc.Unsupported: call_method UserDefinedObjectVariable(set) __contains__ [TorchInGraphFunctionVariable(<function Tensor.split at 0x7f7b19bdf0a0>)] {}
```

### Versions

```
Collecting environment information...
PyTorch version: 2.5.0a0+e000cf0
Is debug build: False
CUDA used to build PyTorch: 12.6
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.5 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.30.4
Libc version: glibc-2.35

Python version: 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-5.11.0-27-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.6.77
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: Tesla V100-SXM2-16GB
GPU 1: Tesla V100-SXM2-16GB
GPU 2: Tesla V100-SXM2-16GB
GPU 3: Tesla V100-SXM2-16GB

Nvidia driver version: 535.161.07
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.5.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
Address sizes:                   46 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          64
On-line CPU(s) list:             0-63
Vendor ID:                       GenuineIntel
Model name:                      Intel(R) Xeon(R) Gold 6130 CPU @ 2.10GHz
CPU family:                      6
Model:                           85
Thread(s) per core:              2
Core(s) per socket:              16
Socket(s):                       2
Stepping:                        4
CPU max MHz:                     3700.0000
CPU min MHz:                     1000.0000
BogoMIPS:                        4200.00
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 ept_ad 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
Virtualization:                  VT-x
L1d cache:                       1 MiB (32 instances)
L1i cache:                       1 MiB (32 instances)
L2 cache:                        32 MiB (32 instances)
L3 cache:                        44 MiB (2 instances)
NUMA node(s):                    2
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
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
Vulnerability Itlb multihit:     KVM: Mitigation: VMX disabled
Vulnerability L1tf:              Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Mitigation; PTI
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; Full generic retpoline, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT vulnerable

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.24.4
[pip3] nvidia-cudnn-frontend==1.7.0
[pip3] nvidia-nccl-cu12==2.22.3
[pip3] nvtx==0.2.5
[pip3] onnx==1.16.2
[pip3] optree==0.13.0
[pip3] pynvjitlink==0.3.0
[pip3] pytorch-triton==3.0.0+dedb7bdf3
[pip3] torch==2.5.0a0+e000cf0
[pip3] torch_tensorrt==2.5.0a0
[pip3] torchprofile==0.0.4
[pip3] torchvision==0.20.0a0
[conda] Could not collect
```

cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @amjames