feat: add model download and conversion
Browse files- server/setup.py +25 -0
server/setup.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys, os
|
2 |
+
from huggingface_hub import snapshot_download
|
3 |
+
import ctranslate2
|
4 |
+
|
5 |
+
|
6 |
+
def download_model():
|
7 |
+
model_id = "JustFrederik/sugoi-v4-ja-en-ct2"
|
8 |
+
local_folder = snapshot_download(repo_id=model_id, local_dir="./fairseq_model")
|
9 |
+
print(f"Files downloaded in: {local_folder}")
|
10 |
+
|
11 |
+
def convert_model():
|
12 |
+
model_dir = "./fairseq_model"
|
13 |
+
output_dir = "./server/ctranslate2_model"
|
14 |
+
if os.path.exists(output_dir) and "-overwrite" not in sys.argv: return
|
15 |
+
|
16 |
+
print("Converting...")
|
17 |
+
converter = ctranslate2.converters.FairseqConverter(model_dir)
|
18 |
+
converter.convert(output_dir) # Você pode escolher entre "int8", "float16" ou deixar como None para não quantizar
|
19 |
+
print(f"Model converted and saved in: {output_dir}")
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
if __name__ == "__name__":
|
24 |
+
if "-download" in sys.argv: download_model()
|
25 |
+
convert_model()
|