【问题标题】:How to check if a tensor is on cuda in Pytorch?如何在 Pytorch 中检查张量是否在 cuda 上?
【发布时间】:2021-03-30 12:52:32
【问题描述】:

我有一个张量

t = torch.zeros((4, 5, 6))

如何检查它是否在gpu上?

【问题讨论】:

    标签: python pytorch gpu tensor


    【解决方案1】:

    From the pytorch forum

    使用t.is_cuda

    t = torch.randn(2,2)
    t.is_cuda  # returns False
    t = torch.randn(2,2).cuda()
    t.is_cuda  # returns True
    

    【讨论】:

      猜你喜欢
      • 2021-05-08
      • 1970-01-01
      • 2019-04-21
      • 2021-05-14
      • 2019-01-10
      • 1970-01-01
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      相关资源
      最近更新 更多