How to load a model instead of only its weights?

username: Aimone
cooked: <p>I used Coqui-TTS with MPS device and pytorch==2.7.0.dev,and it just showed this.How to solve it without changing the codes in Coqui-TTS as it is a pypi repository?</p>
<blockquote>
<blockquote>
<blockquote>
<p>tts = TTS(“tts_models/multilingual/multi-dataset/xtts_v2”).to(device)<br>
tts_models/multilingual/multi-dataset/xtts_v2 is already downloaded.<br>
Using model: xtts<br>
Traceback (most recent call last):<br>
File “”, line 1, in <br>
File “/opt/anaconda3/envs/coqui/lib/python3.10/site-packages/TTS/api.py”, line 74, in <strong>init</strong><br>
self.load_tts_model_by_name(model_name, gpu)<br>
File “/opt/anaconda3/envs/coqui/lib/python3.10/site-packages/TTS/api.py”, line 177, in load_tts_model_by_name<br>
self.synthesizer = Synthesizer(<br>
File “/opt/anaconda3/envs/coqui/lib/python3.10/site-packages/TTS/utils/synthesizer.py”, line 109, in <strong>init</strong><br>
self._load_tts_from_dir(model_dir, use_cuda)<br>
File “/opt/anaconda3/envs/coqui/lib/python3.10/site-packages/TTS/utils/synthesizer.py”, line 164, in _load_tts_from_dir<br>
self.tts_model.load_checkpoint(config, checkpoint_dir=model_dir, eval=True)<br>
File “/opt/anaconda3/envs/coqui/lib/python3.10/site-packages/TTS/tts/models/xtts.py”, line 773, in load_checkpoint<br>
checkpoint = self.get_compatible_checkpoint_state_dict(model_path)<br>
File “/opt/anaconda3/envs/coqui/lib/python3.10/site-packages/TTS/tts/models/xtts.py”, line 714, in get_compatible_checkpoint_state_dict<br>
checkpoint = load_fsspec(model_path, map_location=torch.device(“cpu”))[“model”]<br>
File “/opt/anaconda3/envs/coqui/lib/python3.10/site-packages/TTS/utils/io.py”, line 54, in load_fsspec<br>
return torch.load(f, map_location=map_location, **kwargs)<br>
File “/opt/anaconda3/envs/coqui/lib/python3.10/site-packages/torch/serialization.py”, line 1488, in load<br>
raise pickle.UnpicklingError(_get_wo_message(str(e))) from None<br>
_pickle.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.<br>
(1) In PyTorch 2.6, we changed the default value of the <code>weights_only</code> argument in <code>torch.load</code> from <code>False</code> to <code>True</code>. Re-running <code>torch.load</code> with <code>weights_only</code> set to <code>False</code> will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.<br>
(2) Alternatively, to load with <code>weights_only=True</code> please check the recommended steps in the following error message.<br>
WeightsUnpickler error: Unsupported global: GLOBAL TTS.tts.configs.xtts_config.XttsConfig was not an allowed global by default. Please use <code>torch.serialization.add_safe_globals([XttsConfig])</code> or the <code>torch.serialization.safe_globals([XttsConfig])</code> context manager to allowlist this global if you trust this class/function.</p>
</blockquote>
</blockquote>
</blockquote>
<p>Check the documentation of torch.load to learn more about types accepted by default with weights_only <a href="https://pytorch.org/docs/stable/generated/torch.load.html" class="inline-onebox" rel="noopener nofollow ugc">torch.load — PyTorch 2.5 documentation</a>.</p>
<blockquote>
<blockquote>
<blockquote>
<p>wav = tts.tts(text=“Hello world!”, speaker_wav=“my/cloning/audio.wav”, language=“en”)<br>
Traceback (most recent call last):<br>
File “”, line 1, in <br>
NameError: name ‘tts’ is not defined. Did you mean: ‘TTS’?</p>
</blockquote>
</blockquote>
</blockquote>