Spaces:
Paused
Paused
Create train_orpheus.py
Browse files- train_orpheus.py +42 -0
train_orpheus.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import torch
|
3 |
+
from transformers import Trainer, TrainingArguments
|
4 |
+
from datasets import load_dataset
|
5 |
+
import subprocess
|
6 |
+
|
7 |
+
# Install required packages
|
8 |
+
subprocess.run("pip install git+https://github.com/canopyai/Orpheus-TTS.git", shell=True)
|
9 |
+
subprocess.run("pip install orpheus-speech vllm==0.7.3", shell=True)
|
10 |
+
|
11 |
+
# Load the dataset
|
12 |
+
dataset = load_dataset("Emotional_Speech_Dataset_(ESD)")
|
13 |
+
|
14 |
+
# Get the model
|
15 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
16 |
+
model = AutoModelForCausalLM.from_pretrained("canopylabs/orpheus-3b-0.1-pretrained")
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained("canopylabs/orpheus-3b-0.1-pretrained")
|
18 |
+
|
19 |
+
# Setup training arguments
|
20 |
+
training_args = TrainingArguments(
|
21 |
+
output_dir="./orpheus-finetuned",
|
22 |
+
per_device_train_batch_size=2,
|
23 |
+
gradient_accumulation_steps=4,
|
24 |
+
learning_rate=5e-5,
|
25 |
+
num_train_epochs=3,
|
26 |
+
save_strategy="steps",
|
27 |
+
save_steps=500,
|
28 |
+
)
|
29 |
+
|
30 |
+
# Start training
|
31 |
+
trainer = Trainer(
|
32 |
+
model=model,
|
33 |
+
args=training_args,
|
34 |
+
train_dataset=dataset,
|
35 |
+
tokenizer=tokenizer,
|
36 |
+
)
|
37 |
+
|
38 |
+
trainer.train()
|
39 |
+
|
40 |
+
# Save the model
|
41 |
+
model.save_pretrained("./orpheus-finetuned-model")
|
42 |
+
tokenizer.save_pretrained("./orpheus-finetuned-model")
|