Skip to content

Comments

Fix autocast for MPS devices in music generation pipeline#12

Merged
lmangani merged 2 commits intomainfrom
copilot/fix-mps-device-type-issue
Jan 29, 2026
Merged

Fix autocast for MPS devices in music generation pipeline#12
lmangani merged 2 commits intomainfrom
copilot/fix-mps-device-type-issue

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

PyTorch's torch.autocast() doesn't support the 'mps' device type, causing generation to fail on Apple Metal with RuntimeError: User specified an unsupported autocast device_type 'mps'.

Changes

  • Added get_autocast_context() helper that returns nullcontext() for MPS devices (no-op since MPS pipelines use float32) and torch.autocast() for supported devices (cuda/cpu/xpu)
  • Updated generation loops to use the helper instead of direct torch.autocast() calls
# Before
with torch.autocast(device_type=pipeline.mula_device.type, dtype=pipeline.mula_dtype):
    curr_token = pipeline.mula.generate_frame(...)

# After  
with get_autocast_context(pipeline.mula_device.type, pipeline.mula_dtype):
    curr_token = pipeline.mula.generate_frame(...)

The MPS path becomes a no-op context manager while CUDA/CPU behavior remains unchanged.

Original prompt

This section details on the original issue you should resolve

<issue_title>Generation Failed: User specified an unsupported autocast device_type 'mps'</issue_title>
<issue_description>```
Generation Failed: User specified an unsupported autocast device_type 'mps'


This is a blocker. We need to test generation in CI and make sure it actually runs on Apple MPS CPU/GPU
Our app is designed for Apple Metal CPU/GPUs and must fully support them for generation. Lets review the code carefully and fix this.</issue_description>

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

<comments>
</comments>


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

Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix generation failure for unsupported autocast device_type 'mps' Fix autocast for MPS devices in music generation pipeline Jan 29, 2026
Copilot AI requested a review from lmangani January 29, 2026 17:05
@lmangani lmangani marked this pull request as ready for review January 29, 2026 17:12
@lmangani lmangani merged commit ed752fb 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: User specified an unsupported autocast device_type 'mps'

2 participants