-
Notifications
You must be signed in to change notification settings - Fork 251
Expand file tree
/
Copy pathprepare_llm_models.sh
More file actions
executable file
·241 lines (219 loc) · 9.45 KB
/
prepare_llm_models.sh
File metadata and controls
executable file
·241 lines (219 loc) · 9.45 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/bash
#
# Copyright 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -e
if [ -z "$1" ]; then
echo "Error: No directory specified."
exit 1
fi
TEXT_GENERATION_MODEL="HuggingFaceTB/SmolLM2-360M-Instruct"
FACEBOOK_MODEL="facebook/opt-125m"
TOKENIZER_FILE="openvino_tokenizer.bin"
LEGACY_MODEL_FILE="1/model.bin"
EMBEDDING_MODEL="thenlper/gte-small"
RERANK_MODEL="BAAI/bge-reranker-base"
VLM_MODEL="OpenVINO/InternVL2-1B-int4-ov"
TTS_MODEL="microsoft/speecht5_tts"
STT_MODEL="openai/whisper-tiny"
# Models for tools testing. Only tokenizers are downloaded.
QWEN3_MODEL="Qwen/Qwen3-8B"
LLAMA3_MODEL="unsloth/Llama-3.1-8B-Instruct"
HERMES3_MODEL="NousResearch/Hermes-3-Llama-3.1-8B"
PHI4_MODEL="microsoft/Phi-4-mini-instruct"
MISTRAL_MODEL="mistralai/Mistral-7B-Instruct-v0.3"
GPT_OSS_MODEL="openai/gpt-oss-20b"
DEVSTRAL_MODEL="unsloth/Devstral-Small-2507"
LFM2_MODEL="LiquidAI/LFM2-2.6B"
GEMMA4_MODEL="OpenVINO/gemma-4-E4B-it-int4-ov"
if [ "$(python3 -c 'import sys; print(sys.version_info[1])')" -le "8" ]; then echo "Prepare models with python > 3.8."; exit 1 ; fi
echo "Downloading LLM testing models to directory $1"
export PIP_EXTRA_INDEX_URL="https://download.pytorch.org/whl/cpu https://storage.openvinotoolkit.org/simple/wheels/nightly"
if [ "$2" = "docker" ]; then
export PATH=$PATH:/opt/intel/openvino/python/bin
python3 -m pip install "optimum-intel"@git+https://github.com/huggingface/optimum-intel.git nncf sentence_transformers==5.3.0 sentencepiece requests
else
python3 -m venv .venv
. .venv/bin/activate
pip3 install -U pip
pip3 install -U -r demos/common/export_models/requirements.txt
fi
mkdir -p $1
if [ -f "$1/$TEXT_GENERATION_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$TEXT_GENERATION_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
python3 demos/common/export_models/export_model.py text_generation --source_model "$TEXT_GENERATION_MODEL" --weight-format int8 --model_repository_path $1
fi
if [ ! -f "$1/$TEXT_GENERATION_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$TEXT_GENERATION_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$FACEBOOK_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$FACEBOOK_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
python3 demos/common/export_models/export_model.py text_generation --source_model "$FACEBOOK_MODEL" --weight-format int8 --model_repository_path $1
fi
if [ ! -f "$1/$FACEBOOK_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$FACEBOOK_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ ! -f "$1/$FACEBOOK_MODEL/chat_template.jinja" ]; then
echo "Copying dummy chat template to $FACEBOOK_MODEL model directory."
cp src/test/llm/dummy_facebook_template.jinja "$1/$FACEBOOK_MODEL/chat_template.jinja"
fi
if [ -f "$1/$TTS_MODEL/$TOKENIZER_FILE" ]; then
echo "Model file $1/$TTS_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
python3 demos/common/export_models/export_model.py text2speech --source_model "$TTS_MODEL" --weight-format int4 --model_repository_path $1 --vocoder microsoft/speecht5_hifigan
fi
if [ ! -f "$1/$TTS_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Model file $1/$TTS_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$STT_MODEL/$TOKENIZER_FILE" ]; then
echo "Model file $1/$STT_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
python3 demos/common/export_models/export_model.py speech2text --source_model "$STT_MODEL" --weight-format int4 --model_repository_path $1
fi
if [ ! -f "$1/$STT_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Model file $1/$STT_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$VLM_MODEL/$TOKENIZER_FILE" ]; then
echo "Model file $1/$VLM_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
hf download "$VLM_MODEL" --local-dir $1/$VLM_MODEL
convert_tokenizer OpenGVLab/InternVL2-1B --with_detokenizer -o $1/$VLM_MODEL # WA to use newer tokenizer model format which supports padding.
fi
if [ ! -f "$1/$VLM_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Model file $1/$VLM_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$EMBEDDING_MODEL/ov/$TOKENIZER_FILE" ]; then
echo "Model file $1/$EMBEDDING_MODEL/ov/$TOKENIZER_FILE exists. Skipping downloading models."
else
python3 demos/common/export_models/export_model.py embeddings_ov --source_model "$EMBEDDING_MODEL" --weight-format int8 --model_repository_path $1 --model_name $EMBEDDING_MODEL/ov
fi
if [ ! -f "$1/$EMBEDDING_MODEL/ov/$TOKENIZER_FILE" ]; then
echo "[ERROR] Model file $1/$EMBEDDING_MODEL/ov/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$RERANK_MODEL/rerank/$LEGACY_MODEL_FILE" ]; then
echo "Model file $1/$RERANK_MODEL/rerank/$LEGACY_MODEL_FILE exists. Skipping downloading models."
else
python3 demos/common/export_models/export_model.py rerank --source_model "$RERANK_MODEL" --weight-format int8 --model_repository_path $1
fi
if [ ! -f "$1/$RERANK_MODEL/rerank/$LEGACY_MODEL_FILE" ]; then
echo "[ERROR] Model file $1/$RERANK_MODEL/rerank/$LEGACY_MODEL_FILE does not exist."
exit 1
fi
if [ -f "$1/$RERANK_MODEL/ov/$TOKENIZER_FILE" ]; then
echo "Model file $1/$RERANK_MODEL/ov/$TOKENIZER_FILE exists. Skipping downloading models."
else
python3 demos/common/export_models/export_model.py rerank_ov --source_model "$RERANK_MODEL" --weight-format int8 --model_repository_path $1 --model_name $RERANK_MODEL/ov
fi
if [ ! -f "$1/$RERANK_MODEL/ov/$TOKENIZER_FILE" ]; then
echo "[ERROR] Model file $1/$RERANK_MODEL/ov/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$QWEN3_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$QWEN3_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
mkdir -p $1/$QWEN3_MODEL
convert_tokenizer $QWEN3_MODEL --with_detokenizer -o $1/$QWEN3_MODEL
fi
if [ ! -f "$1/$QWEN3_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$QWEN3_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$LLAMA3_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$LLAMA3_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
mkdir -p $1/$LLAMA3_MODEL
convert_tokenizer $LLAMA3_MODEL --with_detokenizer -o $1/$LLAMA3_MODEL
fi
if [ ! -f "$1/$LLAMA3_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$LLAMA3_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$HERMES3_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$HERMES3_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
mkdir -p $1/$HERMES3_MODEL
convert_tokenizer $HERMES3_MODEL --with_detokenizer -o $1/$HERMES3_MODEL
fi
if [ ! -f "$1/$HERMES3_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$HERMES3_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$PHI4_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$PHI4_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
mkdir -p $1/$PHI4_MODEL
convert_tokenizer $PHI4_MODEL --with_detokenizer -o $1/$PHI4_MODEL
fi
if [ ! -f "$1/$PHI4_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$PHI4_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$MISTRAL_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$MISTRAL_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
mkdir -p $1/$MISTRAL_MODEL
convert_tokenizer $MISTRAL_MODEL --with_detokenizer -o $1/$MISTRAL_MODEL
fi
if [ ! -f "$1/$MISTRAL_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$MISTRAL_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$GPT_OSS_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$GPT_OSS_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
mkdir -p $1/$GPT_OSS_MODEL
convert_tokenizer $GPT_OSS_MODEL --with_detokenizer -o $1/$GPT_OSS_MODEL
fi
if [ ! -f "$1/$GPT_OSS_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$GPT_OSS_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$DEVSTRAL_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$DEVSTRAL_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
mkdir -p $1/$DEVSTRAL_MODEL
convert_tokenizer $DEVSTRAL_MODEL --with_detokenizer -o $1/$DEVSTRAL_MODEL
fi
if [ ! -f "$1/$DEVSTRAL_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$DEVSTRAL_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$LFM2_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$LFM2_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
mkdir -p $1/$LFM2_MODEL
convert_tokenizer $LFM2_MODEL --with_detokenizer -o $1/$LFM2_MODEL
fi
if [ ! -f "$1/$LFM2_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$LFM2_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi
if [ -f "$1/$GEMMA4_MODEL/$TOKENIZER_FILE" ]; then
echo "Models file $1/$GEMMA4_MODEL/$TOKENIZER_FILE exists. Skipping downloading models."
else
hf download "$GEMMA4_MODEL" --local-dir $1/$GEMMA4_MODEL --include *tokenizer*
fi
if [ ! -f "$1/$GEMMA4_MODEL/$TOKENIZER_FILE" ]; then
echo "[ERROR] Models file $1/$GEMMA4_MODEL/$TOKENIZER_FILE does not exist."
exit 1
fi