Closed maxime-fleury closed 1 year ago
at "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\TTS\utils\io.py" at line 83 and line 86 change torch.load(f, map_location=map_location, kwargs) to torch.load(f, map_location=torch.device("cpu"), kwargs)
The problem appears even if you use the new --device mps
option described in #2875, per #2855.
to fix it, just modify this line : https://github.com/coqui-ai/TTS/blob/f829bf50f8cd261a2ef23356cb83f0ac6c3ff6a8/TTS/tts/models/xtts.py#L645
add the device to the map_location from the class :
self.load_state_dict(load_fsspec(model_path, ** map_location=self.device ** )["model"], strict=strict)
i'm not sure if the PR was necessary, ignore it if it doesn't fit the requirements, I didn't really paid attention to the code guidelines ...
[EN]
I had an equivalent problem a few hours ago, tested on hugging face with the basic cpu (without gpu). The problem seems to come from the default model used: tts_models/multilingual/multi-dataset/xtts_v1
. If you want to use a multi-language model, take the second one on the list: tts_models/multilingual/multi-dataset/your_tts
. What's more, you'll probably come across another key_error
error: for a French text, this template takes fr-fr
as the language argument, not fr
. Personally, I find the rendering of model 2 less realistic. But perhaps using a French tts_models/fr/mai/tacotron2-DDC
or the one that follows on the list, you'll get a better result, I haven't tested it. If you're looking for cleaner rendering, try RVC (RVC-Project/Retrieval-based-Voice-Conversion-WebUI). You can train your voice model with your own samples, coupled with TTS, you can get better results, I'll let you find out, there are tutorials on it. Good evening from France.
[FR]
J'ai eu un problème équivalent il y a quelque heure, tester sur hugging face avec le cpu de base (sans gpu). Le poblème semble venir du modèle utilisé par défaut : tts_models/multilingual/multi-dataset/xtts_v1
. Si tu veux utiliser un modèle multi-langue prend le deuxième de la liste, soit : tts_models/multilingual/multi-dataset/your_tts
. De plus, tu rencontreras probablement une autre erreur key_error
, pour un texte français, ce modèle prend fr-fr
comme argument de langue et non fr
. Personnellement, je trouve le rendu du modèle 2 moins réaliste. Mais peut-être qu'en utilisant un français tts_models/fr/mai/tacotron2-DDC
ou celui qui suit sur la liste, tu obtiendras un meilleur résultat, je ne l'ais pas tester. Si tu cherche un rendu plus propre, essaye de voir du coté de RVC (RVC-Project/Retrieval-based-Voice-Conversion-WebUI). Tu peux entrainer ton modèle de voix avec tes propres échantillions, couplé à TTS, tu peux obtenir des meilleurs résultats, je te laisses te renseigner, des tutos existes dessus. Bonsoir de Paris.
at "C:\Users\xxx\AppData\Local\Programs\Python\Python310\lib\site-packages\TTS\utils\io.py" at line 83 and line 86 change torch.load(f, map_location=map_location, kwargs) to torch.load(f, map_location=torch.device("cpu"), kwargs)
Didn't work. Retuned the error:
File "C:\Users\Home\Environments\project\lib\site-packages\TTS\tts\models\xtts.py", line 645, in load_checkpoint
self.load_state_dict(load_fsspec(model_path)["model"], strict=strict)
TypeError: 'NoneType' object is not subscriptable
i'm not sure if the PR was necessary, ignore it if it doesn't fit the requirements, I didn't really paid attention to the code guidelines ...
Didn't work. Retuned error:
File "C:\Users\xxx\Environments\project\lib\site-packages\TTS\tts\models\xtts.py", line 646 self.load_state_dict(load_fsspec(model_path, ** map_location=self.device ** )["model"], strict=strict) ^ SyntaxError: invalid syntax
``When executing the following from the command line:
tts --model_name tts_models/multilingual/multi-dataset/xtts_v1 --text "This is a test" --speaker_wav C:\Users\xxx\OneDrive\Projects\scripts\coqui_TTS\data\source.wav --language_idx en --use_cuda false
I get the same error as others; namely:
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
I then created the following script:
import torch
from TTS.tts.configs.xtts_config import XttsConfig
from TTS.tts.models.xtts import Xtts
config = XttsConfig()
config.load_json(r"C:\Users\xxx\AppData\Local\tts\tts_models--multilingual--multi-dataset--xtts_v1\config.json")
model = Xtts.init_from_config(config)
# Load the model checkpoint using torch.load
checkpoint_path = r"C:\Users\xxx\AppData\Local\tts\tts_models--multilingual--multi-dataset--xtts_v1"
if torch.cuda.is_available():
checkpoint = torch.load(checkpoint_path)
model.load_state_dict(checkpoint['model'])
model.cuda()
else:
checkpoint = torch.load(checkpoint_path, map_location=torch.device('cpu'))
model.load_state_dict(checkpoint['model'])
model.eval()
outputs = model.synthesize(
"It took me quite a long time to develop a voice and now that I have it I am not going to be silent.",
config,
speaker_wav=r"C:\Users\xxx\OneDrive\Projects\Projects\QuranBeheld\scripts\coqui_TTS\data\sh_nuh_ayah_kursi_audacity.wav",
gpt_cond_len=3,
language="en",
)
But I get the strange error:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\xxx\\AppData\\Local\\tts\\tts_models--multilingual--multi-dataset--xtts_v1'
The certainly doesn't seem to be permission issue. So can't explain the above. Any thought?
I'm encountering the same issue when using the example provided in the Readme.md (Running a multi-speaker and multi-lingual model). I've tried a few ways to fix it but none of which I've tried works thus far.
import torch
from TTS.api import TTS
# Get device
device = "cuda" if torch.cuda.is_available() else "cpu"
# List available 🐸TTS models and choose the first one
model_name = TTS().list_models()[0]
# Init TTS
tts = TTS(model_name).to(device)
# Run TTS
# ❗ Since this model is multi-speaker and multi-lingual, we must set the target speaker and the language
# Text to speech with a numpy output
wav = tts.tts("This is a test! This is also a test!!", speaker=tts.speakers[0], language=tts.languages[0])
# Text to speech to a file
tts.tts_to_file(text="Hello world!", speaker=tts.speakers[0], language=tts.languages[0], file_path="output.wav")
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
@JulienRioux same here, did you find any fix?
the fix (#2951 ) is on the dev environment, we'll have to wait the next version release for a publicly available fix.
if you want to use the dev version, you can use :
pip install git+https://github.com/coqui-ai/TTS.git@dev
the fix (#2951 ) is on the dev environment, we'll have to wait the next version release for a publicly available fix. if you want to use the dev version, you can use :
pip install git+https://github.com/coqui-ai/TTS.git@dev
@loupzeur - That did not work for me :(
I am running on windows 11. i5 12th Gen. Python 3.10.11.
I upgraded to TTS Dev version:
My coqui TTS installed packages are:
Running the following command:
tts --model_name tts_models/multilingual/multi-dataset/xtts_v1 --text "This is a test" --speaker_wav C:\Users\xxx\OneDrive\Projects\scripts\coqui_TTS\data\source.wav --language_idx en --use_cuda false
I get the same error:
File "C:\Users\Home\Environments\projectenv\lib\site-packages\torch\serialization.py", line 166, in validate_cuda_device raise RuntimeError('Attempting to deserialize object on a CUDA ' RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
Looking at the resolution of #2951 I see that line 645 of the file xtts.py
has been modified:
Although I used the command:
I thought that the above pip install command would upgrade my installation of TTS, it seems that it didn't. I manually modified the xtts.py
as follows:
However, when running the following from the windows command line:
tts --model_name tts_models/multilingual/multi-dataset/xtts_v1 --text "This is a test" --speaker_wav C:\Users\xxx\OneDrive\Projects\sctts --model_name tts_models/multilingual/multi-dataset/xtts_v1 --text "This is a test" --speaker_wav C:\Users\xxx\OneDrive\Projects\scripts\coqui_TTS\data\source.wav --language_idx en --use_cuda false
I now get the error:
File "C:\Users\Home\Environments\quranbeheld3.10.11\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
PS - I asked ChatGPT:
I then asked:
But checking my pip list I have the required torch packages:
@loupzeur - thoughts and help please :)
if you do it by code, does it work ? my fix only fixed the library, if the executable doesn't transform the argument 'gpu=true' to 'device=cpu' it won't work I guess
Using the following code (where I included my own CPU related workaround(:
import torch
from TTS.tts.configs.xtts_config import XttsConfig
from TTS.tts.models.xtts import Xtts
config = XttsConfig()
config.load_json(r"C:\Users\xxx\AppData\Local\tts\tts_models--multilingual--multi-dataset--xtts_v1\config.json")
model = Xtts.init_from_config(config)
checkpoint_path = r"C:\Users\xxx\AppData\Local\tts\tts_models--multilingual--multi-dataset--xtts_v1"
if torch.cuda.is_available():
checkpoint = torch.load(checkpoint_path)
model.load_state_dict(checkpoint['model'])
model.cuda()
else:
checkpoint = torch.load(checkpoint_path, map_location=torch.device('cpu'))
model.load_state_dict(checkpoint['model'])
model.eval()
outputs = model.synthesize(
"It took me quite a long time to develop a voice and now that I have it I am not going to be silent.",
config,
speaker_wav=r"C:\Users\xxx\OneDrive\Projects\Projects\scripts\coqui_TTS\data\source.wav",
gpt_cond_len=3,
language="en",
)
However, I get the error:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Home\\AppData\\Local\\tts\\tts_models--multilingual--multi-dataset--xtts_v1'
I have tried everything to resolve this error; including:
1) Ran the python script from the command line as admin - same error.
2) Moved the \tts_models--multilingual--multi-dataset--xtts_v1
directory and all files to my Home
directory.
3) Manually downloaded the xtts files from: https://coqui.gateway.scarf.sh/hf-coqui/XTTS-v1
4) Checked the permissions of the files and directory:
icacls C:\Users\xxx\AppData\Local\tts\ C:\Users\xxx\AppData\Local\tts\ NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F) BUILTIN\Administrators:(I)(OI)(CI)(F) DESKTOP-laptop\xxx:(I)(OI)(CI)(F)
C:\Users\xxx\AppData\Local\tts\tts_models--multilingual--multi-dataset--xtts_v1>icacls * config.json NT AUTHORITY\SYSTEM:(I)(F) BUILTIN\Administrators:(I)(F) DESKTOP-laptop\Home:(I)(F)
model.pth NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Administrators:(I)(F)
DESKTOP-laptop\Home:(I)(F)
tos_agreed.txt NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Administrators:(I)(F)
DESKTOP-laptop\Home:(I)(F)
vocab.json NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Administrators:(I)(F)
DESKTOP-laptop\Home:(I)(F)
Successfully processed 4 files; Failed processing 0 files
And with this simpler code, does it work ? this will take care automatically of the model, and configuration.
from TTS.api import TTS
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v1").to('cpu')
tts.tts_to_file(text='my text to speech test',file_path="output.wav",speaker_wav="source.wav",language='en')
I get the error:
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
With the help of chatGPT, I tried the code:
import torch
from TTS.api import TTS
# Load the TTS model with map_location to ensure it's on the CPU
model_path = r"C:\Users\xxx\AppData\Local\tts\tts_models--multilingual--multi-dataset--xtts_v1"
device = torch.device('cpu')
tts = torch.load(model_path, map_location=device)
tts.eval() # Set the model to evaluation mode
# Generate speech to a file
tts.tts_to_file(
text='my text to speech test',
file_path="output.wav",
speaker_wav="source.wav",
language='en'
)
I now get the standard error:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\xxx\\AppData\\Local\\tts\\tts_models--multilingual--multi-dataset--xtts_v1'
are you sure that you have the correct library with the actual fix ?
can you do it with a venv
or conda
environment ? to be sure that you don't have any other version that may take over the dev one.
I don't use windows, so I can't help with the permission problem, can you try to copy the folder's content to the same place your code is ?
Hey @loupzeur
I tried running your code in my virtualenv:
from TTS.api import TTS
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v1").to('cpu')
tts.tts_to_file(text='my text to speech test',file_path="output.wav",speaker_wav="./source.wav",language='en')
It gave me the error:
File "C:\Users\xxx\Environments\xxx\lib\site-packages\torchaudio\backend\soundfile_backend.py", line 233, in load waveform = torch.from_numpy(waveform) RuntimeError: Numpy is not available
As I am running Python==3.10.11
in the virtualenv the requirements.txt
file states I should use numpy==1.22.0
. However, I upgraded to numpy==1.24.3
. This SOLVED the problem!!!
PS - I am still getting permission denied if I try to access the xtts model locally on my PC :☹️That makes no sense whatsoever! I have copied the xtts model directory to the same directory as my script, but I still get the error.☹️
What does you line of code from TTS.api import TTS
do? Does it not use my local xtts model files?
Thanks for all your help. It is much appreciated. Issue boards can be the grave-yard for many people's issue. You are proof that all heros don't wear capes 🦸♂️
Hello, @grabani, no problem, thanks. Its my first contribution here, and I was pretty sure my fix works so I really wanted to understand the problem.
Concerning the permission problem, did you open your folder that causes permissions' problems with the windows navigator ? I'm pretty sure you never allowed your user to get access to it, hence the permissions problem. (you can also check if the permissions' parameters with the navigator gives read access to your user, may be the linux terminal's user from windows doesn't have your user's permission).
Hello, @grabani, no problem, thanks. Its my first contribution here, and I was pretty sure my fix works so I really wanted to understand the problem.
Concerning the permission problem, did you open your folder that causes permissions' problems with the windows navigator ? I'm pretty sure you never allowed your user to get access to it, hence the permissions problem. (you can also check if the permissions' parameters with the navigator gives read access to your user, may be the linux terminal's user from windows doesn't have your user's permission).
i tried your script and it still shows the CUDA error , i am running this in kali linux with python 3.10.3 and TTS 17.04 which is the latest version
at "C:\Users\xxx\AppData\Local\Programs\Python\Python310\lib\site-packages\TTS\utils\io.py" at line 83 and line 86 change torch.load(f, map_location=map_location, kwargs) to torch.load(f, map_location=torch.device("cpu"), kwargs)
Didn't work. Retuned the error:
File "C:\Users\Home\Environments\project\lib\site-packages\TTS\tts\models\xtts.py", line 645, in load_checkpoint self.load_state_dict(load_fsspec(model_path)["model"], strict=strict) TypeError: 'NoneType' object is not subscriptable
Did you find any fix?
I'm encountering the same issue when using the example provided in the Readme.md (Running a multi-speaker and multi-lingual model). I've tried a few ways to fix it but none of which I've tried works thus far.
import torch from TTS.api import TTS # Get device device = "cuda" if torch.cuda.is_available() else "cpu" # List available 🐸TTS models and choose the first one model_name = TTS().list_models()[0] # Init TTS tts = TTS(model_name).to(device) # Run TTS # ❗ Since this model is multi-speaker and multi-lingual, we must set the target speaker and the language # Text to speech with a numpy output wav = tts.tts("This is a test! This is also a test!!", speaker=tts.speakers[0], language=tts.languages[0]) # Text to speech to a file tts.tts_to_file(text="Hello world!", speaker=tts.speakers[0], language=tts.languages[0], file_path="output.wav")
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
Did you find any fix?
Duplicate #2980
if you do it by code, does it work ? my fix only fixed the library, if the executable doesn't transform the argument 'gpu=true' to 'device=cpu' it won't work I guess
it works for me , ths
Describe the bug
Here is the bug:
Also doesn't work with a file:
Environment
Additional context
No response