# RuntimeError: Placeholder storage has not been allocated on MPS device

- **ID:** `huggingface/mps-fp16-cast-error`
- **Domain:** huggingface
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Model weights or tensors are being cast to float16 on Apple MPS backend which does not fully support FP16, causing allocation failure.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| transformers>=4.30.0 | active | — | — |
| torch>=2.0.0 | active | — | — |
| macOS>=13.0 | active | — | — |

## Workarounds

1. **Load model with torch_dtype=torch.float32 and use model.to('mps') without half precision.** (85% success)
   ```
   Load model with torch_dtype=torch.float32 and use model.to('mps') without half precision.
   ```
2. **Set environment variable PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 to disable MPS memory allocation optimization.** (70% success)
   ```
   Set environment variable PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 to disable MPS memory allocation optimization.
   ```
3. **Use CPU fallback by setting device='cpu' and use float16 with CPU if memory is a concern.** (95% success)
   ```
   Use CPU fallback by setting device='cpu' and use float16 with CPU if memory is a concern.
   ```

## Dead Ends

- **** — MPS backend has limited FP16 support; explicit FP16 casting triggers the error. (95% fail)
- **** — Half-precision conversion on MPS is not fully implemented and causes memory allocation errors. (90% fail)
