Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions paconvert/global_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,21 +684,24 @@ class GlobalManager:
"torch.scatter",

# xiangyu
# "torch.cuda.current_device",
# "torch.cuda.device_count",
# "torch.cuda.empty_cache",
"torch.cuda.get_device_properties",
"torch.cuda.get_rng_state",
"torch.cuda.is_current_stream_capturing",
"torch.cuda.manual_seed_all",
# "torch.cuda.memory_allocated",
# "torch.cuda.memory_reserved",
# "torch.cuda.set_device",
"torch.cuda.set_rng_state",
# "torch.get_default_device",
"torch.get_device_module",
"torch.cuda.is_available",
"torch.device",
#Additional additions
"torch.cuda.get_device_capability",

# geyuqiang
"torch.cuda.current_device",
"torch.cuda.device_count",
"torch.cuda.empty_cache",
"torch.cuda.memory_allocated",
"torch.cuda.memory_reserved",
"torch.cuda.set_device",
"torch.cuda.current_stream",
]
2 changes: 1 addition & 1 deletion tests/test_cuda_current_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def compare(
rtol=1.0e-6,
atol=0.0,
):
assert pytorch_result == int(paddle_result.replace("gpu:", ""))
assert pytorch_result == paddle_result
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种也可以直接用APIBase,无需再重写了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的



obj = CudaGetDeviceAPIBase("torch.cuda.current_device")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cuda_set_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
torch.cuda.set_device(0)
torch.cuda.set_device("cuda:0")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前不支持直接set一个int吗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

支持的,但是目前有个情况是,写0会有如下报错,改成cuda:0不会报错,本地测试0和cuda:0均可以通过,我继续定位问题
device = 0
2025-09-26 11:59:15
2025-09-26 11:59:15 def set_device(device: DeviceLike) -> None:
2025-09-26 11:59:15 if isinstance(device, int):
2025-09-26 11:59:15 # Convert int device index to string format (e.g., 0 -> 'gpu:0')
2025-09-26 11:59:15 device_place = framework.current_expected_place()
2025-09-26 11:59:15 if isinstance(device_place, core.CUDAPlace):
2025-09-26 11:59:15 device_str = f'gpu:{device}'
2025-09-26 11:59:15 elif isinstance(device_place, core.CustomPlace):
2025-09-26 11:59:15 device_str = f'{device_place.get_device_type()}:{device}'
2025-09-26 11:59:15 elif isinstance(device_place, core.XPUPlace):
2025-09-26 11:59:15 device_str = f'xpu:{device}'
2025-09-26 11:59:15 else:
2025-09-26 11:59:15 > raise ValueError(
2025-09-26 11:59:15 "Paddle-CPU is not supported. Please use PaddlePaddle with CUDA, XPU or Custom Device"
2025-09-26 11:59:15 E ValueError: Paddle-CPU is not supported. Please use PaddlePaddle with CUDA, XPU or Custom Device

result = torch.cuda.current_device()
"""
)
Expand Down