在 Apple M1 上运行 PyTorch MPS 加速,得到“Placeholder storage has not been allocate on MPS device!”错误,但一切似乎都在设备上

问题描述 投票:0回答:1

我注意到有些人遇到了这个问题。我正在运行 PyTorch 2.4.0.dev20240326 的夜间版本,并尝试使用 Mac 的 GPU 来加速训练。我遇到了可怕的“运行时错误:尚未在 MPS 设备上分配占位符存储!”。我想我明白,当“计算所需的东西没有正确加载到 GPU 上”时,就会发生这种情况。

如果我打电话:

torch.backends.mps.is_available()

我明白了。

我通常对如何以及何时应该将东西“移动”到设备以加速训练感到困惑,但根据这个答案我从断点尝试了以下操作:

state
tensor([0., 3., 0.])
ipdb>  state.to(torch.device("mps"))
tensor([0., 3., 0.], device='mps:0')
ipdb>  self.net.to(torch.device("mps"))
Policy_Network(
  (shared_net): Sequential(
    (0): Linear(in_features=3, out_features=4, bias=True)
    (1): Tanh()
    (2): Linear(in_features=4, out_features=4, bias=True)
    (3): Tanh()
  )
  (output_net): Sequential(
    (0): Linear(in_features=4, out_features=2, bias=True)
    (1): Softmax(dim=-1)
  )
)
ipdb>  self.net.state_dict()
OrderedDict({'shared_net.0.weight': tensor([[ 0.2975, -0.2548, -0.1119],
        [ 0.2710, -0.5435,  0.3462],
        [-0.1188,  0.2937,  0.0803],
        [-0.0707,  0.1601,  0.0285]], device='mps:0'), 'shared_net.0.bias': tensor([ 0.2109, -0.2250, -0.0421, -0.0520], device='mps:0'), 'shared_net.2.weight': tensor([[ 0.0725, -0.0020,  0.4371,  0.1556],
        [-0.1862, -0.3020, -0.0838, -0.2157],
        [-0.1602,  0.0239,  0.2981,  0.2718],
        [-0.4888,  0.3100,  0.1397,  0.4743]], device='mps:0'), 'shared_net.2.bias': tensor([ 0.3300, -0.4556, -0.4754, -0.2412], device='mps:0'), 'output_net.0.weight': tensor([[ 0.4391, -0.0833,  0.2140, -0.2324],
        [ 0.4906, -0.2115,  0.3750,  0.0059]], device='mps:0'), 'output_net.0.bias': tensor([-0.2634,  0.2570], device='mps:0')})
ipdb>  action_probs = self.net(state)
*** RuntimeError: Placeholder storage has not been allocated on MPS device!

(错误仍然存在)。这对我来说没有意义,因为模型和数据(状态)似乎都在 MPS 设备上。该网络(正如您可能看到的)是一个简单的 torch.nn.module。这有意义/有人对为什么会发生这种情况有任何建议吗?我觉得this可能相关,但我还没有确定任何其他参数......

pytorch gpu apple-m1 hardware-acceleration metal-performance-shaders
1个回答
0
投票

我也遇到了同样的问题!,enter image description here

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.