Skip to content

Fix MPS dtype mismatch in audio decoding and app relaunch on close#16

Merged
lmangani merged 3 commits intomainfrom
copilot/fix-decoding-audio-error
Jan 30, 2026
Merged

Fix MPS dtype mismatch in audio decoding and app relaunch on close#16
lmangani merged 3 commits intomainfrom
copilot/fix-decoding-audio-error

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Audio generation succeeded but decoding failed with invalid type: 'torch.mps.FloatTensor' on Apple Silicon. Additionally, closing the app caused an automatic relaunch.

Changes

Audio decoding dtype mismatch

  • Frames generated on MPS with float16 were moved back from CPU without dtype conversion
  • HeartCodec's detokenize() rejected float32 tensors when codec was loaded with float16
  • Added explicit dtype conversion: frames.to(device=pipeline.codec_device, dtype=codec_dtype)
# Get codec dtype once for consistency
codec_dtype = getattr(pipeline, 'codec_dtype', torch.float32)

# Convert frames to codec device and dtype (critical for MPS float16)
frames_for_codec = frames.to(device=pipeline.codec_device, dtype=codec_dtype)
wav = pipeline.codec.detokenize(frames_for_codec)

App relaunch on close

  • Exception handlers in launcher.py had infinite loops without interrupt handling
  • Added KeyboardInterrupt handlers to allow clean shutdown in fallback mode
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    print("\nStopping server...")
Original prompt

This section details on the original issue you should resolve

<issue_title>Decoding Audio Failure</issue_title>
<issue_description>After PR #14 generation succeeds at a reasonable speed, but once completed it fails with:

Deconding Audio:
Generation Failed: invalid type: 'torch.mps.FloatTensor'

Lets fix this last bug to make sure our generations are correctly decoded to audio.</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 30, 2026 08:48
- Fix MPS float16 dtype conversion for audio decoding in music_service.py
- Add KeyboardInterrupt handling in launcher.py exception handlers

Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix decoding audio failure in generation process Fix MPS dtype mismatch in audio decoding and app relaunch on close Jan 30, 2026
Copilot AI requested a review from lmangani January 30, 2026 08:53
@lmangani lmangani marked this pull request as ready for review January 30, 2026 08:53
@lmangani lmangani merged commit a80cb17 into main Jan 30, 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.

Decoding Audio Failure

2 participants