VoiceCraft
VoiceCraft copied to clipboard
Error in loading your tuned EnCodec from Huggingface
Hi, @jasonppy, thanks for the model and open-sourcing the code to inspire ML Speech engineers to investigate it!
My question is about loading your pretrained EnCodec model that is stored in HF hub. I installed the env and main packages, downloaded checkpoint from https://huggingface.co/pyp1/VoiceCraft/tree/main and tried to use it. But got the following error:
phonemization
load tokenizer
load the encodec model
from audiocraft.solvers import CompressionSolver model = CompressionSolver.model_from_checkpoint("/home/jovyan/kda/VoiceCraft/exp/encodec_4cb2048_giga.th") model = model.cuda() model = model.eval()
Output:
MissingConfigException Traceback (most recent call last) Cell In[9], line 5 1 ### phonemization 2 # load tokenizer 3 # load the encodec model 4 from audiocraft.solvers import CompressionSolver ----> 5 model = CompressionSolver.model_from_checkpoint("/home/jovyan/kda/VoiceCraft/exp/encodec_4cb2048_giga.th") 6 model = model.cuda() 7 model = model.eval()
File /home/user/conda/lib/python3.9/site-packages/audiocraft/solvers/compression.py:287, in CompressionSolver.model_from_checkpoint(checkpoint_path, device) 285 logger = logging.getLogger(name) 286 logger.info(f"Loading compression model from checkpoint: {checkpoint_path}") --> 287 _checkpoint_path = checkpoint.resolve_checkpoint_path(checkpoint_path, use_fsdp=False) 288 assert _checkpoint_path is not None, f"Could not resolve compression model checkpoint path: {checkpoint_path}" 289 state = checkpoint.load_checkpoint(_checkpoint_path)
File /home/user/conda/lib/python3.9/site-packages/audiocraft/utils/checkpoint.py:68, in resolve_checkpoint_path(sig_or_path, name, use_fsdp) 56 def resolve_checkpoint_path(sig_or_path: tp.Union[Path, str], name: tp.Optional[str] = None, 57 use_fsdp: bool = False) -> tp.Optional[Path]: 58 """Resolve a given checkpoint path for a provided dora sig or path. 59 60 Args: (...) 66 Path, optional: Resolved checkpoint path, if it exists. 67 """ ---> 68 from audiocraft import train 69 xps_root = train.main.dora.dir / 'xps' 70 sig_or_path = str(sig_or_path)
File /home/user/conda/lib/python3.9/site-packages/audiocraft/train.py:131 126 logger.info("Changing tmpdir to %s", tmpdir) 127 os.environ['TMPDIR'] = str(tmpdir) 130 @hydra_main(config_path='../config', config_name='config', version_base='1.1') --> 131 def main(cfg): 132 init_seed_and_system(cfg) 134 # Setup logging both to XP specific folder, and to stderr.
File /home/user/conda/lib/python3.9/site-packages/dora/hydra.py:308, in hydra_main.
File /home/user/conda/lib/python3.9/site-packages/dora/hydra.py:161, in HydraMain.init(self, main, config_name, config_path, **kwargs) 158 self.full_config_path = self.full_config_path / config_path 160 self._initialized = False --> 161 self._base_cfg = self._get_config() 162 self._config_groups = self._get_config_groups() 163 dora = self._get_dora()
File /home/user/conda/lib/python3.9/site-packages/dora/hydra.py:281, in HydraMain._get_config(self, overrides) 275 """ 276 Internal method, returns the config for the given override, 277 but without the dora.sig field filled. 278 """ 279 with initialize_config_dir(str(self.full_config_path), job_name=self._job_name, 280 **self.hydra_kwargs): --> 281 return self._get_config_noinit(overrides)
File /home/user/conda/lib/python3.9/site-packages/dora/hydra.py:289, in HydraMain._get_config_noinit(self, overrides) 287 cfg = copy.deepcopy(cfg) 288 else: --> 289 cfg = compose(self.config_name, overrides) # type: ignore 290 return cfg
File /home/user/conda/lib/python3.9/site-packages/hydra/compose.py:38, in compose(config_name, overrides, return_hydra_config, strict) 36 gh = GlobalHydra.instance() 37 assert gh.hydra is not None ---> 38 cfg = gh.hydra.compose_config( 39 config_name=config_name, 40 overrides=overrides, 41 run_mode=RunMode.RUN, 42 from_shell=False, 43 with_log_configuration=False, 44 ) 45 assert isinstance(cfg, DictConfig) 47 if not return_hydra_config:
File /home/user/conda/lib/python3.9/site-packages/hydra/_internal/hydra.py:594, in Hydra.compose_config(self, config_name, overrides, run_mode, with_log_configuration, from_shell, validate_sweep_overrides) 576 def compose_config( 577 self, 578 config_name: Optional[str], (...) 583 validate_sweep_overrides: bool = True, 584 ) -> DictConfig: 585 """ 586 :param config_name: 587 :param overrides: (...) 591 :return: 592 """ --> 594 cfg = self.config_loader.load_configuration( 595 config_name=config_name, 596 overrides=overrides, 597 run_mode=run_mode, 598 from_shell=from_shell, 599 validate_sweep_overrides=validate_sweep_overrides, 600 ) 601 if with_log_configuration: 602 configure_log(cfg.hydra.hydra_logging, cfg.hydra.verbose)
File /home/user/conda/lib/python3.9/site-packages/hydra/_internal/config_loader_impl.py:142, in ConfigLoaderImpl.load_configuration(self, config_name, overrides, run_mode, from_shell, validate_sweep_overrides) 133 def load_configuration( 134 self, 135 config_name: Optional[str], (...) 139 validate_sweep_overrides: bool = True, 140 ) -> DictConfig: 141 try: --> 142 return self._load_configuration_impl( 143 config_name=config_name, 144 overrides=overrides, 145 run_mode=run_mode, 146 from_shell=from_shell, 147 validate_sweep_overrides=validate_sweep_overrides, 148 ) 149 except OmegaConfBaseException as e: 150 raise ConfigCompositionException().with_traceback(sys.exc_info()[2]) from e
File /home/user/conda/lib/python3.9/site-packages/hydra/_internal/config_loader_impl.py:243, in ConfigLoaderImpl._load_configuration_impl(self, config_name, overrides, run_mode, from_shell, validate_sweep_overrides) 233 def _load_configuration_impl( 234 self, 235 config_name: Optional[str], (...) 239 validate_sweep_overrides: bool = True, 240 ) -> DictConfig: 241 from hydra import version, version --> 243 self.ensure_main_config_source_available() 244 parsed_overrides, caching_repo = self._parse_overrides_and_create_caching_repo( 245 config_name, overrides 246 ) 248 if validate_sweep_overrides:
File /home/user/conda/lib/python3.9/site-packages/hydra/_internal/config_loader_impl.py:129, in ConfigLoaderImpl.ensure_main_config_source_available(self) 123 else: 124 msg = ( 125 "Primary config directory not found.\nCheck that the" 126 f" config directory '{source.path}' exists and readable" 127 ) --> 129 self._missing_config_error( 130 config_name=None, msg=msg, with_search_path=False 131 )
File /home/user/conda/lib/python3.9/site-packages/hydra/_internal/config_loader_impl.py:102, in ConfigLoaderImpl._missing_config_error(self, config_name, msg, with_search_path) 99 else: 100 return msg --> 102 raise MissingConfigException( 103 missing_cfg_file=config_name, message=add_search_path() 104 )
MissingConfigException: Primary config directory not found. Check that the config directory '/home/user/conda/lib/python3.9/site-packages/audiocraft/../config' exists and readable
So do you have any special config files for your encodec or this is the error with Audiocraft/Hydra package?
UPD.: I reinstalled Audiocraft version using "pip install -e git+https://github.com/facebookresearch/audiocraft.git@c5157b5bf14bf83449c17ea1eeb66c19fb4bc7f0#egg=audiocraft" provided in README. After this got another error "Environment variable 'USER' not found" but it is connected to Audiocraft package: #248
Solution: either set export USER="$(whoami)" in terminal or
import os
os.environ['USER'] = "YOUR_USERNAME"
in Jupyter
after this EnCodec checkpoint is loaded at least
I see no mention of how to get this working on the colab yet tho? It's not generated or uploaded anywhere that I can see. ckpt_fn = "/data/scratch/pyp/exp_pyp/VoiceCraft/gigaspeech/pretrained_830M/best_bundle.pth"
@PylotLight you can download the checkpoint from: https://huggingface.co/pyp1/VoiceCraft/tree/main/encodec_4cb2048_giga.th
and upload to your Colab env maybe? (I'm running on my own Jupyter server based on Docker, so my suggestion could be a mismatch)
@PylotLight you can download the checkpoint from: https://huggingface.co/pyp1/VoiceCraft/tree/main/encodec_4cb2048_giga.th
and upload to your Colab env maybe? (I'm running on my own Jupyter server based on Docker, so my suggestion could be a mismatch)
I already found that, it's one of the two required items. It mentions a checkpoint and a model separately.
UPD.: I reinstalled Audiocraft version using "pip install -e git+https://github.com/facebookresearch/audiocraft.git@c5157b5bf14bf83449c17ea1eeb66c19fb4bc7f0#egg=audiocraft" provided in README. After this got another error "Environment variable 'USER' not found" but it is connected to Audiocraft package: #248
Solution: either set
export USER="$(whoami)"in terminal orimport os os.environ['USER'] = "YOUR_USERNAME"in Jupyter
after this EnCodec checkpoint is loaded at least
After MissingConfigException: Primary config directory not found. I did the same as you but I'm getting "ImportError: cannot import name 'train' from 'audiocraft' ". Did you have something similar?
EDIT: NVM after running the installation again and restarting the jupyter server it works now.
I'm also trying to get this going on Colab, but running into the same problem. Does anyone know a solution to fix MissingConfigException for Audiocraft on Colab? Thanks!
also facing same issue when trying to productionize voicecraft on modal labs
Traceback (most recent call last):
File "/pkg/modal/_container_entrypoint.py", line 488, in handle_user_exception
yield
File "/pkg/modal/_container_entrypoint.py", line 1006, in call_lifecycle_functions
res = func(
^^^^^
File "/root/voicecraft.py", line 149, in on_enter
self.audio_tokenizer = AudioTokenizer(signature=os.path.abspath(encodec_fn), device=device)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/data/tokenizer.py", line 110, in __init__
model = CompressionSolver.model_from_checkpoint(signature)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/audiocraft/solvers/compression.py", line 287, in model_from_checkpoint
_checkpoint_path = checkpoint.resolve_checkpoint_path(checkpoint_path, use_fsdp=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/audiocraft/utils/checkpoint.py", line 68, in resolve_checkpoint_path
from audiocraft import train
File "/usr/local/lib/python3.11/site-packages/audiocraft/train.py", line 124, in <module>
@hydra_main(config_path='../config', config_name='config', version_base='1.1')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/dora/hydra.py", line 308, in _decorator
return HydraMain(main, config_name=config_name, config_path=config_path,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/dora/hydra.py", line 161, in __init__
self._base_cfg = self._get_config()
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/dora/hydra.py", line 281, in _get_config
return self._get_config_noinit(overrides)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/dora/hydra.py", line 289, in _get_config_noinit
cfg = compose(self.config_name, overrides) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/hydra/compose.py", line 38, in compose
cfg = gh.hydra.compose_config(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/hydra/_internal/hydra.py", line 594, in compose_config
cfg = self.config_loader.load_configuration(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/hydra/_internal/config_loader_impl.py", line 142, in load_configuration
return self._load_configuration_impl(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/hydra/_internal/config_loader_impl.py", line 243, in _load_configuration_impl
self.ensure_main_config_source_available()
File "/usr/local/lib/python3.11/site-packages/hydra/_internal/config_loader_impl.py", line 129, in ensure_main_config_source_available
self._missing_config_error(
File "/usr/local/lib/python3.11/site-packages/hydra/_internal/config_loader_impl.py", line 102, in _missing_config_error
raise MissingConfigException(
hydra.errors.MissingConfigException: Primary config directory not found.
Check that the config directory '/usr/local/lib/python3.11/site-packages/audiocraft/../config' exists and readable
Runner failed with exception: MissingConfigException("Primary config directory not found.\nCheck that the config directory '/usr/local/lib/python3.11/site-packages/audiocraft/../config' exists and readable")
can we please reopen this issue @jasonppy? I'm still trying to debug this and have been at it for the past ~5 hours or so 😄
would love some insight into this!
ok so i ended up with a temporary work around and it looks like it's working for me so far
- fork https://github.com/facebookresearch/audiocraft
- Update checkpoint resolving method
resolve_checkpoint_pathto not look for sigs. Code diff available here: https://github.com/dillionverma/audiocraft/commit/677b88630b312af7ba8a0d1a886bee08a97e85aa - Update your VoiceCraft environment to pull the forked version of audiocraft. You can use mine if you like:
git+https://github.com/dillionverma/audiocraft
ok so i ended up with a temporary work around and it looks like it's working for me so far
- fork https://github.com/facebookresearch/audiocraft
- Update checkpoint resolving method
resolve_checkpoint_pathto not look for sigs. Code diff available here: dillionverma/audiocraft@677b886- Update your VoiceCraft environment to pull the forked version of audiocraft. You can use mine if you like:
git+https://github.com/dillionverma/audiocraft
Thanks a ton!! Solve my issue🤩
I had same issue as @dillionverma, do you know why the audiocraft looks for config directory in the wrong place @jasonppy? I didn't see any config setting in the code. And why does @dillionverma hack resolves this?
@jasonppy you can close this, the error causing this is when you install audiocraft repo with:
pip install .
instead of:
pip install -e . , that's why it complains about missing relative paths to config.
also facing same issue when trying to productionize voicecraft on modal labs
Traceback (most recent call last): File "/pkg/modal/_container_entrypoint.py", line 488, in handle_user_exception yield File "/pkg/modal/_container_entrypoint.py", line 1006, in call_lifecycle_functions res = func( ^^^^^ File "/root/voicecraft.py", line 149, in on_enter self.audio_tokenizer = AudioTokenizer(signature=os.path.abspath(encodec_fn), device=device) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/data/tokenizer.py", line 110, in __init__ model = CompressionSolver.model_from_checkpoint(signature) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/audiocraft/solvers/compression.py", line 287, in model_from_checkpoint _checkpoint_path = checkpoint.resolve_checkpoint_path(checkpoint_path, use_fsdp=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/audiocraft/utils/checkpoint.py", line 68, in resolve_checkpoint_path from audiocraft import train File "/usr/local/lib/python3.11/site-packages/audiocraft/train.py", line 124, in <module> @hydra_main(config_path='../config', config_name='config', version_base='1.1') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/dora/hydra.py", line 308, in _decorator return HydraMain(main, config_name=config_name, config_path=config_path, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/dora/hydra.py", line 161, in __init__ self._base_cfg = self._get_config() ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/dora/hydra.py", line 281, in _get_config return self._get_config_noinit(overrides) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/dora/hydra.py", line 289, in _get_config_noinit cfg = compose(self.config_name, overrides) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/hydra/compose.py", line 38, in compose cfg = gh.hydra.compose_config( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/hydra/_internal/hydra.py", line 594, in compose_config cfg = self.config_loader.load_configuration( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/hydra/_internal/config_loader_impl.py", line 142, in load_configuration return self._load_configuration_impl( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/hydra/_internal/config_loader_impl.py", line 243, in _load_configuration_impl self.ensure_main_config_source_available() File "/usr/local/lib/python3.11/site-packages/hydra/_internal/config_loader_impl.py", line 129, in ensure_main_config_source_available self._missing_config_error( File "/usr/local/lib/python3.11/site-packages/hydra/_internal/config_loader_impl.py", line 102, in _missing_config_error raise MissingConfigException( hydra.errors.MissingConfigException: Primary config directory not found. Check that the config directory '/usr/local/lib/python3.11/site-packages/audiocraft/../config' exists and readable Runner failed with exception: MissingConfigException("Primary config directory not found.\nCheck that the config directory '/usr/local/lib/python3.11/site-packages/audiocraft/../config' exists and readable")