Camb-ai / MARS5-TTS

MARS5 speech model (TTS) from CAMB.AI
https://www.camb.ai
GNU Affero General Public License v3.0
2.47k stars 200 forks source link

ImportError - Mars5TTS #21

Closed josiahbryan closed 3 months ago

josiahbryan commented 3 months ago

I followed the QuickStart (https://github.com/Camb-ai/MARS5-TTS?tab=readme-ov-file#quickstart) and copy/pasted code exactly. (did the pip install --upgrade torch torchaudio librosa vocos encodec, etc) - and here's my script. But when I run it, it closes with error (full console log below the script):

ImportError: cannot import name 'Mars5TTS' from partially initialized module 'inference' (most likely due to a circular import) (/Users/josiahbryan/.cache/torch/hub/Camb-ai_mars5-tts_master/inference.py)

Script (mars5.py):

import torch, librosa

mars5, config_class = torch.hub.load('Camb-ai/mars5-tts', 'mars5_english', trust_repo=True)
# The `mars5` contains the AR and NAR model, as well as inference code.
# The `config_class` contains tunable inference config settings like temperature.

# Load reference audio between 1-12 seconds.
wav, sr = librosa.load('/Users/josiahbryan/Downloads/fakePhoneConvoJosiah.wav',
                       sr=mars5.sr, mono=True)
wav = torch.from_numpy(wav)
ref_transcript = "Hey yeah okay...ummm, That sounds great. . Next, we're going to go, and, an' take it, yeah. Okay! Sounds good...when are you coming home? Perfect, okay, talk soon! Thanks, bye."

# Pick whether you want a deep or shallow clone. Set to False if you don't know prompt transcript or want fast inference. Set to True if you know transcript and want highest quality.
deep_clone = True
# Below you can tune other inference settings, like top_k, temperature, top_p, etc...
cfg = config_class(deep_clone=deep_clone, rep_penalty_window=100,
                      top_k=100, temperature=0.7, freq_penalty=3)

ar_codes, output_audio = mars5.tts("The quick brown rat.", wav,
          ref_transcript,
          cfg=cfg)
# output_audio is (T,) shape float tensor corresponding to the 24kHz output audio.

Console Output:

(base) josiahbryan@JosiahscBookPro devel % python mars5.py 
Downloading: "https://github.com/Camb-ai/mars5-tts/zipball/master" to /Users/josiahbryan/.cache/torch/hub/master.zip
Using cache found in /Users/josiahbryan/.cache/torch/hub/Camb-ai_mars5-tts_master
Traceback (most recent call last):
  File "/Users/josiahbryan/devel/rubber/backend/devel/mars5.py", line 3, in <module>
    mars5, config_class = torch.hub.load('Camb-ai/mars5-tts', 'mars5_english', trust_repo=True)
  File "/Users/josiahbryan/miniforge3/lib/python3.10/site-packages/torch/hub.py", line 568, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "/Users/josiahbryan/miniforge3/lib/python3.10/site-packages/torch/hub.py", line 594, in _load_local
    hub_module = _import_module(MODULE_HUBCONF, hubconf_path)
  File "/Users/josiahbryan/miniforge3/lib/python3.10/site-packages/torch/hub.py", line 106, in _import_module
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/josiahbryan/.cache/torch/hub/Camb-ai_mars5-tts_master/hubconf.py", line 7, in <module>
    from inference import Mars5TTS, InferenceConfig
  File "/Users/josiahbryan/.cache/torch/hub/Camb-ai_mars5-tts_master/inference.py", line 12, in <module>
    from mars5.model import CodecLM, ResidualTransformer
  File "/Users/josiahbryan/devel/rubber/backend/devel/mars5.py", line 3, in <module>
    mars5, config_class = torch.hub.load('Camb-ai/mars5-tts', 'mars5_english', trust_repo=True)
  File "/Users/josiahbryan/miniforge3/lib/python3.10/site-packages/torch/hub.py", line 568, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "/Users/josiahbryan/miniforge3/lib/python3.10/site-packages/torch/hub.py", line 594, in _load_local
    hub_module = _import_module(MODULE_HUBCONF, hubconf_path)
  File "/Users/josiahbryan/miniforge3/lib/python3.10/site-packages/torch/hub.py", line 106, in _import_module
    spec.loader.exec_module(module)
  File "/Users/josiahbryan/.cache/torch/hub/Camb-ai_mars5-tts_master/hubconf.py", line 7, in <module>
    from inference import Mars5TTS, InferenceConfig
ImportError: cannot import name 'Mars5TTS' from partially initialized module 'inference' (most likely due to a circular import) (/Users/josiahbryan/.cache/torch/hub/Camb-ai_mars5-tts_master/inference.py)
arnavmehta7 commented 3 months ago

Hey, please check the notebook you can load the model by:

import torch
# load model
mars5, config_class = torch.hub.load('Camb-ai/mars5-tts', 'mars5_english', trust_repo=True)
josiahbryan commented 3 months ago

I will happily try that tomorrow. Please do keep in mind, the code that I was using was copied straight from the readme. Are you saying that the quick start there needs changed as well?

On Thu, Jun 13, 2024, 1:12 AM Arnav Mehta @.***> wrote:

Hey, please check the notebook https://github.com/Camb-ai/MARS5-TTS/blob/master/mars5_demo.ipynb you can load the model by:

import torch# load modelmars5, config_class = torch.hub.load('Camb-ai/mars5-tts', 'mars5_english', trust_repo=True)

— Reply to this email directly, view it on GitHub https://github.com/Camb-ai/MARS5-TTS/issues/21#issuecomment-2164541678, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEZELAODCXWJYPKQVQLU23ZHEZ5ZAVCNFSM6AAAAABJE66U26VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRUGU2DCNRXHA . You are receiving this because you authored the thread.Message ID: @.***>

josiahbryan commented 3 months ago

@arnavmehta7 I literally copied-pasted the import from the notebook -same error. Tried copy/pasting your code, same error. No clue what's going on here - I don't write a lot of python, so not used to reading the stack traces, but it SEEMS a problem in the package published on torch.hub because the error seems to happen inside .cache/torch/hub/Camb-ai_mars5-tts_master/inference.py

So my test file is literally just:

import torch
mars5, config_class = torch.hub.load('Camb-ai/mars5-tts', 'mars5_english', trust_repo=True)

... and it gives the same error:

ImportError: cannot import name 'Mars5TTS' from partially initialized module 'inference' (most likely due to a circular import) (/Users/josiahbryan/.cache/torch/hub/Camb-ai_mars5-tts_master/inference.py)

So yeah, something still very broken. Any suggestions on how to fix?

matus-pikuliak commented 3 months ago

Try renaming the mars5.py file to something else. It shadows the name of the package so that might cause some issues.

josiahbryan commented 3 months ago

WOW - that was IT... reason number 1,024 on why I can't stand python lol. Consider issue closed. So stupid. (Python, not you)

slx965 commented 2 months ago

How do I load the local model?