Skip to content

Commit 812e43d

Browse files
committed
add ollama: not complete
1 parent 3ff3c65 commit 812e43d

5 files changed

Lines changed: 103 additions & 13 deletions

File tree

publish.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Parameters:
3333
additionalProperties: false
3434
required: # 必填项
3535
- region
36+
- imageTag
3637
- serviceName
3738
- roleArn
3839
- modelId
@@ -41,6 +42,10 @@ Parameters:
4142
- gpuMemorySize
4243
- memorySize
4344
- modelCache
45+
- ggufFile
46+
- modelfile
47+
- modelFamily
48+
- servedModelName
4449
properties:
4550
region:
4651
title: 地域
@@ -51,6 +56,11 @@ Parameters:
5156
# - cn-beijing
5257
- cn-hangzhou
5358
- cn-shanghai
59+
imageTag:
60+
title: modelscope镜像tag
61+
type: string
62+
default: fc-deploy-common-v17.3.3
63+
description: registry.${vars.region}.aliyuncs.com/modelscope-repo/modelscope镜像的tag版本。24年7月以后,与modelscope镜像统一
5464
serviceName:
5565
title: 服务名
5666
type: string
@@ -121,3 +131,23 @@ Parameters:
121131
- "www.modelscope.cn"
122132
- "modelsce-mirror-modelsce-mirror-txpzbgwcck.cn-hangzhou-vpc.fcapp.run"
123133
- "modelsce-mirror-modelsce-mirror-txpzbgwcck.cn-shanghai-vpc.fcapp.run"
134+
ggufFile:
135+
title: gguf文件
136+
type: string
137+
default: ""
138+
description: gguf格式的模型文件,使用ollama启动时为必须参数
139+
modelfile:
140+
title: ollama模型template文件内容
141+
type: string
142+
default: ""
143+
description: ollama创建模型时所需的模型template文件的内容, 不配置时将以modelFamily取该类模型的默认配置
144+
modelFamily:
145+
title: 模型family
146+
type: string
147+
default: ""
148+
description: 模型的类型,如qwen2, 用以获取ollama创建模型时所需的模型默认template文件
149+
servedModelName:
150+
title: 模型服务名
151+
type: string
152+
pattern: "^[a-zA-Z_][a-zA-Z0-9-_]{0,127}$"
153+
description: 用户可配置的部署后模型名称,只能包含字母、数字、下划线和中划线。不能以数字、中划线开头。长度在 1-128 之间

src/model_deploy/index.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
from modelscope.hub.api import HubApi
3+
from modelscope.hub.snapshot_download import snapshot_download
4+
5+
def handler(event, context):
6+
model_id = os.getenv('MODEL_ID', '')
7+
revision = os.getenv('MODEL_VERSION', '')
8+
cache_dir = os.getenv('MODELSCOPE_CACHE', '')
9+
sdk_token = os.getenv('MODELSCOPE_TOKEN', '')
10+
image_tag = os.getenv('IMAGE_TAG', '')
11+
gguf_file = os.getenv('GGUF_FILE', '')
12+
modelfile = os.getenv('MODELFILE', '')
13+
family = os.getenv('MODEL_FAMILY', '')
14+
served_model_name = os.getenv('SERVED_MODEL_NAME', '')
15+
16+
return {'served_model_name': served_model_name}

src/model_download/index.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,36 @@ def handler(event, context):
77
revision = os.getenv('MODEL_VERSION', '')
88
cache_dir = os.getenv('MODELSCOPE_CACHE', '')
99
sdk_token = os.getenv('MODELSCOPE_TOKEN', '')
10+
image_tag = os.getenv('IMAGE_TAG', '')
11+
gguf_file = os.getenv('GGUF_FILE', '')
12+
modelfile = os.getenv('MODELFILE', '')
13+
family = os.getenv('MODEL_FAMILY', '')
14+
1015
# login first.
1116
HubApi().login(sdk_token)
12-
if len(revision) > 0:
13-
snapshot_download (model_id =model_id,
14-
revision =revision,
15-
cache_dir = cache_dir)
16-
else:
17-
snapshot_download (model_id =model_id,
17+
if image_tag == 'fc-deploy-common-v17.3.3':
18+
if len(revision) > 0:
19+
snapshot_download (model_id =model_id,
20+
revision =revision,
1821
cache_dir = cache_dir)
19-
print("download model scuccess!")
22+
else:
23+
snapshot_download (model_id =model_id,
24+
cache_dir = cache_dir)
25+
print("download model scuccess!")
26+
else:
27+
command_download_ollama = f'modelscope download --model=modelscope/ollama-linux --local_dir {cache_dir}/ollama-linux'
28+
os.system(command_download_ollama)
29+
30+
command_download_model = f'modelscope download --model={model_id} --local_dir {cache_dir} ${gguf_file}'
31+
os.system(command_download_model)
32+
33+
if modelfile and len(modelfile):
34+
os.system(f'cat {modelfile} > {cache_dir}/ModelFile')
35+
elif family and len(family):
36+
os.system(f'wget https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/{family}.modelfile')
37+
command_gen_modelfile = f'cat {family}.modelfile | sed "s/' + '{gguf_file}' + f'/{gguf_file}/" > {cache_dir}/ModelFile'
38+
os.system(command_gen_modelfile)
39+
else:
40+
raise ValueError(f'modelfile 和 model_family至少需要配置一个。用于ollama模型初始化。')
41+
42+
print("download model scuccess!")

src/model_meta_info/index.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
from modelscope.hub.api import HubApi
3+
from modelscope.hub.snapshot_download import snapshot_download
4+
5+
def handler(event, context):
6+
served_model_name = os.getenv('SERVED_MODEL_NAME', '')
7+
8+
return {'served_model_name': served_model_name}

src/s.yaml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ access: {{ access }}
77

88
vars: # 全局变量
99
region: {{ region }}
10-
version: 2024-06-27-8531bd
10+
version: {{ imageTag }}
1111
service:
1212
name: {{ serviceName }}
1313
description: "modelscope deployment"
@@ -43,6 +43,10 @@ services:
4343
MODELSCOPE_CACHE: /mnt/auto
4444
MODELSCOPE_TOKEN: {{ accessToken }}
4545
MODELSCOPE_DOMAIN: {{ modelCache }}
46+
IMAGE_TAG: {{ imageTag }}
47+
GGUF_FILE: {{ ggufFile }}
48+
MODELFLE: {{ modelfile }}
49+
MODEL_FAMILY: {{ modelFamily }}
4650

4751
model_meta_func:
4852
component: 'fc'
@@ -52,7 +56,8 @@ services:
5256
function:
5357
name: model_meta_func
5458
description: Meta Api
55-
handler: not-used
59+
codeUri: ./model_meta_info
60+
handler: {{ if imageTag == 'fc-deploy-common-v17.3.3' }}not-used{{ else }}index.handler
5661
timeout: 1800
5762
caPort: 9000
5863
instanceType: g1
@@ -63,8 +68,9 @@ services:
6368
instanceConcurrency: 1
6469
runtime: custom-container
6570
customContainerConfig:
66-
image: registry.${vars.region}.aliyuncs.com/modelscope-repo/swingdeploy:${vars.version}
67-
71+
image: registry.${vars.region}.aliyuncs.com/modelscope-repo/modelscope:${vars.version}
72+
environmentVariables:
73+
SERVED_MODEL_NAME: {{ servedModelName }}
6874
triggers:
6975
- name: httpTrigger
7076
type: http
@@ -81,9 +87,10 @@ services:
8187
function:
8288
name: model_app_func
8389
description: Deploy ModelScope applications of model {{ modelId }}
84-
handler: not-used
90+
codeUri: ./model_deploy
91+
handler: {{ if imageTag == 'fc-deploy-common-v17.3.3' }}not-used{{ else }}index.handler
8592
timeout: 1800
86-
caPort: 9000
93+
caPort: {{ if imageTag == 'fc-deploy-common-v17.3.3' }}9000{{ else }}11434
8794
instanceType: {{ gpuInstanceType }}
8895
gpuMemorySize: {{ gpuMemorySize }}
8996
memorySize: {{ memorySize }}
@@ -101,6 +108,12 @@ services:
101108
MODELSCOPE_CACHE: /mnt/auto
102109
MODELSCOPE_TOKEN: {{ accessToken }}
103110
TASK: {{ task }}
111+
IMAGE_TAG: {{ imageTag }}
112+
GGUF_FILE: {{ ggufFile }}
113+
MODELFLE: {{ modelfile }}
114+
MODEL_FAMILY: {{ modelFamily }}
115+
MODELSCOPE_DOMAIN: {{ modelCache }}
116+
SERVED_MODEL_NAME: {{ servedModelName }}
104117

105118
triggers:
106119
- name: httpTrigger

0 commit comments

Comments
 (0)