Skip to content

Conversation

fxyfxy777
Copy link
Contributor

@fxyfxy777 fxyfxy777 commented Sep 25, 2025

PR Docs

向NO_NEED_CONVERT添加一些CUDA 设备管理类API

PR APIs

docs仓库pr:PaddlePaddle/docs#7470

"torch.cuda.current_device",
"torch.cuda.device_count",
"torch.cuda.empty_cache",
"torch.cuda.memory_allocated",
"torch.cuda.memory_reserved",
"torch.cuda.set_device",

Copy link

paddle-bot bot commented Sep 25, 2025

Thanks for your contribution!

@zhwesky2010
Copy link
Collaborator

zhwesky2010 commented Sep 25, 2025

infoflow 2025-09-25 20-01-14

这几个API修改转写方式会导致出现问题吗,有一个case通过不了

@PaddlePaddle PaddlePaddle deleted a comment from fxyfxy777 Sep 25, 2025
@fxyfxy777
Copy link
Contributor Author

infoflow 2025-09-25 20-01-14 这几个API修改转写方式会导致出现问题吗,有一个case通过不了

我在看这个问题,还没定位到原因

@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Sep 25, 2025
@PaddlePaddle PaddlePaddle unlocked this conversation Sep 25, 2025
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.

好的

"""
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

@zhwesky2010
Copy link
Collaborator

上面问题,下个PR修改吧

@zhwesky2010 zhwesky2010 merged commit 6a533ee into PaddlePaddle:master Sep 26, 2025
8 checks passed
@fxyfxy777 fxyfxy777 deleted the yq_cuda_apis branch September 26, 2025 06:33
@fxyfxy777
Copy link
Contributor Author

上面问题,下个PR修改吧

好的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants