Skip to content

Comments

Fix MPS out of memory error by disabling PyTorch memory watermark#10

Merged
lmangani merged 2 commits intomainfrom
copilot/fix-generation-failed-issue
Jan 29, 2026
Merged

Fix MPS out of memory error by disabling PyTorch memory watermark#10
lmangani merged 2 commits intomainfrom
copilot/fix-generation-failed-issue

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

PyTorch MPS backend hits a hard memory limit during generation on macOS, failing with "MPS allocated: 27.06 GB, max allowed: 27.20 GB". The error message suggests the fix.

Changes

  • Set PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 in launcher.py at startup
  • Set PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 in music_service.py before generation

This disables PyTorch's MPS memory watermark, allowing full use of unified memory on Apple Silicon/Metal-enabled Macs.

# launcher.py
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
os.environ["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "0.0"

# music_service.py - in _run_pipeline()
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
os.environ["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "0.0"

MPS-only change. No impact on CUDA/CPU paths.

Original prompt

This section details on the original issue you should resolve

<issue_title>Generation Failed</issue_title>
<issue_description>The app starts and loads models but generation fails with:
Generation Failed: MPS backend out of memory (MPS allocated: 27.06 GB, other allocations: 512.00 KB, max allowed: 27.20 GB). Tried to allocate 192.00 MB on private pool. Use PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 to disable upper limit for memory allocations (may cause system failure).</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

… errors

Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix generation failed due to MPS backend out of memory Fix MPS out of memory error by disabling PyTorch memory watermark Jan 29, 2026
Copilot AI requested a review from lmangani January 29, 2026 14:28
@lmangani lmangani marked this pull request as ready for review January 29, 2026 15:22
@lmangani lmangani merged commit 5f7dafc into main Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generation Failed

2 participants