Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions __tests__/e2e/ci-mac-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ echo "test model download"
cd model
pip install -r requirements.txt
export fc_component_function_name=model-$(uname)-$(uname -m)-$RANDSTR
# export artifact_endpoint=devs-pre.cn-hangzhou.aliyuncs.com
python deploy_and_test_model.py --model-id iic/cv_LightweightEdge_ocr-recognitoin-general_damo --region cn-shanghai --auto-cleanup
python deploy_and_test_model.py --model-id Qwen/Qwen2.5-0.5B-Instruct --region cn-shanghai --auto-cleanup
# python deploy_and_test_model.py --model-id iic/cv_LightweightEdge_ocr-recognitoin-general_damo --region cn-shanghai --storage oss --auto-cleanup
# python deploy_and_test_model.py --model-id Qwen/Qwen2.5-0.5B-Instruct --region cn-shanghai --storage oss --auto-cleanup
cd ..

echo "test go runtime"
Expand Down
42 changes: 30 additions & 12 deletions __tests__/e2e/model/deploy_and_test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def simple_hash(input_string: str) -> str:
return sha256_hash[:8] + sha256_hash[-8:]


def deploy_model(model_id: str, region: str = "cn-hangzhou"):
def deploy_model(model_id: str, region: str = "cn-hangzhou", storage: str = "nas"):
"""
部署模型到函数计算

Expand Down Expand Up @@ -71,9 +71,7 @@ def deploy_model(model_id: str, region: str = "cn-hangzhou"):
encoded_model_id = urllib.parse.quote(model_id, safe="")

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

# 下载到 oss
if storage == "oss":
s_yaml["resources"]["test_func"]["props"].pop("nasConfig", None)
s_yaml["resources"]["test_func"]["props"].pop("vpcConfig", None)
s_yaml["resources"]["test_func"]["props"]["ossMountConfig"] = "auto"
s_yaml["resources"]["test_func"]["props"][
"role"
] = "acs:ram::${config('AccountID')}:role/aliyunfcdefaultrole"
s_yaml["resources"]["test_func"]["props"]["annotations"]["modelConfig"][
"storage"
] = storage
# 修改 customContainerConfig.entrypoint 中的路径
custom_container_config = s_yaml["resources"]["test_func"]["props"].get("customContainerConfig", {})
if "entrypoint" in custom_container_config:
entrypoint = custom_container_config["entrypoint"]
if isinstance(entrypoint, list):
# 遍历 entrypoint 数组,替换包含 /mnt/ 的路径
for i, item in enumerate(entrypoint):
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"]:
entrypoint[i] = f"/mnt/serverless-{region}-d5d4cd07-616a-5428-91b7-ec2d0257b3a2"
custom_container_config["entrypoint"] = entrypoint

# 保存配置到临时文件
s_yaml_file = f"s.yaml"
with open(s_yaml_file, "w", encoding="utf-8") as f:
Expand Down Expand Up @@ -326,14 +346,9 @@ def cleanup_deployment(s_yaml_file: str):
try:
print(f"正在清除部署资源: {s_yaml_file}")
# 清除模型
subprocess.check_call(
f"echo 123456 | sudo -S s model remove -y -t {s_yaml_file}", shell=True
)
subprocess.check_call(f"s model remove -y -t {s_yaml_file}", shell=True)
# 清除函数
subprocess.check_call(
f"echo 123456 | sudo -S s remove -y -t {s_yaml_file} --skip-push",
shell=True,
)
subprocess.check_call(f"s remove -y -t {s_yaml_file} --skip-push", shell=True)
print("部署资源清除完成!")
except subprocess.CalledProcessError as e:
print(f"清除部署资源失败: {e}")
Expand All @@ -354,6 +369,7 @@ def main():
parser.add_argument(
"--auto-cleanup", action="store_true", help="部署和测试完成后自动执行清理操作"
)
parser.add_argument("--storage", help="存储区域", default="nas")

args = parser.parse_args()

Expand All @@ -364,7 +380,9 @@ def main():
return 0
elif args.model_id:
# 部署和测试模型
deploy_url, s_yaml_file = deploy_model(args.model_id, args.region)
deploy_url, s_yaml_file = deploy_model(
args.model_id, args.region, args.storage
)

# 测试模型
test_model(args.model_id, deploy_url, s_yaml_file)
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@alicloud/devs20230714": "^2.4.5",
"@alicloud/devs20230714": "^2.4.6-alpha.2",
"@alicloud/fc2": "^2.6.6",
"@alicloud/fc20230330": "4.6.0",
"@alicloud/pop-core": "^1.8.0",
Expand Down
Loading