Skip to content

Commit

Permalink
Optimizing CPU image
Browse files Browse the repository at this point in the history
  • Loading branch information
WeberJulian committed Dec 13, 2023
1 parent 281b1f4 commit 898a5f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
3 changes: 1 addition & 2 deletions server/Dockerfile.cpu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-devel
FROM python:3.11.7
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
Expand All @@ -16,6 +16,5 @@ RUN mkdir -p /app/tts_models
COPY main.py .
ENV USE_CPU=1

ENV NUM_THREADS=2
EXPOSE 80
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
14 changes: 5 additions & 9 deletions server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@
import io
import os
import tempfile
from typing import List, Literal
import wave

import numpy as np
import torch
from fastapi import (
FastAPI,
UploadFile,
Body,
)
import numpy as np
from typing import List
from pydantic import BaseModel

from fastapi import FastAPI, UploadFile, Body
from fastapi.responses import StreamingResponse

from TTS.tts.configs.xtts_config import XttsConfig
from TTS.tts.models.xtts import Xtts
from TTS.utils.generic_utils import get_user_data_dir
from TTS.utils.manage import ModelManager

torch.set_num_threads(int(os.environ.get("NUM_THREADS", "2")))
torch.set_num_threads(int(os.environ.get("NUM_THREADS", os.cpu_count())))
device = torch.device("cuda" if os.environ.get("USE_CPU", "0") == "0" else "cpu")
if not torch.cuda.is_available() and device == "cuda":
raise RuntimeError("CUDA device unavailable, please use Dockerfile.cpu instead.")
Expand Down

0 comments on commit 898a5f2

Please sign in to comment.