huggingface
runtime_error
ai_generated
partial
运行时错误:MPS设备上未分配占位符存储
RuntimeError: Placeholder storage has not been allocated on MPS device
ID: huggingface/mps-fp16-cast-error
80%修复率
85%置信度
1证据数
2023-06-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| transformers>=4.30.0 | active | — | — | — |
| torch>=2.0.0 | active | — | — | — |
| macOS>=13.0 | active | — | — | — |
根因分析
模型权重或张量在Apple MPS后端上被转换为float16,但MPS不完全支持FP16,导致分配失败。
English
Model weights or tensors are being cast to float16 on Apple MPS backend which does not fully support FP16, causing allocation failure.
官方文档
https://pytorch.org/docs/stable/notes/mps.html解决方案
-
Load model with torch_dtype=torch.float32 and use model.to('mps') without half precision. -
Set environment variable PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 to disable MPS memory allocation optimization.
-
Use CPU fallback by setting device='cpu' and use float16 with CPU if memory is a concern.
无效尝试
常见但无效的做法:
-
95% 失败
MPS backend has limited FP16 support; explicit FP16 casting triggers the error.
-
90% 失败
Half-precision conversion on MPS is not fully implemented and causes memory allocation errors.