Skip to content

Commit 142e540

Browse files
eikohszexi
andauthored
[Feature] llm model 使用 post_overlay 功能实现秒装挂载模型 (#23769)
* feat(llm): add probed-package * feat(llm): add llm-save-instant-app * feat(llm): add some llm-instant-app options * fix(llm): change app to model * fix(llm): rename origin model to sku * feat(llm): add llm-quick-models * fix(llm): saved paths for instant model * fix(llm): fix quick-install-model --------- Co-authored-by: Zexi Li <[email protected]>
1 parent bdf22fd commit 142e540

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3691
-342
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
)
99

1010
func init() {
11-
cmd := shell.NewResourceCmd(&modules.LLMModel)
12-
cmd.List(new(options.LLMModelListOptions))
13-
cmd.Show(new(options.LLMModelShowOptions))
14-
cmd.Update(new(options.LLMModelUpdateOptions))
15-
cmd.Create(new(options.LLMModelCreateOptions))
16-
cmd.Delete(new(options.LLMModelDeleteOptions))
11+
cmd := shell.NewResourceCmd(&modules.DifySku)
12+
cmd.List(new(options.DifySkuListOptions))
13+
cmd.Show(new(options.DifySkuShowOptions))
14+
cmd.Update(new(options.DifySkuUpdateOptions))
15+
cmd.Create(new(options.DifySkuCreateOptions))
16+
cmd.Delete(new(options.DifySkuDeleteOptions))
1717
cmd.Perform("public", &base_options.BasePublicOptions{})
1818
cmd.Perform("private", &base_options.BaseIdOptions{})
19-
// cmd.Perform("clone", new(options.DesktopModelCloneOptions))
19+
// cmd.Perform("clone", new(options.DesktopSkuCloneOptions))
2020
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package llm
2+
3+
import (
4+
"yunion.io/x/onecloud/cmd/climc/shell"
5+
6+
modules "yunion.io/x/onecloud/pkg/mcclient/modules/llm"
7+
commonoptions "yunion.io/x/onecloud/pkg/mcclient/options"
8+
options "yunion.io/x/onecloud/pkg/mcclient/options/llm"
9+
)
10+
11+
func init() {
12+
cmd := shell.NewResourceCmd(&modules.LLMInstantModel)
13+
cmd.List(new(options.LLMInstantModelListOptions))
14+
cmd.Show(new(options.LLMInstantModelShowOptions))
15+
// cmd.Update(new(options.InstantAppUpdateOptions))
16+
cmd.Create(new(options.LLMInstantModelCreateOptions))
17+
// cmd.Delete(new(options.InstantAppDeleteOptions))
18+
cmd.Perform("syncstatus", new(commonoptions.BaseIdOptions))
19+
cmd.Perform("change-owner", new(commonoptions.ChangeOwnerOptions))
20+
cmd.Perform("enable", new(commonoptions.BaseIdOptions))
21+
cmd.Perform("disable", new(commonoptions.BaseIdOptions))
22+
cmd.Perform("public", new(commonoptions.BasePublicOptions))
23+
cmd.Perform("private", new(commonoptions.BaseIdOptions))
24+
// cmd.PerformClass("import", new(options.InstantAppImportOptions))
25+
}

cmd/climc/shell/llm/llm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ func init() {
1313
cmd.Show(new(options.LLMShowOptions))
1414
cmd.Delete(new(options.LLMDeleteOptions))
1515
// cmd.Perform("change-model", new(options.LLMChangeModelOptions))
16+
cmd.Perform("syncstatus", new(options.LLMIdOptions))
1617
cmd.BatchPerform("stop", new(options.LLMStopOptions))
1718
cmd.BatchPerform("start", new(options.LLMStartOptions))
19+
cmd.Get("probed-models", new(options.LLMIdOptions))
20+
cmd.Perform("save-instant-model", new(options.LLMSaveInstantModelOptions))
21+
cmd.Perform("quick-models", new(options.LLMQuickModelsOptions))
1822
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
)
99

1010
func init() {
11-
cmd := shell.NewResourceCmd(&modules.DifyModel)
12-
cmd.List(new(options.DifyModelListOptions))
13-
cmd.Show(new(options.DifyModelShowOptions))
14-
cmd.Update(new(options.DifyModelUpdateOptions))
15-
cmd.Create(new(options.DifyModelCreateOptions))
16-
cmd.Delete(new(options.DifyModelDeleteOptions))
11+
cmd := shell.NewResourceCmd(&modules.LLMSku)
12+
cmd.List(new(options.LLMSkuListOptions))
13+
cmd.Show(new(options.LLMSkuShowOptions))
14+
cmd.Update(new(options.LLMSkuUpdateOptions))
15+
cmd.Create(new(options.LLMSkuCreateOptions))
16+
cmd.Delete(new(options.LLMSkuDeleteOptions))
1717
cmd.Perform("public", &base_options.BasePublicOptions{})
1818
cmd.Perform("private", &base_options.BaseIdOptions{})
19-
// cmd.Perform("clone", new(options.DesktopModelCloneOptions))
19+
// cmd.Perform("clone", new(options.DesktopSkuCloneOptions))
2020
}

pkg/apis/llm/dify.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ type DifyCustomized struct {
1414
type DifyListInput struct {
1515
LLMBaseListInput
1616

17-
DifyModel string `json:"dify_model"`
17+
DifySku string `json:"dify_sku"`
1818
}
1919

2020
type DifyCreateInput struct {
2121
LLMBaseCreateInput
2222

23-
DifyModelId string
23+
DifySkuId string
2424
}

pkg/apis/llm/instantmodel.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package llm
2+
3+
import (
4+
"yunion.io/x/onecloud/pkg/apis"
5+
)
6+
7+
type InstantModelListInput struct {
8+
apis.SharableVirtualResourceListInput
9+
apis.EnabledResourceBaseListInput
10+
11+
ModelName string `json:"model_name"`
12+
Tag string `json:"tag"`
13+
ModelId string `json:"model_id"`
14+
Image string `json:"image"`
15+
16+
Mounts string `json:"mounts"`
17+
18+
AutoCache *bool `json:"auto_cache"`
19+
}
20+
21+
type InstantModelCreateInput struct {
22+
apis.SharableVirtualResourceCreateInput
23+
apis.EnabledBaseResourceCreateInput
24+
25+
LLMType LLMContainerType `json:"llm_type"`
26+
ModelName string `json:"model_name"`
27+
Tag string `json:"tag"`
28+
ImageId string `json:"image_id"`
29+
Size int64 `json:"size"`
30+
ModelId string `json:"model_id"`
31+
32+
ActualSizeMb int32 `json:"actual_size_mb"`
33+
34+
Mounts []string `json:"mounts"`
35+
}
36+
37+
type InstantModelUpdateInput struct {
38+
apis.SharableVirtualResourceBaseUpdateInput
39+
40+
ImageId string `json:"image_id"`
41+
Size int64 `json:"size"`
42+
43+
ActualSizeMb int32 `json:"actual_size_mb"`
44+
45+
Mounts []string `json:"mounts"`
46+
}
47+
48+
type InstantModelDetails struct {
49+
apis.SharableVirtualResourceDetails
50+
51+
Image string
52+
53+
CacheCount int
54+
CachedCount int
55+
56+
IconBase64 string `json:"icon_base64"`
57+
}
58+
59+
type InstantModelImportInput struct {
60+
Endpoint string `json:"endpoint"`
61+
AccessKey string `json:"access_key"`
62+
SecretKey string `json:"secret_key"`
63+
Bucket string `json:"bucket"`
64+
Key string `json:"key"`
65+
SignVer string `json:"sign_ver"`
66+
}
67+
68+
func (input InstantModelImportInput) Invalid() bool {
69+
if len(input.Endpoint) == 0 || len(input.AccessKey) == 0 || len(input.SecretKey) == 0 || len(input.Bucket) == 0 || len(input.Key) == 0 {
70+
return true
71+
}
72+
return false
73+
}
74+
75+
type InstantModelSyncstatusInput struct {
76+
}
77+
78+
type InstantAppCacheInput struct {
79+
}
80+
81+
type InstantModelEnableAutoCacheInput struct {
82+
AutoCache bool `json:"auto_cache"`
83+
}
84+
85+
type MountedModelResourceListInput struct {
86+
MountedModels []string `json:"mounted_models"`
87+
}
88+
89+
type MountedModelResourceCreateInput struct {
90+
MountedModels []string `json:"mounted_models"`
91+
}
92+
93+
type MountedModelResourceUpdateInput struct {
94+
MountedModels []string `json:"mounted_models"`
95+
}

pkg/apis/llm/llm.go

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package llm
22

3-
import "yunion.io/x/onecloud/pkg/apis"
3+
import (
4+
"yunion.io/x/onecloud/pkg/apis"
5+
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
6+
)
47

58
const (
69
SERVICE_TYPE = "llm"
@@ -19,7 +22,7 @@ type LLMBaseCreateInput struct {
1922
type LLMCreateInput struct {
2023
LLMBaseCreateInput
2124

22-
LLMModelId string
25+
LLMSkuId string
2326
LLMImageId string
2427
}
2528

@@ -40,6 +43,73 @@ type LLMBaseListInput struct {
4043
type LLMListInput struct {
4144
LLMBaseListInput
4245

43-
LLMModel string `json:"llm_model"`
46+
LLMSku string `json:"llm_sku"`
4447
LLMImage string `json:"llm_image"`
4548
}
49+
50+
type ModelInfo struct {
51+
// 秒装模型ID
52+
Id string `json:"id"`
53+
// 秒装模型 ModelId
54+
ModelId string `json:"model_id"`
55+
// 秒装模型展示的名称,如: Qwen-7B
56+
DisplayName string `json:"display_name"`
57+
// 秒装模型 tag,如: 7b
58+
Tag string `json:"tag"`
59+
}
60+
61+
type LLMPerformQuickModelsInput struct {
62+
Models []ModelInfo
63+
Method TQuickModelMethod
64+
}
65+
66+
type LLMBatchPerformOutput struct {
67+
Data []LLMPerformOutput
68+
Task *taskman.STask
69+
}
70+
71+
type LLMPerformOutput struct {
72+
Id string
73+
Name string
74+
RequestStatus int
75+
Msg string
76+
TaskId string
77+
}
78+
79+
type LLMSyncModelTaskInput struct {
80+
LLMPerformQuickModelsInput
81+
82+
LLMStatus string `json:"llm_status"`
83+
InstallModelIds []string `json:"install_model_ids"`
84+
InstallDirs []string `json:"install_dirs"`
85+
UninstallModelIds []string `json:"uninstall_model_ids"`
86+
}
87+
88+
type LLMMountDirInfo struct {
89+
ImageId string
90+
Host string
91+
Container string
92+
}
93+
94+
func (info LLMMountDirInfo) ToOverlay() apis.ContainerVolumeMountDiskPostOverlay {
95+
// uid := int64(1000)
96+
// gid := int64(1000)
97+
if len(info.ImageId) > 0 {
98+
return apis.ContainerVolumeMountDiskPostOverlay{
99+
Image: &apis.ContainerVolumeMountDiskPostImageOverlay{
100+
Id: info.ImageId,
101+
},
102+
// FsUser: &uid,
103+
// FsGroup: &gid,
104+
}
105+
}
106+
return apis.ContainerVolumeMountDiskPostOverlay{
107+
ContainerTargetDir: info.Container,
108+
HostLowerDir: []string{info.Host},
109+
// FsUser: &uid,
110+
// FsGroup: &gid,
111+
}
112+
}
113+
114+
type LLMSyncStatusInput struct {
115+
}

pkg/apis/llm/llm_const.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,26 @@ const (
1616
/* 停机失败 */
1717
LLM_STATUS_STOP_FAILED = "stop_fail"
1818

19+
/* 开始保存应用 */
20+
LLM_STATUS_START_SAVE_MODEL = "start_save_model"
21+
/* 正在保存应用 */
22+
LLM_STATUS_SAVING_MODEL = "saving_model"
23+
/* 保存应用失败 */
24+
LLM_STATUS_SAVE_MODEL_FAILED = "save_model_failed"
25+
26+
/* 开始同步状态 */
27+
LLM_STATUS_START_SYNCSTATUS = "start_syncstatus"
28+
/* 正在同步状态 */
29+
LLM_STATUS_SYNCSTATUS = "syncstatus"
30+
1931
/* 停机 */
2032
LLM_STATUS_READY = "ready"
2133
/* 运行 */
2234
LLM_STATUS_RUNNING = "running"
2335

36+
/* 删除 */
37+
LLM_STATUS_DELETED = "deleted"
38+
2439
LLM_STATUS_CREATING_POD = "creating_pod"
2540
LLM_STATUS_CREAT_POD_FAILED = "creat_pod_failed"
2641
LLM_STATUS_PULLING_MODEL = "pulling_model"
@@ -37,3 +52,15 @@ const (
3752
LLM_STATUS_DELETING = "deleting"
3853
LLM_STATUS_DELETE_FAILED = "delete_fail"
3954
)
55+
56+
type TQuickModelMethod string
57+
58+
const (
59+
QuickModelInstall = TQuickModelMethod("install")
60+
QuickModelUninstall = TQuickModelMethod("uninstall")
61+
QuickModelReinstall = TQuickModelMethod("reinstall")
62+
)
63+
64+
const (
65+
LLM_PROBE_INSTANT_MODEl_INTERVAL_SECOND = 120 // 2 minute
66+
)

pkg/apis/llm/llm_instant_model.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package llm
2+
3+
import "yunion.io/x/onecloud/pkg/apis"
4+
5+
type LLMInternalInstantMdlInfo struct {
6+
ModelId string `json:"model_id"`
7+
Name string `json:"name"`
8+
Tag string `json:"tag"`
9+
Size int64 `json:"size"`
10+
// Modified string `json:"modified"`
11+
Blobs []string `json:"blobs"`
12+
}
13+
14+
type LLMSaveInstantModelInput struct {
15+
apis.ProjectizedResourceCreateInput
16+
17+
ModelId string `json:"model_id"`
18+
ImageName string `json:"image_name"`
19+
20+
InstantModelId string `json:"instant_model_id"`
21+
22+
// AutoRestart bool `json:"auto_restart"`
23+
}

pkg/apis/llm/ollama_const.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
)
1212

1313
const (
14+
LLM_OLLAMA_SAVE_DIR = "/opt/.ollama-models/%s"
1415
LLM_OLLAMA_HOST_PATH = "/opt/ollama-models"
1516
LLM_OLLAMA_HOST_MANIFESTS_DIR = "/manifests"
1617
LLM_OLLAMA_CACHE_DIR = "/.llm_ollama_cache"

0 commit comments

Comments
 (0)