Skip to content

Commit a80cb17

Browse files
authored
Merge pull request #16 from audiohacking/copilot/fix-decoding-audio-error
Fix MPS dtype mismatch in audio decoding and app relaunch on close
2 parents 5962c22 + 6273ae9 commit a80cb17

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

backend/app/services/music_service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,14 +822,16 @@ def _pad_audio_token(token):
822822
if callback is not None:
823823
callback(95, "Decoding audio...")
824824

825+
# Get codec dtype once for consistency
826+
codec_dtype = getattr(pipeline, 'codec_dtype', torch.float32)
827+
825828
# Lazy codec loading: Load HeartCodec only when needed (for 12GB GPU mode)
826829
lazy_codec = getattr(pipeline, '_lazy_codec', False)
827830
if lazy_codec and pipeline._codec is None:
828831
print("[Lazy Loading] Loading HeartCodec for decoding...", flush=True)
829832
codec_path = getattr(pipeline, '_codec_path', None)
830833
if codec_path:
831834
# Use the same dtype as specified in the pipeline for consistency
832-
codec_dtype = getattr(pipeline, 'codec_dtype', torch.float32)
833835
pipeline._codec = HeartCodec.from_pretrained(
834836
codec_path,
835837
device_map=pipeline.codec_device,
@@ -842,7 +844,8 @@ def _pad_audio_token(token):
842844
else:
843845
raise RuntimeError("Cannot load HeartCodec: codec_path not available")
844846

845-
frames_for_codec = frames.to(pipeline.codec_device)
847+
# Convert frames to codec device and dtype (important for MPS float16)
848+
frames_for_codec = frames.to(device=pipeline.codec_device, dtype=codec_dtype)
846849
wav = pipeline.codec.detokenize(frames_for_codec)
847850

848851
# Cleanup codec if using lazy loading (free VRAM for next generation)

launcher.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,25 @@ def run_server():
210210
print("Warning: pywebview not available, falling back to browser")
211211
import webbrowser
212212
webbrowser.open("http://127.0.0.1:8000")
213-
# Keep the server running
214-
while True:
215-
time.sleep(1)
213+
# Keep the server running - wait for user to terminate
214+
print("Server is running. Press Ctrl+C to stop.")
215+
try:
216+
while True:
217+
time.sleep(1)
218+
except KeyboardInterrupt:
219+
print("\nStopping server...")
216220
except Exception as e:
217221
print(f"Error launching window: {e}")
218222
print("Falling back to browser...")
219223
import webbrowser
220224
webbrowser.open("http://127.0.0.1:8000")
221-
# Keep the server running
222-
while True:
223-
time.sleep(1)
225+
# Keep the server running - wait for user to terminate
226+
print("Server is running. Press Ctrl+C to stop.")
227+
try:
228+
while True:
229+
time.sleep(1)
230+
except KeyboardInterrupt:
231+
print("\nStopping server...")
224232

225233
def main():
226234
"""Main entry point."""

0 commit comments

Comments
 (0)