0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【エラー対処】TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.

Posted at

開発環境

Python 3.10.16
pytorch 2.5.1 py3.10_0 pytorch

↓↓↓Visual Studio Code↓↓↓
バージョン: 1.98.2
コミット: ddc367ed5c8936efe395cffeec279b04ffd7db78
日付: 2025-03-12T13:32:45.399Z
Electron: 34.2.0
ElectronBuildId: 11161602
Chromium: 132.0.6834.196
Node.js: 20.18.2
V8: 13.2.152.36-electron.0
OS: Darwin arm64 24.2.0

エラー内容

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[16], line 67
     65 imgs = imgs.to(device).float()
     66 # imgs = torch.squeeze(imgs)
---> 67 masks = masks.to(device).float()
     68 masks = masks.view(imgs.shape[0], -1, 256, 256)
     70 optimizer.zero_grad()

TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.

対処法


#Apple SiliconののGPUを使用する場合はmpsを指定する
device = torch.device("mps" if torch.mps.is_available() else "cpu")

masks.to(device).float() #これだとエラー

#↓

masks.float().to(device)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?