# 运行时错误：MPS后端内存不足（MPS已分配：2.00 GB，限制：2.00 GB）

- **ID:** `cuda/mps-memory-pressure`
- **领域:** cuda
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| PyTorch 2.1.0 | active | — | — |
| macOS 14.0 | active | — | — |
| MPS 1.0 | active | — | — |

## 解决方案

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.
   ```

## 无效尝试

- **** — The OS enforces a hard limit on MPS memory allocation. (90% 失败率)
- **** — This is a workaround, not a fix for GPU memory management. (50% 失败率)
