Skip to content

Commit d9e3f88

Browse files
authored
[Feature] multi source download (#3125)
* multi-source download * multi-source download * huggingface download revision * requirement * style * add revision arg * test * pre-commit * Change default download * change requirements.txt * modify English Documentation * documentation * modify model download path * add requirements * error optimization * 连接失败兜底 * 连接失败兜底 * 连接失败兜底 * unit test * unit test * unit test * test * test
1 parent 9408e66 commit d9e3f88

File tree

4 files changed

+56
-17
lines changed

4 files changed

+56
-17
lines changed

fastdeploy/utils.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,15 @@ def retrive_model_from_server(model_name_or_path, revision="master"):
532532
aistudio_download(repo_id=repo_id, revision=revision, local_dir=local_path)
533533
model_name_or_path = local_path
534534
except Exception:
535-
raise Exception(f"The setting model_name_or_path:{model_name_or_path} is not exist.")
535+
if os.path.exists(local_path):
536+
llm_logger.error(
537+
f"Failed to connect to aistudio, but detected that the model directory {local_path} exists. Attempting to start."
538+
)
539+
return local_path
540+
else:
541+
raise Exception(
542+
f"The {revision} of {model_name_or_path} is not exist. Please check the model name or revision."
543+
)
536544
elif model_source == "MODELSCOPE":
537545
try:
538546
from modelscope.hub.snapshot_download import (
@@ -547,7 +555,9 @@ def retrive_model_from_server(model_name_or_path, revision="master"):
547555
modelscope_download(repo_id=repo_id, revision=revision, local_dir=local_path)
548556
model_name_or_path = local_path
549557
except Exception:
550-
raise Exception(f"The setting model_name_or_path:{model_name_or_path} is not exist.")
558+
raise Exception(
559+
f"The {revision} of {model_name_or_path} is not exist. Please check the model name or revision."
560+
)
551561
elif model_source == "HUGGINGFACE":
552562
try:
553563
from huggingface_hub._snapshot_download import (
@@ -565,7 +575,9 @@ def retrive_model_from_server(model_name_or_path, revision="master"):
565575
huggingface_download(repo_id=repo_id, revision=revision, local_dir=local_path)
566576
model_name_or_path = local_path
567577
except Exception:
568-
raise Exception(f"The setting model_name_or_path:{model_name_or_path} is not exist.")
578+
raise Exception(
579+
f"The {revision} of {model_name_or_path} is not exist. Please check the model name or revision."
580+
)
569581
else:
570582
raise ValueError(
571583
f"Unsupported model source: {model_source}, please choose one of ['MODELSCOPE', 'AISTUDIO', 'HUGGINGFACE']"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use-triton-in-paddle
3030
crcmod
3131
fastsafetensors==0.1.14
3232
msgpack
33+
modelscope
3334
opentelemetry-api>=1.24.0
3435
opentelemetry-sdk>=1.24.0
3536
opentelemetry-instrumentation-redis

scripts/coverage_run.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ disabled_tests=(
3838
operators/test_fused_moe.py
3939
layers/test_repetition_early_stopper.py
4040
operators/test_stop_generation_multi_ends.py
41-
utils/test_download.py
4241
graph_optimization/test_cuda_graph.py
4342
)
4443
is_disabled() {

test/utils/test_download.py

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@
55

66

77
class TestAistudioDownload(unittest.TestCase):
8-
def test_retrive_model_from_server_MODELSCOPE(self):
9-
os.environ["FD_MODEL_SOURCE"] = "MODELSCOPE"
10-
os.environ["FD_MODEL_CACHE"] = "./models"
11-
12-
model_name_or_path = "baidu/ERNIE-4.5-0.3B-PT"
13-
revision = "master"
14-
expected_path = f"./models/PaddlePaddle/ERNIE-4.5-0.3B-PT/{revision}"
15-
result = retrive_model_from_server(model_name_or_path, revision)
16-
self.assertEqual(expected_path, result)
17-
18-
os.environ.clear()
8+
"""
9+
Test cases for downloading models from different sources using FastDeploy utilities.
10+
"""
1911

2012
def test_retrive_model_from_server_unsupported_source(self):
13+
"""
14+
Test case for retrieving a model from an unsupported source.
15+
"""
2116
os.environ["FD_MODEL_SOURCE"] = "UNSUPPORTED_SOURCE"
2217
os.environ["FD_MODEL_CACHE"] = "./models"
2318

@@ -27,17 +22,49 @@ def test_retrive_model_from_server_unsupported_source(self):
2722

2823
os.environ.clear()
2924

30-
def test_retrive_model_from_server_model_not_exist(self):
25+
def test_retrive_model_from_modelscope_server_model_not_exist(self):
26+
"""
27+
Test case for retrieving a model from ModelScope server when it doesn't exist.
28+
"""
3129
os.environ["FD_MODEL_SOURCE"] = "MODELSCOPE"
30+
os.environ["FD_MODEL_CACHE"] = "./model"
31+
32+
model_name_or_path = "non_existing_model_modelscope"
33+
34+
with self.assertRaises(Exception):
35+
retrive_model_from_server(model_name_or_path)
36+
37+
os.environ.clear()
38+
39+
def test_retrive_model_from_huggingface_server_model_not_exist(self):
40+
"""
41+
Test case for retrieving a model from Hugging Face server when it doesn't exist.
42+
"""
43+
os.environ["FD_MODEL_SOURCE"] = "HUGGINGFACE"
3244
os.environ["FD_MODEL_CACHE"] = "./models"
3345

34-
model_name_or_path = "non_existing_model"
46+
model_name_or_path = "non_existing_model_hf"
3547

3648
with self.assertRaises(Exception):
3749
retrive_model_from_server(model_name_or_path)
3850

3951
os.environ.clear()
4052

53+
def test_retrive_model_from_aistudio_server_(self):
54+
"""
55+
Test case for retrieving a model from AI Studio server.
56+
"""
57+
os.environ["FD_MODEL_SOURCE"] = "AISTUDIO"
58+
os.environ["FD_MODEL_CACHE"] = "./models"
59+
60+
model_name_or_path = "baidu/ERNIE-4.5-0.3B-PT"
61+
revision = "aaa"
62+
expected_path = "./models/PaddlePaddle/ERNIE-4.5-0.3B-PT"
63+
result = retrive_model_from_server(model_name_or_path, revision)
64+
self.assertEqual(expected_path, result)
65+
66+
os.environ.clear()
67+
4168

4269
if __name__ == "__main__":
4370
unittest.main()

0 commit comments

Comments
 (0)