-
Notifications
You must be signed in to change notification settings - Fork 57
Description
When I follow this torch_tts_tutorial I got error.
bundle = torchaudio.pipelines.TACOTRON2_WAVERNN_PHONE_LJSPEECH
processor = bundle.get_text_processor()
text = "Hello world! Text to speech!"
with torch.inference_mode():
processed, length = processor(text)
And this error traceback meet this code.
https://github.com/spring-media/DeepPhonemizer/blob/5dce7e27556aef4426f5623baf6351d266a30a73/dp/model/model.py#L293-L312
And when I changed
from
checkpoint = torch.load(checkpoint_path, map_location=device)
to
checkpoint = torch.load(checkpoint_path, map_location=device,weights_only=False)
it works.
So I also issued to pytorch/audio#3911 (comment)
But I don't know exactly which should be made a issue. or both (or torchaudio?)
UnpicklingError Traceback (most recent call last)
Cell In[6], line 7
3 bundle = torchaudio.pipelines.TACOTRON2_WAVERNN_PHONE_LJSPEECH
4 # torch.serialization.safe_globals([bundle.get_text_processor.name])
5 # torch.serialization.add_safe_globals([Preprocessor])
6 # with torch.serialization.safe_globals([Preprocessor]): # Allowlist the Preprocessor class
----> 7 processor = bundle.get_text_processor()
8 text = "Hello world! Text to speech!"
9 with torch.inference_mode():
File /opt/conda/lib/python3.10/site-packages/torchaudio/pipelines/_tts/impl.py:140, in _PhoneMixin.get_text_processor(self, dl_kwargs)
139 def get_text_processor(self, *, dl_kwargs=None) -> Tacotron2TTSBundle.TextProcessor:
--> 140 return _EnglishPhoneProcessor(dl_kwargs=dl_kwargs)
File /opt/conda/lib/python3.10/site-packages/torchaudio/pipelines/_tts/impl.py:47, in _EnglishPhoneProcessor.init(self, dl_kwargs)
45 self._tokens = utils._get_phones()
46 self._mapping = {p: i for i, p in enumerate(self._tokens)}
---> 47 self._phonemizer = utils._load_phonemizer("en_us_cmudict_forward.pt", dl_kwargs=dl_kwargs)
48 self.pattern = r"([[A-Z]+?]|[!'(),.:;? -])"
File /opt/conda/lib/python3.10/site-packages/torchaudio/pipelines/_tts/utils.py:177, in _load_phonemizer(file, dl_kwargs)
175 dl_kwargs = {} if dl_kwargs is None else dl_kwargs
176 download_url_to_file(url, path, **dl_kwargs)
--> 177 return Phonemizer.from_checkpoint(path)
178 finally:
179 logger.setLevel(orig_level)
File /opt/conda/lib/python3.10/site-packages/dp/phonemizer.py:202, in Phonemizer.from_checkpoint(cls, checkpoint_path, device, lang_phoneme_dict)
186 @classmethod
187 def from_checkpoint(cls,
188 checkpoint_path: str,
189 device='cpu',
190 lang_phoneme_dict: Dict[str, Dict[str, str]] = None) -> 'Phonemizer':
191 """Initializes a Phonemizer object from a model checkpoint (.pt file).
192
193 Args:
(...)
199 Phonemizer: Phonemizer object carrying the loaded model and, optionally, a phoneme dictionary.
200 """
--> 202 model, checkpoint = load_checkpoint(checkpoint_path, device=device)
203 applied_phoneme_dict = None
204 if lang_phoneme_dict is not None:
File /opt/conda/lib/python3.10/site-packages/dp/model/model.py:306, in load_checkpoint(checkpoint_path, device)
294 """
295 Initializes a model from a checkpoint (.pt file).
296
(...)
302 and the second element is a dictionary (config).
303 """
305 device = torch.device(device)
--> 306 checkpoint = torch.load(checkpoint_path, map_location=device)
307 model_type = checkpoint['config']['model']['type']
308 model_type = ModelType(model_type)
File /opt/conda/lib/python3.10/site-packages/torch/serialization.py:1524, in load(f, map_location, pickle_module, weights_only, mmap, **pickle_load_args)
1516 return _load(
1517 opened_zipfile,
1518 map_location,
(...)
1521 **pickle_load_args,
1522 )
1523 except pickle.UnpicklingError as e:
-> 1524 raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
1525 return _load(
1526 opened_zipfile,
1527 map_location,
(...)
1530 **pickle_load_args,
1531 )
1532 if mmap:
UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint.
(1) In PyTorch 2.6, we changed the default value of the weights_only argument in torch.load from False to True. Re-running torch.load with weights_only set to False will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
(2) Alternatively, to load with weights_only=True please check the recommended steps in the following error message.
WeightsUnpickler error: Unsupported global: GLOBAL dp.preprocessing.text.Preprocessor was not an allowed global by default. Please use torch.serialization.add_safe_globals([dp.preprocessing.text.Preprocessor]) or the torch.serialization.safe_globals([dp.preprocessing.text.Preprocessor]) context manager to allowlist this global if you trust this class/function.
Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.