myshell-ai / OpenVoice

Instant voice cloning by MyShell.
https://research.myshell.ai/open-voice
MIT License
27.07k stars 2.62k forks source link

Embedding error for Chinese language #272

Open zhouhao27 opened 1 week ago

zhouhao27 commented 1 week ago

Got the following error message:

File "/opt/miniconda3/envs/ollama/lib/python3.10/site-packages/torch/nn/functional.py", line 2264, in embedding return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse) RuntimeError: Placeholder storage has not been allocated on MPS device!

My code which caused the error message in model.tts_to_file:

            model = TTS(language=language, device=self._device)
            speaker_ids = model.hps.data.spk2id

            for speaker_key in speaker_ids.keys():
                speaker_id = speaker_ids[speaker_key]
                speaker_key = speaker_key.lower().replace('_', '-')
                speaker_model_path = f'modules/OpenVoice/checkpoints_v2/base_speakers/ses/{speaker_key}.pth'
                source_se = torch.load(speaker_model_path, map_location=self._device)
                model.tts_to_file(text, speaker_id, src_path, speed=speed)
                save_path = f'{self._output_dir}/output_v2_{speaker_key}_{language}.wav'

I tried all other languages. Only ZH and KR has issue. . But KR is different issue. And I run the test in MeloTTS for Chinese language without any issue.

The full error message:

Building prefix dict from the default dictionary ... Loading model from cache /var/folders/gv/1g4vr17173q0fjt6jr3c6m900000gn/T/jieba.cache Loading model cost 0.253 seconds. Prefix dict has been built successfully. /opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/huggingface_hub/file_download.py:1132: FutureWarning: resume_download is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use force_download=True. warnings.warn( Some weights of the model checkpoint at bert-base-multilingual-uncased were not used when initializing BertForMaskedLM: ['cls.seq_relationship.bias', 'cls.seq_relationship.weight']

  • This IS expected if you are initializing BertForMaskedLM from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
  • This IS NOT expected if you are initializing BertForMaskedLM from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model). /opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/huggingface_hub/file_download.py:1132: FutureWarning: resume_download is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use force_download=True. warnings.warn( 0%| | 0/2 [00:04<?, ?it/s] Traceback (most recent call last): File "/Users/zhouhao/Projects/AI/openvoice_example/main.py", line 53, in model.tts_to_file(text, speaker_id, src_path, speed=speed) File "/Users/zhouhao/Projects/AI/openvoice_example/modules/MeloTTS/melo/api.py", line 100, in tts_to_file bert, ja_bert, phones, tones, lang_ids = utils.get_text_for_tts_infer(t, language, self.hps, device, self.symbol_to_id) File "/Users/zhouhao/Projects/AI/openvoice_example/modules/MeloTTS/melo/utils.py", line 38, in get_text_for_tts_infer bert = get_bert(norm_text, word2ph, language_str, device) File "/Users/zhouhao/Projects/AI/openvoice_example/modules/MeloTTS/melo/text/init.py", line 34, in get_bert bert = lang_bert_func_map[language](norm_text, word2ph, device) File "/Users/zhouhao/Projects/AI/openvoice_example/modules/MeloTTS/melo/text/chinese_mix.py", line 199, in get_bert_feature return chinese_bert.get_bert_feature(text, word2ph, model_id='bert-base-multilingual-uncased', device=device) File "/Users/zhouhao/Projects/AI/openvoice_example/modules/MeloTTS/melo/text/chinese_bert.py", line 35, in get_bert_feature res = model(inputs, output_hidden_states=True) File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, *kwargs) File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(args, kwargs) File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/transformers/models/bert/modeling_bert.py", line 1358, in forward outputs = self.bert( File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, kwargs) File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, *kwargs) File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/transformers/models/bert/modeling_bert.py", line 1013, in forward embedding_output = self.embeddings( File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(args, kwargs) File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, kwargs) File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/transformers/models/bert/modeling_bert.py", line 230, in forward inputs_embeds = self.word_embeddings(input_ids) File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, *kwargs) File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(args, kwargs) File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/torch/nn/modules/sparse.py", line 163, in forward return F.embedding( File "/opt/miniconda3/envs/openvoice/lib/python3.10/site-packages/torch/nn/functional.py", line 2264, in embedding return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse) RuntimeError: Placeholder storage has not been allocated on MPS device!

Anybody encounter the similar issue? How to solve it? Thanks.

gougang commented 1 week ago

I encountered the same issue

yuichkun commented 6 days ago

I stumbled into the same error too. Turns out it's an issue with MeloTTS: https://github.com/myshell-ai/MeloTTS/issues/9

And this guys comment actually does solve the problem. I monkey-patched the source code in the site-packages directory and made the change he proposes, and it works.

I hope the proper fix will be incorporated in the library code soon, but for now it's good for me as a hobbyist.