-
Notifications
You must be signed in to change notification settings - Fork 637
Expand file tree
/
Copy pathsku.go
More file actions
321 lines (264 loc) · 10.3 KB
/
Copy pathsku.go
File metadata and controls
321 lines (264 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
package llm
import (
"reflect"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/gotypes"
"yunion.io/x/pkg/util/sets"
"yunion.io/x/onecloud/pkg/apis"
computeapi "yunion.io/x/onecloud/pkg/apis/compute"
)
var (
LLM_SKU_BASE_NETWORK_TYPES = sets.NewString(
string(computeapi.NETWORK_TYPE_HOSTLOCAL),
string(computeapi.NETWORK_TYPE_GUEST),
)
)
func IsLLMSkuBaseNetworkType(t string) bool {
return LLM_SKU_BASE_NETWORK_TYPES.Has(t)
}
type HostInfo struct {
HostId string
Host string
HostAccessIp string
HostEIP string
}
func init() {
gotypes.RegisterSerializable(reflect.TypeOf(&PortMappings{}), func() gotypes.ISerializable {
return &PortMappings{}
})
gotypes.RegisterSerializable(reflect.TypeOf(&Devices{}), func() gotypes.ISerializable {
return &Devices{}
})
gotypes.RegisterSerializable(reflect.TypeOf(&PortMappingEnvs{}), func() gotypes.ISerializable {
return &PortMappingEnvs{}
})
gotypes.RegisterSerializable(reflect.TypeOf(&Envs{}), func() gotypes.ISerializable {
return &Envs{}
})
}
type PortMappingEnv struct {
Key string `json:"key"`
ValueFrom string `json:"value_from"`
}
type PortMappingEnvs []PortMappingEnv
func (pm PortMappingEnvs) String() string {
return jsonutils.Marshal(pm).String()
}
func (pm PortMappingEnvs) IsZero() bool {
return len(pm) == 0
}
type PortMapping struct {
Protocol string `json:"protocol"`
ContainerPort int `json:"container_port"`
RemoteIps []string `json:"remote_ips"`
FirstPortOffset *int `json:"first_port_offset"`
Envs []computeapi.GuestPortMappingEnv `json:"envs"`
}
type PortMappings []PortMapping
func (s PortMappings) String() string {
return jsonutils.Marshal(s).String()
}
func (s PortMappings) IsZero() bool {
return len(s) == 0
}
type Device struct {
DevType string `json:"dev_type"`
Model string `json:"model"`
DevicePath string `json:"device_path"`
}
type Devices []Device
func (s Devices) String() string {
return jsonutils.Marshal(s).String()
}
func (s Devices) IsZero() bool {
return len(s) == 0
}
type Env struct {
Key string `json:"key"`
Value string `json:"value"`
}
type Envs []Env
func (s Envs) String() string {
return jsonutils.Marshal(s).String()
}
func (s Envs) IsZero() bool {
return len(s) == 0
}
type LLMSkuDetails struct {
apis.SharableVirtualResourceDetails
// 当前大模型套餐包含的实例个数。
LLMCapacity int
Image string
ImageLabel string
ImageName string
MountedModelDetails []MountedModelInfo `json:"mounted_model_details"`
Template string `json:"template"`
// LLMType 为 SKU 类型(ollama/vllm/dify),与 llm_spec 一起带出
LLMType string `json:"llm_type"`
// LLMSpec 从 SKU 持久化字段带出,保证 list/show 与 create 一致
LLMSpec *LLMSpec `json:"llm_spec,omitempty"`
// Model source
LLMModelSpecId string `json:"llm_model_spec_id"`
Source string `json:"source"`
HuggingfaceRepoId string `json:"huggingface_repo_id"`
HuggingfaceFilename string `json:"huggingface_filename"`
ModelScopeModelId string `json:"model_scope_model_id"`
ModelScopeFilePath string `json:"model_scope_file_path"`
LocalPath string `json:"local_path"`
// Model categories
Categories string `json:"categories"`
// Inference backend version and parameters
BackendVersion string `json:"backend_version"`
BackendParameters string `json:"backend_parameters"`
}
type MountedAppResourceDetails struct {
MountedModels []string `json:"mounted_models"`
}
type LLMSKuBaseCreateInput struct {
apis.SharableVirtualResourceCreateInput
Cpu int `json:"cpu"`
Memory int `json:"memory"`
Bandwidth int `json:"bandwidth"`
// VramClaimMb is the estimated VRAM (MiB) the inference instance will
// require. Optional — if 0, the deployment create task will auto-fill it
// from the mounted InstantModel's weight_size_bytes.
VramClaimMb int `json:"vram_claim_mb,omitempty"`
Volumes *Volumes `json:"volumes"`
HostPaths *HostPaths `json:"host_paths"`
PortMappings *PortMappings `json:"port_mappings"`
Devices *Devices `json:"devices"`
Envs *Envs `json:"envs"`
Properties map[string]string `json:"properties"`
}
type LLMSkuBaseUpdateInput struct {
apis.SharableVirtualResourceBaseUpdateInput
Cpu *int `json:"cpu"`
Memory *int `json:"memory"`
// RequstSyncImage *bool `json:"request_sync_image"`
DiskSize *int `json:"disk_size" yunion-deprecated-by:"disk_size_mb"`
DiskSizeMB *int `json:"disk_size_mb"`
TemplateId *string `json:"template_id"`
StorageType *string `json:"storage_type"`
Volumes *Volumes `json:"volumes"`
HostPaths *HostPaths `json:"host_paths"`
Bandwidth *int `json:"bandwidth"`
PortMappings *PortMappings `json:"port_mappings"`
Devices *Devices `json:"devices"`
Envs *Envs `json:"envs"`
Properties map[string]string `json:"properties"`
}
type LLMSkuListInput struct {
apis.SharableVirtualResourceListInput
MountedModelResourceListInput
LLMType string `json:"llm_type"`
LLMTypes []string `json:"llm_types"`
Source string `json:"source"`
Categories string `json:"categories"`
}
type LLMSkuCreateInput struct {
LLMSKuBaseCreateInput
MountedModelResourceCreateInput
LLMImageId string `json:"llm_image_id"`
LLMType string `json:"llm_type"`
// LLMModelSpecId references one deployable spec from the in-memory model catalog.
LLMModelSpecId string `json:"llm_model_spec_id"`
// LLMSpec:
// - ollama/vllm: backend builds llm_spec from llm_image_id + mounted_models; for vllm preferred model should be set in llm_spec.vllm.preferred_model.
// - dify: client must send llm_spec with type "dify" and dify payload.
LLMSpec *LLMSpec `json:"llm_spec,omitempty"`
// Model source
Source string `json:"source"`
HuggingfaceRepoId string `json:"huggingface_repo_id"`
HuggingfaceFilename string `json:"huggingface_filename"`
ModelScopeModelId string `json:"model_scope_model_id"`
ModelScopeFilePath string `json:"model_scope_file_path"`
LocalPath string `json:"local_path"`
// Model categories
Categories []string `json:"categories"`
// Inference backend version and parameters
BackendVersion string `json:"backend_version"`
BackendParameters []string `json:"backend_parameters"`
}
type LLMSkuUpdateInput struct {
LLMSkuBaseUpdateInput
MountedModelResourceUpdateInput
LLMImageId string `json:"llm_image_id"`
// LLMSpec:
// - dify: send full spec to update image ids.
// - ollama/vllm: backend may build from llm_image_id/mounted_models; for vllm preferred model should be set in llm_spec.vllm.preferred_model.
LLMSpec *LLMSpec `json:"llm_spec,omitempty"`
// Model source
LLMModelSpecId *string `json:"llm_model_spec_id,omitempty"`
Source *string `json:"source,omitempty"`
HuggingfaceRepoId *string `json:"huggingface_repo_id,omitempty"`
HuggingfaceFilename *string `json:"huggingface_filename,omitempty"`
ModelScopeModelId *string `json:"model_scope_model_id,omitempty"`
ModelScopeFilePath *string `json:"model_scope_file_path,omitempty"`
LocalPath *string `json:"local_path,omitempty"`
// Model categories
Categories *[]string `json:"categories,omitempty"`
// Inference backend version and parameters
BackendVersion *string `json:"backend_version,omitempty"`
BackendParameters *[]string `json:"backend_parameters,omitempty"`
}
// type LLMModelCloneInput struct {
// Name string `json:"name"`
// }
// type LLMModelSyncImageRequestTaskInput struct {
// Request bool `json:"request"`
// }
// type DifySkulListInput struct {
// apis.SharableVirtualResourceListInput
// MountedModelResourceListInput
// }
// type DifySkuCreateInput struct {
// LLMSKuBaseCreateInput
// PostgresImageId string `json:"postgres_image_id"`
// RedisImageId string `json:"redis_image_id"`
// NginxImageId string `json:"nginx_image_id"`
// DifyApiImageId string `json:"dify_api_image_id"`
// DifyPluginImageId string `json:"dify_plugin_image_id"`
// DifyWebImageId string `json:"dify_web_image_id"`
// DifySandboxImageId string `json:"dify_sandbox_image_id"`
// DifySSRFImageId string `json:"dify_ssrf_image_id"`
// DifyWeaviateImageId string `json:"dify_weaviate_image_id"`
// }
// type DifySkuUpdateInput struct {
// LLMSkuBaseUpdateInput
// PostgresImageId string `json:"postgres_image_id"`
// RedisImageId string `json:"redis_image_id"`
// NginxImageId string `json:"nginx_image_id"`
// DifyApiImageId string `json:"dify_api_image_id"`
// DifyPluginImageId string `json:"dify_plugin_image_id"`
// DifyWebImageId string `json:"dify_web_image_id"`
// DifySandboxImageId string `json:"dify_sandbox_image_id"`
// DifySSRFImageId string `json:"dify_ssrf_image_id"`
// DifyWeaviateImageId string `json:"dify_weaviate_image_id"`
// }
// LLMSchedulableCheckInput is the query params for
// GET /llm_skus/{id}/schedulable-check
type LLMSchedulableCheckInput struct {
GpuCount int `json:"gpu_count,omitempty"`
}
// LLMSchedulableHostInfo describes GPU availability on one candidate host.
type LLMSchedulableHostInfo struct {
HostId string `json:"host_id"`
HostName string `json:"host_name"`
GpuAvailable int `json:"gpu_available"`
BestGpuVramMb int `json:"best_gpu_vram_mb"`
BestGpuModel string `json:"best_gpu_model,omitempty"`
}
// LLMSchedulableCheckOutput mirrors GPUStack's ModelEvaluationResult:
// a yes/no verdict plus per-host detail so the caller can surface a
// meaningful message ("not enough VRAM on any host", "host X qualifies", …).
type LLMSchedulableCheckOutput struct {
Schedulable bool `json:"schedulable"`
VramClaimMb int `json:"vram_claim_mb"`
PerDevMinMb int `json:"per_dev_min_mb"`
GpuCount int `json:"gpu_count"`
Reason string `json:"reason,omitempty"`
FilteredCandidates jsonutils.JSONObject `json:"filtered_candidates,omitempty"`
Hosts []LLMSchedulableHostInfo `json:"hosts,omitempty"`
TotalGpuHosts int `json:"total_gpu_hosts"`
QualifiedHosts int `json:"qualified_hosts"`
}