Repository: pytorch
Issue: dynamo cannot trace global op_set .__contains__
Labels: oncall: pt2,module: dynamo,dynamo-triage-jan2025

### 🐛 Describe the bug

This gives a graph break:
```python
import torch

op_set = {
    torch._C._set_grad_enabled,
    torch.amp._enter_autocast,
    torch.amp._exit_autocast,
}

def f(x):
    if torch.ops.aten.add in op_set:
        return x.sin()
    return x.cos()
torch.compile(f, fullgraph=True, backend="eager")(torch.randn(3,4))
```
error message:
```
Traceback (most recent call last):
  File "/data/users/yidi/pytorch/test.py", line 13, in <module>
    torch.compile(f, fullgraph=True, backend="eager")(torch.randn(3,4))
  File "/data/users/yidi/pytorch/torch/_dynamo/eval_frame.py", line 566, in _fn
    return fn(*args, **kwargs)
  File "/data/users/yidi/pytorch/torch/_dynamo/convert_frame.py", line 1400, in __call__
    return self._torchdynamo_orig_callable(
  File "/data/users/yidi/pytorch/torch/_dynamo/convert_frame.py", line 565, in __call__
    return _compile(
  File "/data/users/yidi/pytorch/torch/_dynamo/convert_frame.py", line 997, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "/data/users/yidi/pytorch/torch/_utils_internal.py", line 95, in wrapper_function
    return function(*args, **kwargs)
  File "/data/users/yidi/pytorch/torch/_dynamo/convert_frame.py", line 726, in compile_inner
    return _compile_inner(code, one_graph, hooks, transform)
  File "/data/users/yidi/pytorch/torch/_dynamo/convert_frame.py", line 760, in _compile_inner
    out_code = transform_code_object(code, transform)
  File "/data/users/yidi/pytorch/torch/_dynamo/bytecode_transformation.py", line 1404, in transform_code_object
    transformations(instructions, code_options)
  File "/data/users/yidi/pytorch/torch/_dynamo/convert_frame.py", line 236, in _fn
    return fn(*args, **kwargs)
  File "/data/users/yidi/pytorch/torch/_dynamo/convert_frame.py", line 680, in transform
    tracer.run()
  File "/data/users/yidi/pytorch/torch/_dynamo/symbolic_convert.py", line 2914, in run
    super().run()
  File "/data/users/yidi/pytorch/torch/_dynamo/symbolic_convert.py", line 1084, in run
    while self.step():
  File "/data/users/yidi/pytorch/torch/_dynamo/symbolic_convert.py", line 994, in step
    self.dispatch_table[inst.opcode](self, inst)
  File "/data/users/yidi/pytorch/torch/_dynamo/symbolic_convert.py", line 2197, in CONTAINS_OP
    self.push(right.call_method(self, "__contains__", [left], {}))
  File "/data/users/yidi/pytorch/torch/_dynamo/variables/user_defined.py", line 818, in call_method
    return super().call_method(tx, name, args, kwargs)
  File "/data/users/yidi/pytorch/torch/_dynamo/variables/base.py", line 413, in call_method
    unimplemented(f"call_method {self} {name} {args} {kwargs}")
  File "/data/users/yidi/pytorch/torch/_dynamo/exc.py", line 361, in unimplemented
    raise Unsupported(msg, case_name=case_name)
torch._dynamo.exc.Unsupported: call_method UserDefinedObjectVariable(set) __contains__ [TorchInGraphFunctionVariable(aten.add)] {}

from user code:
   File "/data/users/yidi/pytorch/test.py", line 10, in f
    if torch.ops.aten.add in op_set:

Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information


You can suppress this exception and fall back to eager by setting:
    import torch._dynamo
    torch._dynamo.config.suppress_errors = True
```

However, when the op_set is a local variable it works fine.

### Versions

on master

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