forked from Ksuriuri/index-tts-vllm
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·140 lines (119 loc) · 4.36 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
·140 lines (119 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
#need to set alias within container
alias python=python3
# Set default values if environment variables are not set
MODEL_DIR=${MODEL_DIR:-"checkpoints/"}
MODEL=${MODEL:-"IndexTeam/IndexTTS-1.5"}
VLLM_USE_MODELSCOPE=${VLLM_USE_MODELSCOPE:-1}
DOWNLOAD_MODEL=${DOWNLOAD_MODEL:-1}
CONVERT_MODEL=${CONVERT_MODEL:-1}
PORT=${PORT:-8001}
echo "Starting IndexTTS server..."
echo "Model directory: $MODEL_DIR"
echo "Model: $MODEL"
echo "Use ModelScope: $VLLM_USE_MODELSCOPE"
# Function to check if model directory exists and has required files
check_model_exists() {
if [ ! -d "$MODEL_DIR" ]; then
echo "Model directory $MODEL_DIR does not exist"
return 1
fi
# Check for download completion marker
if [ ! -f "$MODEL_DIR/.download_complete" ]; then
echo "Model download not completed (marker file missing)"
return 1
fi
# Check for essential model files
if [ ! -f "$MODEL_DIR/config.yaml" ] || [ ! -f "$MODEL_DIR/gpt.pth" ] || [ ! -f "$MODEL_DIR/bigvgan_generator.pth" ]; then
echo "Essential model files not found in $MODEL_DIR"
return 1
fi
echo "Model files found in $MODEL_DIR"
return 0
}
# Function to check if model conversion is complete
check_conversion_complete() {
if [ -f "$MODEL_DIR/.conversion_complete" ]; then
echo "Model conversion already completed"
return 0
fi
return 1
}
# Function to download model from HuggingFace
download_from_huggingface() {
echo "Downloading model from HuggingFace: $MODEL"
# Create model directory
mkdir -p "$MODEL_DIR"
# Use huggingface-cli to download the model
if ! huggingface-cli download "$MODEL" --local-dir "$MODEL_DIR" --local-dir-use-symlinks False; then
echo "Error: Failed to download model from HuggingFace"
exit 1
fi
# Create download marker file
touch "$MODEL_DIR/.download_complete"
echo "Download completed successfully!"
}
# Function to download model from ModelScope
download_from_modelscope() {
echo "Downloading model from ModelScope: $MODEL"
# Create model directory
mkdir -p "$MODEL_DIR"
# Use modelscope CLI to download the model
if ! modelscope download --model "$MODEL" --local_dir "$MODEL_DIR"; then
echo "Error: Failed to download model from ModelScope"
exit 1
fi
# Create download marker file
touch "$MODEL_DIR/.download_complete"
echo "Download completed successfully!"
}
# Check if model exists and download if necessary
if [ "$DOWNLOAD_MODEL" = "1" ]; then
if ! check_model_exists; then
echo "Model not found, downloading..."
# Download based on VLLM_USE_MODELSCOPE setting
if [ "$VLLM_USE_MODELSCOPE" = "1" ]; then
download_from_modelscope
else
download_from_huggingface
fi
# Verify download
if ! check_model_exists; then
echo "Error: Model download failed or files are missing"
exit 1
fi
else
echo "Model already exists, skipping download"
fi
else
echo "Model download disabled (DOWNLOAD_MODEL=0)"
if ! check_model_exists; then
echo "Error: Model not found and download is disabled"
exit 1
fi
fi
# Convert model format if requested
if [ "$CONVERT_MODEL" = "1" ]; then
if ! check_conversion_complete; then
echo "Converting model format..."
# Run conversion and capture the exit code
bash convert_hf_format.sh "$MODEL_DIR"
conversion_exit_code=$?
# Check if conversion was successful by verifying the vllm directory exists
if [ $conversion_exit_code -eq 0 ] && [ -d "$MODEL_DIR/vllm" ] && [ -f "$MODEL_DIR/vllm/model.safetensors" ]; then
# Create conversion marker file on success
touch "$MODEL_DIR/.conversion_complete"
echo "Model conversion completed successfully"
else
echo "Error: Model conversion failed (exit code: $conversion_exit_code)"
exit 1
fi
else
echo "Model conversion already completed, skipping"
fi
else
echo "Model conversion disabled (CONVERT_MODEL=0)"
fi
# Start the API server
echo "Starting IndexTTS API server on port $PORT..."
VLLM_USE_V1=0 python3 api_server.py --model_dir "$MODEL_DIR" --port "$PORT" --gpu_memory_utilization="$GPU_MEMORY_UTILIZATION"