Skip to content

Commit 671cf89

Browse files
authored
Merge pull request #73 from devsapp/add-model-download
fix: nasAuto mountDir
2 parents 48884e0 + c23c3f2 commit 671cf89

File tree

6 files changed

+187
-6
lines changed

6 files changed

+187
-6
lines changed

example/s-pipeline.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
edition: 3.0.0
2+
name: ai-model-app
3+
access: quanxi
4+
5+
resources:
6+
modelDemo:
7+
component: fc3
8+
props:
9+
region: cn-shanghai
10+
runtime: custom-container
11+
functionName: ${env('fc_component_function_name', 'ai-model-test-qwen-pipeline')}
12+
description: model service from functionai test
13+
logConfig: auto
14+
vpcConfig: auto
15+
nasConfig: auto
16+
instanceConcurrency: 20
17+
cpu: 8
18+
memorySize: 65536
19+
diskSize: 10240
20+
timeout: 300
21+
gpuConfig:
22+
gpuMemorySize: 49152
23+
gpuType: fc.gpu.ada.1
24+
customContainerConfig:
25+
image: >-
26+
serverless-registry.cn-hangzhou.cr.aliyuncs.com/functionai/modelscope:ubuntu22.04-cuda12.1.0-py311-torch2.3.1-tf2.16.1-1.26.0
27+
port: 9000
28+
entrypoint:
29+
- sh
30+
- '-c'
31+
- >-
32+
mkdir -p /.function_model && curl -fL --retry 3 -o
33+
/.function_model/server.py
34+
https://images.devsapp.cn/modelscope/server.py && MODEL_ID="${env('MODEL_ID', 'iic/SenseVoiceSmall')}" MODEL_VERSION="${env('MODEL_VERSION', 'master')}" MODEL_PATH="/mnt/${env('fc_component_function_name', 'ai-model-test-qwen-pipeline')} /${env('MODEL_ID', 'iic/SenseVoiceSmall')}" TASK="${env('TASK')}" python3 -u /.function_model/server.py
35+
triggers: # 默认,用户可能关注的是开启 authType 是 bear token
36+
- triggerConfig:
37+
methods:
38+
- GET
39+
- POST
40+
- PUT
41+
- DELETE
42+
authType: anonymous
43+
disableURLInternet: false
44+
triggerName: httpTrigger
45+
description: ''
46+
qualifier: LATEST
47+
triggerType: http
48+
provisionConfig:
49+
target: 1
50+
alwaysAllocateCPU: false
51+
alwaysAllocateGPU: false
52+
mode: sync
53+
54+
supplement:
55+
modelConfig:
56+
source: modelscope
57+
id: ${env('MODEL_ID', 'iic/SenseVoiceSmall')}
58+
# id: Qwen/Qwen3-14B
59+
storage: nas
60+
role: acs:ram::${config('AccountID')}:role/aliyundevsdefaultrole
61+

example/s.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ access: quanxi
44

55
resources:
66
modelDemo:
7-
component: fc3@dev
7+
component: fc3
88
props:
99
region: cn-shanghai
1010
runtime: custom-container

example/test_models_pipeline.sh

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/bin/bash
2+
3+
# 定义日志文件
4+
LOG_FILE="test_models.log"
5+
6+
# 清空或创建日志文件
7+
> "$LOG_FILE"
8+
9+
# 日志记录函数
10+
log() {
11+
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
12+
}
13+
14+
# 定义模型列表 (每个元素包含model_version, model_id, task)
15+
MODEL_LIST=(
16+
'{"model_version": "v2.4.0", "model_id": "iic/cv_convnextTiny_ocr-recognition-general_damo", "task": "ocr-recognition", "input":{"image":"http://modelscope.oss-cn-beijing.aliyuncs.com/demo/images/image_ocr_recognition.jpg"}'
17+
'{"model_version": "master", "model_id": "iic/SenseVoiceSmall", "task": "auto-speech-recognition", "input": "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav"}'
18+
)
19+
20+
# 检查yaml文件是否存在
21+
YAML_FILE="s.yaml"
22+
if [ ! -f "$YAML_FILE" ]; then
23+
log "Error: $YAML_FILE not found!"
24+
exit 1
25+
fi
26+
27+
# 遍历每个model_id
28+
for MODEL_INFO in "${MODEL_LIST[@]}"; do
29+
log "========================================"
30+
log "Testing model: $MODEL_INFO"
31+
log "========================================"
32+
# 从JSON对象中提取字段 (使用 jq)
33+
export MODEL_VERSION=$(echo "$MODEL_INFO" | grep -o '"model_version": *"[^"]*' | awk -F'"' '{print $4}')
34+
export MODEL_ID=$(echo "$MODEL_INFO" | grep -o '"model_id": *"[^"]*' | awk -F'"' '{print $4}')
35+
export TASK=$(echo "$MODEL_INFO" | grep -o '"task": *"[^"]*' | awk -F'"' '{print $4}')
36+
INPUT=$(echo "$MODEL_INFO" | grep -o '"input": *"[^"]*' | awk -F'"' '{print $4}')
37+
38+
# 生成随机函数名
39+
RANDOM_STRING=$(openssl rand -hex 10)
40+
export fc_component_function_name=ai-model-qwen-$RANDOM_STRING
41+
export NEW_MODEL_SERVICE_CLIENT_CONNECT_TIMEOUT=10000
42+
43+
# 下载模型
44+
log "Downloading model..."
45+
DOWNLOAD_OUTPUT=$(s model download -t s-pipeline.yaml 2>&1)
46+
echo "$DOWNLOAD_OUTPUT" >> "$LOG_FILE"
47+
echo "$DOWNLOAD_OUTPUT"
48+
if echo "$DOWNLOAD_OUTPUT" | grep -q "Error"; then
49+
log "Failed to download model: $MODEL_ID"
50+
continue
51+
fi
52+
53+
# 部署服务
54+
log "Deploying..."
55+
DEPLOY_OUTPUT=$(s deploy -t s-pipeline.yaml -y 2>&1)
56+
echo "$DEPLOY_OUTPUT" >> "$LOG_FILE"
57+
echo "$DEPLOY_OUTPUT"
58+
59+
# 检查部署是否成功
60+
if echo "$DEPLOY_OUTPUT" | grep -q "state:.*Active"; then
61+
log "Deployment successful for model: $MODEL_ID"
62+
else
63+
log "Deployment failed for model: $MODEL_ID"
64+
# 清理资源
65+
REMOVE_OUTPUT=$(s model remove -t s-pipeline.yaml -y 2>&1)
66+
echo "$REMOVE_OUTPUT" >> "$LOG_FILE"
67+
echo "$REMOVE_OUTPUT"
68+
REMOVE_OUTPUT=$(s remove -t s-pipeline.yaml -y 2>&1)
69+
echo "$REMOVE_OUTPUT" >> "$LOG_FILE"
70+
echo "$REMOVE_OUTPUT"
71+
continue
72+
fi
73+
74+
# 提取system_url
75+
SYSTEM_URL=$(echo "$DEPLOY_OUTPUT" | grep "system_url:" | sed 's/.*system_url: *//' | tr -d ' "[:cntrl:]')
76+
if [ -z $SYSTEM_URL ]; then
77+
log "Failed to extract system_url for model: $MODEL_ID"
78+
# 清理资源
79+
REMOVE_OUTPUT=$(s model remove -y 2>&1)
80+
echo "$REMOVE_OUTPUT" >> "$LOG_FILE"
81+
echo "$REMOVE_OUTPUT"
82+
REMOVE_OUTPUT=$(s remove -y 2>&1)
83+
echo "$REMOVE_OUTPUT" >> "$LOG_FILE"
84+
echo "$REMOVE_OUTPUT"
85+
continue
86+
fi
87+
log "Extracted system_url: $SYSTEM_URL"
88+
89+
# 发送测试请求
90+
log "Sending test request..."
91+
CURL_OUTPUT=$(curl -v -d '{"input":$INPUT}' $SYSTEM_URL 2>&1)
92+
93+
echo "$CURL_OUTPUT" >> "$LOG_FILE"
94+
echo "$CURL_OUTPUT"
95+
96+
# 检查curl请求是否成功
97+
if echo "$CURL_OUTPUT" | grep -q '"object":"chat.completion"'; then
98+
log "Model test successful for: $MODEL_ID"
99+
# 提取并显示模型回复内容
100+
RESPONSE_CONTENT=$(echo "$CURL_OUTPUT" | sed -n 's/.*"text":"\([^"]*\)".*/\1/p' | sed 's/\\n/\n/g' | sed 's/\\t/\t/g')
101+
log "Model response: $RESPONSE_CONTENT"
102+
else
103+
log "Model test failed for: $MODEL_ID"
104+
fi
105+
106+
# 清理资源
107+
log "Removing resources..."
108+
REMOVE_OUTPUT=$(s model remove -y 2>&1)
109+
echo "$REMOVE_OUTPUT" >> "$LOG_FILE"
110+
echo "$REMOVE_OUTPUT"
111+
REMOVE_OUTPUT=$(s remove -y 2>&1)
112+
echo "$REMOVE_OUTPUT" >> "$LOG_FILE"
113+
echo "$REMOVE_OUTPUT"
114+
115+
log ""
116+
log "Finished testing model: $MODEL_ID"
117+
log ""
118+
done
119+
120+
log "All models tested."

src/subCommands/deploy/impl/function.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ nasConfig:
402402
userId: 0
403403
mountPoints:
404404
- serverAddr: ${mountTargetDomain}:/${functionName}${isEmpty(modelConfig) ? '' : '/' + modelConfig.id}
405-
mountDir: /mnt/${functionName}${isEmpty(modelConfig) ? '' : '/' + modelConfig.id}
405+
mountDir: /mnt/${functionName}
406406
enableTLS: false\n`),
407407
);
408408
this.createResource.nas = { mountTargetDomain, fileSystemId };
@@ -412,7 +412,7 @@ nasConfig:
412412
mountPoints: [
413413
{
414414
serverAddr: `${mountTargetDomain}:/${functionName}${isEmpty(modelConfig) ? '' : '/' + modelConfig.id}`,
415-
mountDir: `/mnt/${functionName}${isEmpty(modelConfig) ? '' : '/' + modelConfig.id}`,
415+
mountDir: `/mnt/${functionName}`,
416416
enableTLS: false,
417417
},
418418
],

src/subCommands/model/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import assert from 'assert';
1414
import { sleep } from '../../utils';
1515

1616
export const NEW_MODEL_SERVICE_CLIENT_CONNECT_TIMEOUT: number =
17-
parseInt(process.env.NEW_MODEL_SERVICE_CLIENT_CONNECT_TIMEOUT as string, 10) || 5 * 1000;
17+
parseInt(process.env.NEW_MODEL_SERVICE_CLIENT_CONNECT_TIMEOUT as string, 10) || 10 * 1000;
1818
export const NEW_MODEL_SERVICE_CLIENT_READ_TIMEOUT: number =
1919
parseInt(process.env.NEW_MODEL_SERVICE_CLIENT_READ_TIMEOUT as string, 10) || 86400 * 1000;
2020
export const MODEL_DOWNLOAD_TIMEOUT: number =
@@ -111,7 +111,7 @@ groupId: 0
111111
userId: 0
112112
mountPoints:
113113
- serverAddr: ${mountTargetDomain}:/${functionName}/${supplement.modelConfig.id}
114-
mountDir: /mnt/${functionName}/${supplement.modelConfig.id}
114+
mountDir: /mnt/${functionName}
115115
enableTLS: false\n`),
116116
);
117117
this.createResource.nas = { mountTargetDomain, fileSystemId };
@@ -121,7 +121,7 @@ mountPoints:
121121
mountPoints: [
122122
{
123123
serverAddr: `${mountTargetDomain}:/${functionName}/${supplement.modelConfig.id}`,
124-
mountDir: `/mnt/${functionName}/${supplement.modelConfig.id}`,
124+
mountDir: `/mnt/${functionName}`,
125125
enableTLS: false,
126126
},
127127
],

0 commit comments

Comments
 (0)