Fix Mac MPS support + PyTorch 2.6+ weights_only compat#248
Open
hewuxingkong wants to merge 1 commit into
Open
Conversation
Two small fixes that block training on macOS with recent PyTorch: 1. extract_f0_print.py — RMVPE init was hardcoded to "cuda:0" so it crashed on Macs even when MPS was available. Now auto-detects: cuda → mps → cpu. 2. extract_feature_print.py — fairseq's checkpoint_utils.load_model_ensemble_and_task calls torch.load() without specifying weights_only=False. PyTorch 2.6 flipped the default to True, which rejects fairseq Dictionary pickles. Patches torch.load module-globally before importing fairseq so the existing flow keeps working. Tested with PyTorch 2.8.0 on macOS arm64 (M-series), Python 3.9.6. Hubert + RMVPE both load and run extraction on MPS without errors.
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.
What
Two small fixes that block training on macOS with recent PyTorch:
1.
extract_f0_print.py— auto-detect device for RMVPERMVPE("rmvpe.pt", is_half=False, device=\"cuda:0\")was hardcoded, so on Macs without CUDA the F0 extraction step crashed even though Apple Silicon MPS was available. Now it pickscuda→mps→cpubased on what's actually available.2.
extract_feature_print.py— PyTorch 2.6+ weights_only compatibilityPyTorch 2.6 flipped the default of `torch.load(weights_only=…)` from `False` to `True`, which rejects fairseq's `Dictionary` pickles (used by Hubert). The full error:
```
_pickle.UnpicklingError: Weights only load failed.
WeightsUnpickler error: Unsupported global: GLOBAL fairseq.data.dictionary.Dictionary
```
The fix monkey-patches `torch.load` to inject `weights_only=False` when not specified, before importing fairseq. Same approach the upstream Seed-VC project uses.
Why
These two issues alone are enough to block fresh users running training on a current Mac (MPS-capable, PyTorch ≥ 2.6). With these patches the existing flow works unchanged: feature extraction completes on MPS, F0 extraction completes via RMVPE, training proceeds with the released v2 pretrained weights.
Tested
train_nsf_sim_cache_sid_load_pretrain.py) starts and runs epoch 1 end-to-end withpretrained_v2/f0G40k.pth+f0D40k.pthNotes for reviewer
torch.loadpatch is module-global withinextract_feature_print.pyonly; doesn't leak to other scripts