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

Adding deepspeed to xtts-streaming #242

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions xtts-streaming/config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
base_image:
image: htrivedi05/xtts-streaming
python_executable_path: /opt/conda/bin/python
environment_variables:
COQUI_TOS_AGREED: '1'
external_package_dirs: []
model_metadata: {}
model_name: XTTS Streaming
python_version: py310
requirements_file: ./requirements.txt
resources:
accelerator: T4
accelerator: H100
cpu: '3'
memory: 10Gi
use_gpu: true
secrets: {}
system_packages: []
37 changes: 21 additions & 16 deletions xtts-streaming/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import io
import logging
import os
import time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need this.

import wave

import numpy as np
Expand Down Expand Up @@ -32,8 +33,12 @@ def load(self):
config = XttsConfig()
config.load_json(os.path.join(model_path, "config.json"))
self.model = Xtts.init_from_config(config)
self.model.load_checkpoint(config, checkpoint_dir=model_path, eval=True)
# self.model.load_checkpoint(config, checkpoint_dir=model_path, eval=True)
self.model.load_checkpoint(
config, checkpoint_dir=model_path, eval=True, use_deepspeed=True
)
self.model.to(device)
# self.compiled_model = torch.compile(self.model.inference_stream)

self.speaker = {
"speaker_embedding": self.model.speaker_manager.speakers[SPEAKER_NAME][
Expand All @@ -51,6 +56,17 @@ def load(self):
.half()
.tolist(),
}

self.speaker_embedding = (
torch.tensor(self.speaker.get("speaker_embedding"))
.unsqueeze(0)
.unsqueeze(-1)
)
self.gpt_cond_latent = (
torch.tensor(self.speaker.get("gpt_cond_latent"))
.reshape((-1, 1024))
.unsqueeze(0)
)
logging.info("🔥Model Loaded")

def wav_postprocess(self, wav):
Expand All @@ -66,32 +82,21 @@ def predict(self, model_input):
text = model_input.get("text")
language = model_input.get("language", "en")
chunk_size = int(
model_input.get("chunk_size", 150)
model_input.get("chunk_size", 20)
) # Ensure chunk_size is an integer
add_wav_header = False

speaker_embedding = (
torch.tensor(self.speaker.get("speaker_embedding"))
.unsqueeze(0)
.unsqueeze(-1)
)
gpt_cond_latent = (
torch.tensor(self.speaker.get("gpt_cond_latent"))
.reshape((-1, 1024))
.unsqueeze(0)
)

streamer = self.model.inference_stream(
text,
language,
gpt_cond_latent,
speaker_embedding,
self.gpt_cond_latent,
self.speaker_embedding,
stream_chunk_size=chunk_size,
enable_text_splitting=True,
temperature=0.2,
)

for chunk in streamer:
print(type(chunk))
processed_chunk = self.wav_postprocess(chunk)
processed_bytes = processed_chunk.tobytes()
yield processed_bytes
Loading