Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Doesn't respect the cuda flag #2947

Closed
maxime-fleury opened this issue Sep 14, 2023 · 26 comments
Closed

[Bug] Doesn't respect the cuda flag #2947

maxime-fleury opened this issue Sep 14, 2023 · 26 comments
Labels
bug Something isn't working

Comments

@maxime-fleury
Copy link

Describe the bug

Here is the bug:

PS E:\AI> tts --model_name "tts_models/multilingual/multi-dataset/xtts_v1" --text "Ceci est un teste de voix." --language_idx "fr"  --use_cuda False
 > tts_models/multilingual/multi-dataset/xtts_v1 is already downloaded.
 > Using model: xtts
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Scripts\tts.exe\__main__.py", line 7, in <module>
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\bin\synthesize.py", line 401, in main
    synthesizer = Synthesizer(
                  ^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\utils\synthesizer.py", line 109, in __init__
    self._load_tts_from_dir(model_dir, use_cuda)
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\utils\synthesizer.py", line 164, in _load_tts_from_dir
    self.tts_model.load_checkpoint(config, checkpoint_dir=model_dir, eval=True)
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\tts\models\xtts.py", line 645, in load_checkpoint
    self.load_state_dict(load_fsspec(model_path)["model"], strict=strict)
                         ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\utils\io.py", line 86, in load_fsspec
    return torch.load(f, map_location=map_location, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 809, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 1172, in _load
    result = unpickler.load()
             ^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 1142, in persistent_load
    typed_storage = load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 1116, in load_tensor
    wrap_storage=restore_location(storage, location),
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 217, in default_restore_location
    result = fn(storage, location)
             ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 182, in _cuda_deserialize
    device = validate_cuda_device(location)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\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.
PS E:\AI>

Also doesn't work with a file:

from TTS.api import TTS
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v1", gpu=False)

tts.tts_to_file(text="Ceci est un test de voix en utilisant python.",
                file_path="E:\AI\output.wav",
                language="fr")
 > tts_models/multilingual/multi-dataset/xtts_v1 is already downloaded.
 > Using model: xtts
Traceback (most recent call last):
  File "e:\AI\test.py", line 2, in <module>
    tts = TTS("tts_models/multilingual/multi-dataset/xtts_v1", gpu=False)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\api.py", line 81, in __init__
    self.load_tts_model_by_name(model_name, gpu)
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\api.py", line 185, in load_tts_model_by_name
    self.synthesizer = Synthesizer(
                       ^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\utils\synthesizer.py", line 109, in __init__
    self._load_tts_from_dir(model_dir, use_cuda)
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\utils\synthesizer.py", line 164, in _load_tts_from_dir
    self.tts_model.load_checkpoint(config, checkpoint_dir=model_dir, eval=True)
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\tts\models\xtts.py", line 645, in load_checkpoint
    self.load_state_dict(load_fsspec(model_path)["model"], strict=strict)
                         ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\utils\io.py", line 86, in load_fsspec
    return torch.load(f, map_location=map_location, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 809, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 1172, in _load
    result = unpickler.load()
             ^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 1142, in persistent_load
    typed_storage = load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 1116, in load_tensor
    wrap_storage=restore_location(storage, location),
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 217, in default_restore_location
    result = fn(storage, location)
             ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 182, in _cuda_deserialize
    device = validate_cuda_device(location)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\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.
PS C:\Users\Max> ```


### To Reproduce

tts --model_name "tts_models/multilingual/multi-dataset/xtts_v1" --text "Ceci est un teste de voix." --language_idx "fr"  --use_cuda False

### Expected behavior

Generate audio without gpu

### Logs

```shell
PS E:\AI> tts --model_name "tts_models/multilingual/multi-dataset/xtts_v1" --text "Ceci est un teste de voix." --language_idx "fr"  --use_cuda False
 > tts_models/multilingual/multi-dataset/xtts_v1 is already downloaded.
 > Using model: xtts
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Scripts\tts.exe\__main__.py", line 7, in <module>
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\bin\synthesize.py", line 401, in main
    synthesizer = Synthesizer(
                  ^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\utils\synthesizer.py", line 109, in __init__
    self._load_tts_from_dir(model_dir, use_cuda)
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\utils\synthesizer.py", line 164, in _load_tts_from_dir
    self.tts_model.load_checkpoint(config, checkpoint_dir=model_dir, eval=True)
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\tts\models\xtts.py", line 645, in load_checkpoint
    self.load_state_dict(load_fsspec(model_path)["model"], strict=strict)
                         ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\TTS\utils\io.py", line 86, in load_fsspec
    return torch.load(f, map_location=map_location, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 809, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 1172, in _load
    result = unpickler.load()
             ^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 1142, in persistent_load
    typed_storage = load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 1116, in load_tensor
    wrap_storage=restore_location(storage, location),
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 217, in default_restore_location
    result = fn(storage, location)
             ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\torch\serialization.py", line 182, in _cuda_deserialize
    device = validate_cuda_device(location)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Max\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch-2.0.1-py3.11-win-amd64.egg\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.
PS E:\AI>

Environment

- Coqui TTS is LTS version
- OS windows
- GPU (amd 6700xt, meaning no GPU)
- Ryzen 7 7800x
- pip is installed

Additional context

No response

@maxime-fleury maxime-fleury added the bug Something isn't working label Sep 14, 2023
@ibrahimrefai2010
Copy link

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)

@alessandroperilli
Copy link

The problem appears even if you use the new --device mps option described in #2875, per #2855.

@loupzeur
Copy link
Contributor

loupzeur commented Sep 15, 2023

to fix it, just modify this line :

self.load_state_dict(load_fsspec(model_path)["model"], strict=strict)

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)

@loupzeur
Copy link
Contributor

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 ...

@Olivier-true
Copy link

Olivier-true commented Sep 16, 2023

[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.

@grabani
Copy link

grabani commented Sep 16, 2023

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

@grabani
Copy link

grabani commented Sep 16, 2023

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

@grabani
Copy link

grabani commented Sep 16, 2023

``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?

@JulienRioux
Copy link

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.

@GJakobi
Copy link

GJakobi commented Sep 20, 2023

@JulienRioux same here, did you find any fix?

@loupzeur
Copy link
Contributor

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

@grabani
Copy link

grabani commented Sep 21, 2023

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:

  • aiohttp 3.8.4
    anyascii 0.3.2
    bangla 0.0.2
    bnnumerizer 0.0.2
    bnunicodenormalizer 0.1.1
    clip-anytorch 2.5.2
    coqpit 0.0.17
    Cython 0.29.30
    einops 0.6.1
    encodec 0.1.1
    Flask 2.3.2
    fsspec 2023.6.0
    g2pkk 0.1.2
    gruut 2.2.3
    gruut-ipa 0.13.0
    gruut-lang-de 2.0.0
    gruut-lang-en 2.0.0
    gruut-lang-es 2.0.0
    gruut-lang-fr 2.0.2
    inflect 5.6.0
    jamo 0.4.1
    jieba 0.42.1
    librosa 0.10.0
    matplotlib 3.7.1
    nltk 3.8.1
    numba 0.57.0
    numpy 1.22.0
    packaging 23.1
    pandas 2.0.3
    pypinyin 0.49.0
    pysbd 0.3.4
    PyYAML 6
    scipy 1.11.2
    soundfile 0.12.1
    torch 2.0.1
    torchaudio 2.0.2
    torchdiffeq 0.2.3
    torchsde 0.2.5
    torchvision 0.15.2
    tqdm 4.65.0
    trainer 0.0.27
    transformers 4.33.2
    umap-learn 0.5.1
    Unidecode 1.3.6

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.

@grabani
Copy link

grabani commented Sep 21, 2023

Looking at the resolution of #2951 I see that line 645 of the file xtts.py has been modified:

image

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:

image

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:

image

I then asked:

image

But checking my pip list I have the required torch packages:

image

@loupzeur - thoughts and help please :)

@loupzeur
Copy link
Contributor

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

@grabani
Copy link

grabani commented Sep 21, 2023

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

@loupzeur
Copy link
Contributor

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')

@grabani
Copy link

grabani commented Sep 21, 2023

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.

@grabani
Copy link

grabani commented Sep 21, 2023

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'

@loupzeur
Copy link
Contributor

loupzeur commented Sep 21, 2023

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 ?

@grabani
Copy link

grabani commented Sep 21, 2023

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 🦸‍♂️

@loupzeur
Copy link
Contributor

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).

@Lenos500
Copy link

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

@Lenos500
Copy link

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?

@Lenos500
Copy link

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?

@erogol
Copy link
Member

erogol commented Sep 25, 2023

Duplicate #2980

@erogol erogol closed this as completed Sep 25, 2023
@usernamedd
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests