Skip to content

Fix Mac MPS support + PyTorch 2.6+ weights_only compat#248

Open
hewuxingkong wants to merge 1 commit into
Mangio621:mainfrom
hewuxingkong:fix/mac-mps-and-pytorch-2.6-compat
Open

Fix Mac MPS support + PyTorch 2.6+ weights_only compat#248
hewuxingkong wants to merge 1 commit into
Mangio621:mainfrom
hewuxingkong:fix/mac-mps-and-pytorch-2.6-compat

Conversation

@hewuxingkong
Copy link
Copy Markdown

What

Two small fixes that block training on macOS with recent PyTorch:

1. extract_f0_print.py — auto-detect device for RMVPE

RMVPE("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 picks cudampscpu based on what's actually available.

2. extract_feature_print.py — PyTorch 2.6+ weights_only compatibility

PyTorch 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

  • macOS arm64 (M-series), Python 3.9.6, PyTorch 2.8.0
  • Hubert v2 feature extraction: 627 slices in ~2 min on MPS
  • RMVPE F0 extraction: 627 slices in ~2:22 with 4 workers
  • Training (train_nsf_sim_cache_sid_load_pretrain.py) starts and runs epoch 1 end-to-end with pretrained_v2/f0G40k.pth + f0D40k.pth

Notes for reviewer

  • Both changes are minimal (≈10 lines total) and don't alter behavior on Linux/CUDA
  • The torch.load patch is module-global within extract_feature_print.py only; doesn't leak to other scripts

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.
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.

1 participant