• 文档 >
  • torch 加速器 >
  • torch 加速器.current_accelerator
快捷键

torch 加速器.current_accelerator ¶

torch 加速器.current_accelerator(check_available=False)[source][source] ¶

返回编译时可用加速器的设备。如果编译时没有可用加速器,则返回 None。请参阅加速器获取详细信息。

参数:

check_available (布尔值,可选) – 如果为 True,将在编译时检查的基础上也进行运行时检查,以查看设备 torch.accelerator.is_available() 是否可用。默认: False

返回值:

返回当前加速器为 torch.device

返回类型:

torch.device

注意

返回的 torch.device 的索引将是 None ,请使用 torch.accelerator.current_device_index() 了解当前使用的索引。

示例:

>>> # If an accelerator is available, sent the model to it
>>> model = torch.nn.Linear(2, 2)
>>> if (current_device := current_accelerator(check_available=True)) is not None:
>>>     model.to(current_device)

© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,主题由 Read the Docs 提供。

文档

查看 PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源