neonbjb / tortoise-tts

A multi-voice TTS system trained with an emphasis on quality
Apache License 2.0
12.9k stars 1.78k forks source link

Model files not found when installing by docker #818

Open Hamlet626 opened 1 week ago

Hamlet626 commented 1 week ago

I tried to start a tortoise server by writing a docker file installing tortoise and other dependencies, and a python script to run the server, but it always shows error:

File "/opt/program/predictor.py", line 11, in <module>
    tts = TextToSpeech(enable_redaction=False)
  File "/usr/local/lib/python3.10/site-packages/tortoise/api_fast.py", line 215, in __init__
    self.autoregressive.load_state_dict(torch.load(get_model_path('autoregressive.pth', models_dir)), strict=False)
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 1065, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 468, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 449, in __init__
    super().__init__(open(name, mode))

 FileNotFoundError: [Errno 2] No such file or directory: '/opt/ml/model/tortoise/models/models--Manmay--tortoise-tts/snapshots/50672670cecf2265aa61edb4eef5d1a293a8a373/autoregressive.pth'

my docker file is like below (I tried both default and custom model dir, but none works, if I use the default model dir, the error will be something like [No such file or directory: '/root/.cache/tortoise/...']):

FROM python:3.10

# Install system dependencies
RUN apt-get -y update && apt-get install -y --no-install-recommends \
         wget \
         git \
         python3 \
         nginx \
         ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# Install pip using the official installer and upgrade pip
RUN wget https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py && \
    python -m pip install --upgrade pip

# Set environment variables
ENV HF_HOME=/opt/ml/model/huggingface
ENV TORTOISE_MODELS_DIR=/opt/ml/model/tortoise/models

# Install tortoise-tts and additional Python packages
RUN python -m pip install flask gevent gunicorn tortoise-tts spacy && \
    python -m spacy download en

COPY serverDir /opt/program
WORKDIR /opt/program

my predictor.py is like:

from fastapi import FastAPI, Request
from tortoise.api import TextToSpeech
import torch
import io

os.environ['TORTOISE_MODELS_DIR'] = '/opt/ml/model/tortoise/models'

# I used enable_redaction=False, otherwise it's going to raise hugging face model FileNotFoundError as well 
tts_model = TextToSpeech(enable_redaction=False)

#... other code

Does anyone know if I'm setting up tortoise correctly(by just installing the package and call TextToSpeech())? Thanks in advance

Hamlet626 commented 1 week ago

Also I tried to download and upload all the models from https://huggingface.co/Manmay/tortoise-tts/tree/main, but it seems that it requires 'autoregressive.ptt', instead of 'autoregressive.pth' as I saw in source code https://github.com/neonbjb/tortoise-tts/blob/2d6d3868f99d2fb97429741aba7d3a4314ae04aa/tortoise/api_fast.py#L211