Skip to content

60 add mps support - #61

Merged
ChrisNick92 merged 2 commits into
mainfrom
60-add-mps-support
Apr 6, 2026
Merged

60 add mps support#61
ChrisNick92 merged 2 commits into
mainfrom
60-add-mps-support

Conversation

@ChrisNick92

Copy link
Copy Markdown
Collaborator

Summary

This PR adds explicit device selection support ("cuda", "mps", "cpu") across the training and evaluation pipelines, enabling users on Apple Silicon to leverage the MPS backend. It also includes targeted DataLoader efficiency improvements.

Device Selection

  • Added DeviceName = Literal["cuda", "mps", "cpu"] type alias to schemas/types.py.
  • Refactored get_device() to accept an explicit device argument instead of auto-detecting. Raises a clear ValueError for unavailable or misconfigured devices (e.g. CUDA not available, invalid device_index, device_index passed for MPS).
  • Exposed device and device_index parameters on both Trainer and Evaluator. The device_index is only applicable when device="cuda".
  • Fixed hardcoded "cuda" string in PaSST's mel spectrogram autocast guard — replaced with x.device.type so it works correctly on any device.

DataLoader Efficiency

  • pin_memory is now conditional on device.type == "cuda" in both Trainer and Evaluator — avoids unsupported behavior on MPS and CPU.
  • Added persistent_workers=True (when num_workers > 0) to all DataLoaders — eliminates worker process spawn/kill overhead at every epoch boundary.
  • Optimized pad_collate_fn to use torch.stack when all waveforms in a batch have the same length (e.g. when segment_duration is set), falling back to pad_sequence for variable-length batches.

Documentation

  • Updated README training and evaluation examples and parameter tables to document the new device parameter with all supported options.

@ChrisNick92 ChrisNick92 linked an issue Apr 5, 2026 that may be closed by this pull request
@ChrisNick92
ChrisNick92 merged commit d5413cc into main Apr 6, 2026
9 checks passed
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.

add mps support

1 participant