Repository: pytorch
Issue: [Dynamo] Dynamo is not aware of the function users override
Labels: triaged,oncall: pt2,module: dynamo

### 🐛 Describe the bug

Hi, we are trying to enabling Llama in Intel HPU, but found graph break in `torch.cuda.current_device()` . We have a package GPU migration tool, it replaces `torch.cuda.current_device()` to `torch.hpu.current_device()`. But we found dynamo is not aware of the function override, and still consider `torch.cuda.current_device()`, eventually leading to graph break or program failed.
Can you give us some suggestions or have any plan to fix it?

### Error logs

Here is a simple case 
```python
import os
os.environ["PT_HPU_LAZY_MODE"] = "0"
import torch
import habana_frameworks.torch.dynamo.compile_backend

def hpu_device():
    return torch.hpu.current_device()

torch.cuda.current_device = hpu_device

@torch.compile(backend="hpu_backend", fullgraph=True)
def foo(x):
    dim_size = list(x.size())
    y = torch.tensor([6], device=torch.cuda.current_device())
    return torch.mul(x, y)

x = torch.tensor([6], device=torch.hpu.current_device())
foo(x)
```

Our GPU migration tool implement, override cuda current_device():
```python
@CudaModuleRegister.register_f()
def current_device() -> int:
    """
    .. py:gpumgrcall:: current_device.hpu_match

    Maps torch.cuda.current_device to torch.hpu.current_device.

    """
    G_LOGGER.info(
        api_type="hpu_match",
        func_prefix="torch.cuda",
        new_call="torch.hpu.current_device()",
    )

    return torch.hpu.current_device()
```


The error gets from dynamo:
```
 File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/bytecode_transformation.py", line 1322, in transform_code_object
    transformations(instructions, code_options)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 219, in _fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 634, in transform
    tracer.run()
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 2796, in run
    super().run()
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 983, in run
    while self.step():
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 895, in step
    self.dispatch_table[inst.opcode](self, inst)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 582, in wrapper
    return inner_fn(self, inst)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 1602, in CALL_FUNCTION
    self.call_function(fn, args, {})
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 830, in call_function
    self.push(fn.call_function(self, args, kwargs))  # type: ignore[arg-type]
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/functions.py", line 727, in call_function
    unimplemented(msg)
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/exc.py", line 297, in unimplemented
    raise Unsupported(msg, case_name=case_name)
torch._dynamo.exc.Unsupported: 'skip function hpu_device in file /root/test.py'

from user code:
   File "/root/test.py", line 14, in foo
    y = torch.tensor([6], device=torch.cuda.current_device())
```

### Versions
```
PyTorch version: 2.5.1a0+git3ba5690
Is debug build: False
CUDA used to build PyTorch: None
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.22.1
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.15.0-122-generic-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
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, 57 bits virtual
Byte Order:                           Little Endian
CPU(s):                               160
On-line CPU(s) list:                  0-159
Vendor ID:                            GenuineIntel
Model name:                           Intel(R) Xeon(R) Platinum 8380 CPU @ 2.30GHz
CPU family:                           6
Model:                                106
Thread(s) per core:                   2
Core(s) per socket:                   40
Socket(s):                            2


Versions of relevant libraries:
[pip3] habana-torch-dataloader==1.19.0.428
[pip3] habana-torch-plugin==1.19.0.428
[pip3] numpy==1.23.5
[pip3] pytorch-lightning==2.4.0
[pip3] torch==2.5.1a0+git3ba5690
[pip3] torch_tb_profiler==0.4.0
[pip3] torchaudio==2.5.1a0+1661daf
[pip3] torchdata==0.9.0+d4bb3e6
[pip3] torchmetrics==1.6.0
[pip3] torchtext==0.18.0a0+9bed85d
[pip3] torchvision==0.20.1a0+3ac97aa
[conda] Could not collect
```

cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @amjames