Add device-agnostic inference support - #38
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the public inference.py entry point to support device-agnostic inference (CUDA/MPS/CPU), removes hard-coded CUDA assumptions, and documents a tested Apple Silicon workflow while adding unit coverage for the new device/IO behavior.
Changes:
- Add
--device auto|cuda|mps|cpuand device selection logic; keep model/input on the same device and write output back on CPU. - Resolve checkpoints from either a local path or by downloading
pytorch_model.binfrom a Hugging Face repo ID. - Add unit tests for device selection and CPU inference, plus Apple Silicon documentation and a macOS arm64 requirements file.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
inference.py |
Device selection, HF/local checkpoint resolution, SoundFile-based IO, and safer CPU writeback. |
tests/test_inference.py |
Unit tests covering select_device() and CPU inference behavior. |
README.md |
Updated inference command and documentation for --device / --checkpoint. |
MACOS_ARM64.md |
Apple Silicon/MPS setup notes and validation details. |
requirements-macos-arm64.txt |
Pinned macOS arm64 inference/smoke-test dependencies. |
.gitignore |
Ignore common local inference outputs and venv/models dirs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Djshinshin
marked this pull request as draft
August 13, 2026 17:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.cuda()calls andCUDA_VISIBLE_DEVICESsetting frominference.py.--device auto|cuda|mps|cpu;autopreserves the existing CUDA-first behavior, then selects MPS, then CPU.JusperLee/Apolloremote checkpoint; custom checkpoints must be existing local files from trusted sources.Compatibility
The upstream environment records PyTorch
2.0.0+cu118and TorchAudio2.0.1+cu118as the original Linux/CUDA baseline. Apple Silicon validation used an Apple M3 with macOS 27.0, native arm64 Python 3.10, and PyTorch/TorchAudio 2.11.0.CUDA remains the first
autochoice and the CUDA inference path is preserved, but CUDA was not hardware-tested on the Apple Silicon validation machine. MPS support can also vary with PyTorch and macOS versions.Tests
python -m unittest discover -s tests -v: 14/14 passed, including trusted checkpoint resolution, rejection of arbitrary/dotted remote IDs, validation ordering, and hard-link protection.python -m py_compile inference.py tests/test_inference.py: passed.python -m pip check: passed.git diff --check: passed.CPU unit tests; it runs compile and mock-based unit tests only and does not claim MPS or CUDA coverage.asserts/input_wav.wavfixture end to end on MPS and CPU after the review fixes.3c9a053913c3016b493ddc0b92e21a4e682e8fb5f872dafc945154155bddf771.0.000249214470387, RMSE2.02574076096e-05, correlation0.999999991468.5.78 s; CPU316.46 son the tested Apple M3.Security and trust boundary
The upstream loader uses
torch.load(..., weights_only=False). To avoid downloading arbitrary serialized objects, the CLI accepts the exact officialJusperLee/Apolloremote ID or an explicitly existing local file only. Missing local files, directories, and all other remote IDs fail clearly. The tested official checkpoint SHA-256 is documented as a reproducibility record, not enforced as a permanent hash gate, so future legitimate official updates are not blocked.Limitations
test.pyand the training configuration retain their existing CUDA assumptions; this PR is limited to the public inference entry point.Copyright and safety
Validation used only the repository's official public fixture. No private music was read or uploaded, and no checkpoint, WAV output, virtual environment, cache, or other generated artifact is included in the commits.
Refs #37