Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add str type to device parameter of torch.cuda.get_device_name() on the doc #126400

Closed
hyperkai opened this issue May 16, 2024 · 2 comments
Closed
Labels
actionable module: cuda Related to torch.cuda, and CUDA support in general module: python frontend For issues relating to PyTorch's Python frontend triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@hyperkai
Copy link

hyperkai commented May 16, 2024

📚 The doc issue

The doc explains device parameter but it doesn't have str type as shown below:

device (torch.device or int, optional) – device for which to return the name. This function is a no-op if this argument is a negative integer. It uses the current device, given by current_device(), if device is None (default).

Actually, device parameter with str type works as shown below:

import torch

torch.cuda.get_device_name(device='cuda:0') # Tesla T4

Suggest a potential alternative/fix

The doc should also say str type as shown below:

device (torch.device, int or str, optional) – device for which to return ...

cc @ptrblck @msaroufim @albanD

@shink
Copy link
Contributor

shink commented May 17, 2024

this case works because the string you passed in will be used to create an torch.device object, I guess that there are a lot of function signatures that look like this, so I think it's unnecessary to update the doc and any suggestions are welcome

/// Constructs a `Device` from a string description, for convenience.
/// The string supplied must follow the following schema:
/// `(cpu|cuda)[:<device-index>]`
/// where `cpu` or `cuda` specifies the device type, and
/// `:<device-index>` optionally specifies a device index.
/* implicit */ Device(const std::string& device_string);

@hyperkai hyperkai changed the title Add str type to device parameter of torch.cuda.get_device_name() Add str type to device parameter of torch.cuda.get_device_name() on the doc May 19, 2024
@mikaylagawarecki mikaylagawarecki added module: cuda Related to torch.cuda, and CUDA support in general module: python frontend For issues relating to PyTorch's Python frontend triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels May 20, 2024
@albanD
Copy link
Collaborator

albanD commented May 20, 2024

Yes updating the doc sounds good.
If you need typing, you can use

Device = Optional[Union[_device, str, _int]]

pytorch-bot bot pushed a commit that referenced this issue May 30, 2024
…ce_capability()` function (#126743)

Fixes #126400

The `get_device_name()` and `get_device_capability()` allow passing in a string, but it's not stated in the doc.

Pull Request resolved: #126743
Approved by: https://github.com/eqy, https://github.com/kit1980
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable module: cuda Related to torch.cuda, and CUDA support in general module: python frontend For issues relating to PyTorch's Python frontend triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
4 participants