Skip to content

Commit e7fcb58

Browse files
committed
fix: add s model download
1 parent 845f988 commit e7fcb58

9 files changed

Lines changed: 463 additions & 6 deletions

File tree

example/s.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
edition: 3.0.0
2+
name: ai-model-app
3+
access: quanxi
4+
5+
resources:
6+
modelDemo:
7+
component: ${path("../")}
8+
props:
9+
region: cn-hangzhou
10+
runtime: custom-container
11+
functionName: ai-model-test-qwen
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+
role: acs:ram::1431999136518149:role/aliyunfcdefaultrole
20+
diskSize: 10240
21+
timeout: 300
22+
gpuConfig:
23+
gpuMemorySize: 49152
24+
gpuType: fc.gpu.ada.1
25+
instanceLifecycleConfig:
26+
initializer:
27+
handler: index.initializer
28+
timeout: 600
29+
preStop:
30+
handler: index.preStop
31+
timeout: 300
32+
customContainerConfig:
33+
image: >-
34+
serverless-registry.cn-hangzhou.cr.aliyuncs.com/functionai/dms-vllm:openai_v0.10.0
35+
port: 9000
36+
entrypoint:
37+
- vllm
38+
- serve
39+
- /mnt/ai-model-test-qwen
40+
- --port
41+
- "9000"
42+
- --served-model-name
43+
- Qwen/Qwen3-0.6B
44+
- --tensor-parallel-size
45+
- "1"
46+
- --trust-remote-code # 添加这个参数
47+
triggers: # 默认,用户可能关注的是开启 authType 是 bear token
48+
- triggerName: httpTrigger
49+
triggerType: http
50+
triggerConfig:
51+
methods:
52+
- GET
53+
- POST
54+
- PUT
55+
- DELETE
56+
provisionConfig:
57+
target: 1
58+
alwaysAllocateCPU: false
59+
alwaysAllocateGPU: false
60+
mode: sync
61+
62+
supplement:
63+
modelConfig:
64+
source: modelscope
65+
id: 'Qwen/Qwen3-0.6B'
66+
storage: nas

package-lock.json

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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"author": "",
2323
"license": "ISC",
2424
"dependencies": {
25+
"@alicloud/devs20230714": "^2.4.5",
2526
"@alicloud/fc2": "^2.6.6",
2627
"@alicloud/fc20230330": "4.3.4",
2728
"@alicloud/pop-core": "^1.8.0",
@@ -34,6 +35,7 @@
3435
"@serverless-devs/utils": "^0.0.17",
3536
"@serverless-devs/zip": "^0.0.3-beta.8",
3637
"ajv": "^8.17.1",
38+
"ali-oss": "6.18.1",
3739
"aliyun-sdk": "^1.12.10",
3840
"chalk": "^4.1.0",
3941
"crc64-ecma182.js": "^2.0.2",
@@ -51,8 +53,7 @@
5153
"temp-dir": "^2.0.0",
5254
"tty-table": "^4.2.3",
5355
"uuid": "^9.0.1",
54-
"uuid-by-string": "^4.0.0",
55-
"ali-oss": "6.18.1"
56+
"uuid-by-string": "^4.0.0"
5657
},
5758
"devDependencies": {
5859
"@serverless-devs/component-interface": "^0.0.6",

src/commands-help/model.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export default {
2+
help: {
3+
description: 'Resource layer operation ',
4+
summary: 'Resource layer operation ',
5+
},
6+
subCommands: {
7+
download: {
8+
help: {
9+
description: `Download model`,
10+
summary: 'Publish new layer version',
11+
option: [],
12+
},
13+
},
14+
reomve: {
15+
help: {
16+
description: `Remove model`,
17+
summary: 'Remove model',
18+
option: [],
19+
},
20+
},
21+
},
22+
};

src/default/resources.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ export const VPC_AND_NAS_NAME = process.env.FC_GENERATE_VPC_AND_NAS_NAME || defa
44
const defaultLogStoreName = 'default-logs';
55
export const PROJECT = process.env.FC_GENERATE_PROJECT_NAME;
66
export const LOG_STORE = process.env.FC_GENERATE_LOGSTORE_NAME || defaultLogStoreName;
7+
8+
export function getEnvVariable(key: string): string {
9+
if (typeof process !== 'undefined' && process.env) {
10+
return process.env[key] || '';
11+
}
12+
return '';
13+
}

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import SYaml2To3 from './subCommands/2to3';
2525
import Logs from './subCommands/logs';
2626
import { SCHEMA_FILE_PATH } from './constant';
2727
import { checkDockerIsOK, isAppCenter, isYunXiao } from './utils';
28+
import { Model } from './subCommands/model';
2829

2930
export default class Fc extends Base {
3031
// 部署函数
@@ -168,6 +169,13 @@ export default class Fc extends Base {
168169
return await logs.run();
169170
}
170171

172+
public async model(inputs: IInputs) {
173+
await super.handlePreRun(inputs, false);
174+
const model = new Model(inputs);
175+
logger.debug(`model inputs: ${model.subCommand}`);
176+
return await model[model.subCommand]();
177+
}
178+
171179
public async getSchema(inputs: IInputs) {
172180
logger.debug(`getSchema: ${JSON.stringify(inputs)}`);
173181
return fs.readFileSync(SCHEMA_FILE_PATH, 'utf-8');

src/interface/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface IProps extends IFunction {
1919
concurrencyConfig?: IConcurrencyConfig;
2020
provisionConfig?: IProvisionConfig;
2121
endpoint?: string;
22+
supplement: any;
2223
}
2324

2425
export interface IInputs extends _IInputs {

src/subCommands/deploy/impl/function.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _ from 'lodash';
1+
import _, { isEmpty } from 'lodash';
22
import { diffConvertYaml } from '@serverless-devs/diff';
33
import inquirer from 'inquirer';
44
import fs from 'fs';
@@ -319,7 +319,7 @@ export default class Service extends Base {
319319
* 生成 auto 资源,非 FC 资源,主要指 vpc、nas、log、role(oss mount 挂载点才有)
320320
*/
321321
private async _deployAuto() {
322-
const { region } = this.inputs.props;
322+
const { region, supplement } = this.inputs.props;
323323
const { credential } = this.inputs;
324324
const { functionName } = this.local;
325325

@@ -390,13 +390,15 @@ vpcConfig:
390390
_.set(this.local, 'vpcConfig', vpcConfig);
391391
}
392392
if (nasAuto) {
393+
const { modelConfig } = supplement;
394+
393395
logger.write(
394396
yellow(`Created nas resource succeeded, please replace nasConfig: auto in yaml with:
395397
nasConfig:
396398
groupId: 0
397399
userId: 0
398400
mountPoints:
399-
- serverAddr: ${mountTargetDomain}:/${functionName}
401+
- serverAddr: ${mountTargetDomain}:/${functionName}${isEmpty(modelConfig) ? '' : '/'+ modelConfig.id}
400402
mountDir: /mnt/${functionName}
401403
enableTLS: false\n`),
402404
);
@@ -406,7 +408,7 @@ nasConfig:
406408
userId: 0,
407409
mountPoints: [
408410
{
409-
serverAddr: `${mountTargetDomain}:/${functionName}`,
411+
serverAddr: `${mountTargetDomain}:/${functionName}${isEmpty(modelConfig) ? '' : '/'+ modelConfig.id}`,
410412
mountDir: `/mnt/${functionName}`,
411413
enableTLS: false,
412414
},

0 commit comments

Comments
 (0)