Skip to content

Commit 7c8c2a1

Browse files
authored
Merge pull request #93 from devsapp/oss-auto
feat: add e2e model tests and refactor model deployment logic
2 parents 4e0bdd6 + 02403fe commit 7c8c2a1

File tree

5 files changed

+195
-128
lines changed

5 files changed

+195
-128
lines changed

__tests__/e2e/ci-mac-linux.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ echo "test model download"
3131
cd model
3232
pip install -r requirements.txt
3333
export fc_component_function_name=model-$(uname)-$(uname -m)-$RANDSTR
34+
# export artifact_endpoint=devs-pre.cn-hangzhou.aliyuncs.com
3435
python deploy_and_test_model.py --model-id iic/cv_LightweightEdge_ocr-recognitoin-general_damo --region cn-shanghai --auto-cleanup
3536
python deploy_and_test_model.py --model-id Qwen/Qwen2.5-0.5B-Instruct --region cn-shanghai --auto-cleanup
37+
# python deploy_and_test_model.py --model-id iic/cv_LightweightEdge_ocr-recognitoin-general_damo --region cn-shanghai --storage oss --auto-cleanup
38+
# python deploy_and_test_model.py --model-id Qwen/Qwen2.5-0.5B-Instruct --region cn-shanghai --storage oss --auto-cleanup
3639
cd ..
3740

3841
echo "test go runtime"

__tests__/e2e/model/deploy_and_test_model.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def simple_hash(input_string: str) -> str:
4242
return sha256_hash[:8] + sha256_hash[-8:]
4343

4444

45-
def deploy_model(model_id: str, region: str = "cn-hangzhou"):
45+
def deploy_model(model_id: str, region: str = "cn-hangzhou", storage: str = "nas"):
4646
"""
4747
部署模型到函数计算
4848
@@ -71,9 +71,7 @@ def deploy_model(model_id: str, region: str = "cn-hangzhou"):
7171
encoded_model_id = urllib.parse.quote(model_id, safe="")
7272

7373
# 调用部署接口
74-
model_registry_url = os.getenv(
75-
"MODEL_REGISTRY_URL", "model-registry.devsapp.cn"
76-
)
74+
model_registry_url = os.getenv("MODEL_REGISTRY_URL", "model-registry.devsapp.cn")
7775
deploy_url = (
7876
f"http://{model_registry_url}/api/v1/models/{encoded_model_id}/deploy-info"
7977
)
@@ -108,6 +106,28 @@ def deploy_model(model_id: str, region: str = "cn-hangzhou"):
108106
# 更新resources中的props
109107
s_yaml["resources"]["test_func"]["props"] = deploy_info
110108

109+
# 下载到 oss
110+
if storage == "oss":
111+
s_yaml["resources"]["test_func"]["props"].pop("nasConfig", None)
112+
s_yaml["resources"]["test_func"]["props"].pop("vpcConfig", None)
113+
s_yaml["resources"]["test_func"]["props"]["ossMountConfig"] = "auto"
114+
s_yaml["resources"]["test_func"]["props"][
115+
"role"
116+
] = "acs:ram::${config('AccountID')}:role/aliyunfcdefaultrole"
117+
s_yaml["resources"]["test_func"]["props"]["annotations"]["modelConfig"][
118+
"storage"
119+
] = storage
120+
# 修改 customContainerConfig.entrypoint 中的路径
121+
custom_container_config = s_yaml["resources"]["test_func"]["props"].get("customContainerConfig", {})
122+
if "entrypoint" in custom_container_config:
123+
entrypoint = custom_container_config["entrypoint"]
124+
if isinstance(entrypoint, list):
125+
# 遍历 entrypoint 数组,替换包含 /mnt/ 的路径
126+
for i, item in enumerate(entrypoint):
127+
if isinstance(item, str) and "/mnt/" in item and not item.startswith("vllm") and not item.isdigit() and item not in ["--port", "--served-model-name", "--trust-remote-code"]:
128+
entrypoint[i] = f"/mnt/serverless-{region}-d5d4cd07-616a-5428-91b7-ec2d0257b3a2"
129+
custom_container_config["entrypoint"] = entrypoint
130+
111131
# 保存配置到临时文件
112132
s_yaml_file = f"s.yaml"
113133
with open(s_yaml_file, "w", encoding="utf-8") as f:
@@ -326,14 +346,9 @@ def cleanup_deployment(s_yaml_file: str):
326346
try:
327347
print(f"正在清除部署资源: {s_yaml_file}")
328348
# 清除模型
329-
subprocess.check_call(
330-
f"echo 123456 | sudo -S s model remove -y -t {s_yaml_file}", shell=True
331-
)
349+
subprocess.check_call(f"s model remove -y -t {s_yaml_file}", shell=True)
332350
# 清除函数
333-
subprocess.check_call(
334-
f"echo 123456 | sudo -S s remove -y -t {s_yaml_file} --skip-push",
335-
shell=True,
336-
)
351+
subprocess.check_call(f"s remove -y -t {s_yaml_file} --skip-push", shell=True)
337352
print("部署资源清除完成!")
338353
except subprocess.CalledProcessError as e:
339354
print(f"清除部署资源失败: {e}")
@@ -354,6 +369,7 @@ def main():
354369
parser.add_argument(
355370
"--auto-cleanup", action="store_true", help="部署和测试完成后自动执行清理操作"
356371
)
372+
parser.add_argument("--storage", help="存储区域", default="nas")
357373

358374
args = parser.parse_args()
359375

@@ -364,7 +380,9 @@ def main():
364380
return 0
365381
elif args.model_id:
366382
# 部署和测试模型
367-
deploy_url, s_yaml_file = deploy_model(args.model_id, args.region)
383+
deploy_url, s_yaml_file = deploy_model(
384+
args.model_id, args.region, args.storage
385+
)
368386

369387
# 测试模型
370388
test_model(args.model_id, deploy_url, s_yaml_file)

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"author": "",
2323
"license": "ISC",
2424
"dependencies": {
25-
"@alicloud/devs20230714": "^2.4.5",
25+
"@alicloud/devs20230714": "^2.4.6-alpha.2",
2626
"@alicloud/fc2": "^2.6.6",
2727
"@alicloud/fc20230330": "4.6.0",
2828
"@alicloud/pop-core": "^1.8.0",

0 commit comments

Comments
 (0)