cuda resource_error ai_generated partial

运行时错误:MPS后端内存不足(MPS已分配:2.00 GB,限制:2.00 GB)

RuntimeError: MPS backend out of memory (MPS allocated: 2.00 GB, limit: 2.00 GB)

ID: cuda/mps-memory-pressure

其他格式: JSON · Markdown 中文 · English
85%修复率
82%置信度
1证据数
2023-12-05首次发现

版本兼容性

版本状态引入弃用备注
PyTorch 2.1.0 active
macOS 14.0 active
MPS 1.0 active

根因分析

Apple MPS(Metal Performance Shaders)后端有固定的内存限制,即使是在统一内存系统上,大型模型或批量大小也可能耗尽内存。

English

Apple MPS (Metal Performance Shaders) backend has a fixed memory limit that can be exhausted by large models or batch sizes, even on unified memory systems.

generic

官方文档

https://pytorch.org/docs/stable/mps.html

解决方案

  1. Reduce batch size or model size. For example, in PyTorch, set `batch_size = 16` or use gradient accumulation: `optimizer.step()` after multiple `loss.backward()` calls.

无效尝试

常见但无效的做法:

  1. 90% 失败

    The OS enforces a hard limit on MPS memory allocation.

  2. 50% 失败

    This is a workaround, not a fix for GPU memory management.