bshall / knn-vc

Voice Conversion With Just Nearest Neighbors
https://bshall.github.io/knn-vc/
Other
431 stars 64 forks source link

Torch Hub CPU inference support #14

Closed skyler14 closed 1 year ago

skyler14 commented 1 year ago

Currently it seems your repository only supports running on GPU, and gives the error

knn_vc = torch.hub.load('bshall/knn-vc', 'knn_vc', prematched=True, trust_repo=True, pretrained=True) 
Using cache found in C:\Users\Skyler/.cache\torch\hub\bshall_knn-vc_master
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Users\Skyler\Documents\startai_tts_foss\.conda\lib\site-packages\torch\hub.py", line 558, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "c:\Users\Skyler\Documents\startai_tts_foss\.conda\lib\site-packages\torch\hub.py", line 587, in _load_local
    model = entry(*args, **kwargs)
  File "C:\Users\Skyler/.cache\torch\hub\bshall_knn-vc_master\hubconf.py", line 20, in knn_vc
    hifigan, hifigan_cfg = hifigan_wavlm(pretrained, progress, prematched, device)
  File "C:\Users\Skyler/.cache\torch\hub\bshall_knn-vc_master\hubconf.py", line 36, in hifigan_wavlm
    generator = HiFiGAN(h).to(device)
  File "c:\Users\Skyler\Documents\startai_tts_foss\.conda\lib\site-packages\torch\nn\modules\module.py", line 1145, in to
    return self._apply(convert)
  File "c:\Users\Skyler\Documents\startai_tts_foss\.conda\lib\site-packages\torch\nn\modules\module.py", line 797, in _apply
    module._apply(fn)
  File "c:\Users\Skyler\Documents\startai_tts_foss\.conda\lib\site-packages\torch\nn\modules\module.py", line 820, in _apply
    param_applied = fn(param)
  File "c:\Users\Skyler\Documents\startai_tts_foss\.conda\lib\site-packages\torch\nn\modules\module.py", line 1143, in convert
    return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
  File "c:\Users\Skyler\Documents\startai_tts_foss\.conda\lib\site-packages\torch\cuda\__init__.py", line 239, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

Can you modify the hubconf to support cpu only systems too.

RF5 commented 1 year ago

The hubconf.py already supports cpu only systems.

The default device is cuda as can be seen in the hubconf file, but you can specify it with a simple keyword argument.

You can load it to cpu only using the current code by specifying device='cpu' in:

knn_vc = torch.hub.load('bshall/knn-vc', 'knn_vc', prematched=True, trust_repo=True, pretrained=True, device='cpu')

I hope that helps!