You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.go 17 kB

6 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
6 months ago
6 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. package sch
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/types"
  4. "gitlink.org.cn/cloudream/common/sdks/hpc"
  5. schsdk "gitlink.org.cn/cloudream/common/sdks/scheduler"
  6. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  7. "gitlink.org.cn/cloudream/common/utils/serder"
  8. "time"
  9. )
  10. type ResourceType string
  11. const (
  12. ResourceTypeCPU ResourceType = "CPU"
  13. ResourceTypeNPU ResourceType = "NPU"
  14. ResourceTypeGPU ResourceType = "GPU"
  15. ResourceTypeMLU ResourceType = "MLU"
  16. ResourceTypeStorage ResourceType = "STORAGE"
  17. ResourceTypeMemory ResourceType = "MEMORY"
  18. ResourceTypeDCU ResourceType = "DCU"
  19. ResourceTypeGCU ResourceType = "GCU"
  20. Split = "/"
  21. CODE = "code"
  22. DATASET = "dataset"
  23. IMAGE = "image"
  24. MODEL = "model"
  25. RESULT = "result"
  26. PackageTypeNormal = "normal"
  27. PackageTypeNull = "null"
  28. Null = "null"
  29. OrderByName = "name"
  30. OrderBySize = "size"
  31. OrderByTime = "time"
  32. StorageTypeURL = "url"
  33. StorageTypeJCS = "jcs"
  34. RejectedStatus = "rejected"
  35. PendingStatus = "pending"
  36. ApprovedStatus = "approved"
  37. RevokedStatus = "revoked"
  38. CancelStatus = "cancel"
  39. ExpiredStatus = "expired"
  40. ApplyAccess = "apply"
  41. PrivateAccess = "private"
  42. PublicAccess = "public"
  43. PreferencePriority = "preference"
  44. SpecifyClusterPriority = "specify"
  45. FailedStatus = "failed"
  46. SuccessStatus = "success"
  47. SucceededStatus = "succeeded"
  48. UploadingStatus = "uploading"
  49. RunningStatus = "running"
  50. Query = "query"
  51. Delete = "delete"
  52. ChildrenType = "children"
  53. ParentType = "parent"
  54. PlatformSugon = "sugon"
  55. PlatformOpenI = "OpenI"
  56. PlatformModelArts = "ModelArts"
  57. PlatformAI = "AI" // 智算
  58. PlatformCloud = "CLOUD" // 云算
  59. PlatformCloudInference = "PCM_Inference"
  60. PlatformHPC = "HPCSlurm" //超算
  61. URL = "url"
  62. ID = "id"
  63. Startup = "startup"
  64. Schedule = "schedule"
  65. BlockChainJobCreatePrefix = "job_create_"
  66. Complete = "Complete"
  67. NodeTypeBinding = "binding"
  68. NodeTypeUpload = "upload"
  69. NodeTypeDataReturn = "data_return"
  70. NodeTypeHPCCreate = "hpc_create"
  71. NodeTypeInference = "inference"
  72. NodeTypeInferenceStop = "inference_stop"
  73. NodeTypeAICreate = "ai_job_create"
  74. NodeTypeAIJobRun = "ai_job_run"
  75. NodeTypeNotify = "notify"
  76. )
  77. type TaskID int64
  78. type DataID int64
  79. type ClusterDetail struct {
  80. // 集群ID
  81. ClusterId schsdk.ClusterID `json:"clusterID"`
  82. // 集群功能类型:云算,智算,超算
  83. ClusterType string `json:"clusterType"`
  84. // 集群地区:华东地区、华南地区、华北地区、华中地区、西南地区、西北地区、东北地区
  85. Region string `json:"region"`
  86. // 资源类型
  87. Resources2 []ResourceData `json:"resources1,omitempty"`
  88. //Resources2 []ResourceData `json:"resources"`
  89. Resources []ClusterResource `json:"resources"`
  90. }
  91. type ClusterResource struct {
  92. Resource TmpResourceData `json:"resource"`
  93. BaseResources []TmpResourceData `json:"baseResources"`
  94. }
  95. type TmpResourceData struct {
  96. Type ResourceType `json:"type"`
  97. Name string `json:"name"`
  98. Total UnitValue[float64] `json:"total"`
  99. Available UnitValue[float64] `json:"available"`
  100. }
  101. type ResourceData interface {
  102. Noop()
  103. }
  104. var ResourceDataTypeUnion = types.NewTypeUnion[ResourceData](
  105. (*CPUResourceData)(nil),
  106. (*NPUResourceData)(nil),
  107. (*GPUResourceData)(nil),
  108. (*MLUResourceData)(nil),
  109. (*DCUResourceData)(nil),
  110. (*GCUResourceData)(nil),
  111. (*GPGPUResourceData)(nil),
  112. (*StorageResourceData)(nil),
  113. (*MemoryResourceData)(nil),
  114. (*BalanceResourceData)(nil),
  115. (*RateResourceData)(nil),
  116. )
  117. var _ = serder.UseTypeUnionInternallyTagged(&ResourceDataTypeUnion, "type")
  118. type ResourceDataBase struct{}
  119. func (d *ResourceDataBase) Noop() {}
  120. type UnitValue[T any] struct {
  121. Unit string `json:"unit"`
  122. Value T `json:"value"`
  123. }
  124. type CPUResourceData struct {
  125. serder.Metadata `union:"CPU"`
  126. ResourceDataBase
  127. Type string `json:"type"`
  128. Name ResourceType `json:"name"`
  129. Total UnitValue[int64] `json:"total"`
  130. Available UnitValue[int64] `json:"available"`
  131. }
  132. type NPUResourceData struct {
  133. serder.Metadata `union:"NPU"`
  134. ResourceDataBase
  135. Type string `json:"type"`
  136. Name ResourceType `json:"name"`
  137. Total UnitValue[int64] `json:"total"`
  138. Available UnitValue[int64] `json:"available"`
  139. }
  140. type GPUResourceData struct {
  141. serder.Metadata `union:"GPU"`
  142. ResourceDataBase
  143. Type string `json:"type"`
  144. Name ResourceType `json:"name"`
  145. Total UnitValue[int64] `json:"total"`
  146. Available UnitValue[int64] `json:"available"`
  147. }
  148. type MLUResourceData struct {
  149. serder.Metadata `union:"MLU"`
  150. ResourceDataBase
  151. Type string `json:"type"`
  152. Name ResourceType `json:"name"`
  153. Total UnitValue[int64] `json:"total"`
  154. Available UnitValue[int64] `json:"available"`
  155. }
  156. type DCUResourceData struct {
  157. serder.Metadata `union:"DCU"`
  158. ResourceDataBase
  159. Type string `json:"type"`
  160. Name ResourceType `json:"name"`
  161. Total UnitValue[int64] `json:"total"`
  162. Available UnitValue[int64] `json:"available"`
  163. }
  164. type GCUResourceData struct {
  165. serder.Metadata `union:"GCU"`
  166. ResourceDataBase
  167. Type string `json:"type"`
  168. Name ResourceType `json:"name"`
  169. Total UnitValue[int64] `json:"total"`
  170. Available UnitValue[int64] `json:"available"`
  171. }
  172. type GPGPUResourceData struct {
  173. serder.Metadata `union:"ILUVATAR-GPGPU"`
  174. ResourceDataBase
  175. Type string `json:"type"`
  176. Name ResourceType `json:"name"`
  177. Total UnitValue[int64] `json:"total"`
  178. Available UnitValue[int64] `json:"available"`
  179. }
  180. type StorageResourceData struct {
  181. serder.Metadata `union:"STORAGE"`
  182. ResourceDataBase
  183. Type string `json:"type"`
  184. Name ResourceType `json:"name"`
  185. Total UnitValue[float64] `json:"total"`
  186. Available UnitValue[float64] `json:"available"`
  187. }
  188. type MemoryResourceData struct {
  189. serder.Metadata `union:"MEMORY"`
  190. ResourceDataBase
  191. Type string `json:"type"`
  192. Name ResourceType `json:"name"`
  193. Total UnitValue[float64] `json:"total"`
  194. Available UnitValue[float64] `json:"available"`
  195. }
  196. type BalanceResourceData struct {
  197. serder.Metadata `union:"BALANCE"`
  198. ResourceDataBase
  199. Type string `json:"type"`
  200. Name ResourceType `json:"name"`
  201. Total UnitValue[float64] `json:"total"`
  202. Available UnitValue[float64] `json:"available"`
  203. }
  204. type RateResourceData struct {
  205. serder.Metadata `union:"RATE"`
  206. ResourceDataBase
  207. Type string `json:"type"`
  208. Name ResourceType `json:"name"`
  209. Total UnitValue[float64] `json:"total"`
  210. Available UnitValue[float64] `json:"available"`
  211. }
  212. type ResourceRange struct {
  213. UserID cdssdk.UserID `json:"userID"`
  214. Type ResourceType `json:"type"`
  215. GPU Range `json:"gpu"`
  216. GPUNumber int `json:"gpuNumber"`
  217. CPU Range `json:"cpu"`
  218. Memory Range `json:"memory"`
  219. Storage Range `json:"storage"`
  220. Ids []string `json:"ids"`
  221. }
  222. type JobInfo struct {
  223. TaskID string `json:"taskID"`
  224. JobSubmitInfo JobSubmitInfo `json:"jobSubmitInfo"`
  225. ResultFiles []ResultFile `json:"resultFiles"`
  226. }
  227. type ResultFile struct {
  228. ClusterID schsdk.ClusterID `json:"clusterID"`
  229. Objects []cdssdk.Object `json:"objects"`
  230. }
  231. type JobSubmitInfo interface {
  232. Noop()
  233. }
  234. type JobSubmitInfoBase struct {
  235. }
  236. var JobSubmitInfoTypeUnion = types.NewTypeUnion[JobSubmitInfo](
  237. (*PCMJobSubmitInfo)(nil),
  238. (*HPCJobSubmitInfo)(nil),
  239. )
  240. var _ = serder.UseTypeUnionInternallyTagged(&JobSubmitInfoTypeUnion, "type")
  241. func (d *JobSubmitInfoBase) Noop() {}
  242. type PCMJobSubmitInfo struct {
  243. serder.Metadata `union:"pcm"`
  244. JobSubmitInfoBase
  245. Type string `json:"type"`
  246. Info CreateAIJobReq `json:"info"`
  247. }
  248. type HPCJobSubmitInfo struct {
  249. serder.Metadata `union:"hpc"`
  250. JobSubmitInfoBase
  251. Type string `json:"type"`
  252. Info hpc.CreateHPCJobReq `json:"info"`
  253. }
  254. type Range struct {
  255. Min float64 `json:"min"`
  256. Max float64 `json:"max"`
  257. }
  258. type ResourcePriority interface {
  259. Noop()
  260. }
  261. type ResourcePriorityBase struct {
  262. }
  263. var ResourcePriorityTypeUnion = types.NewTypeUnion[ResourcePriority](
  264. (*RegionPriority)(nil),
  265. (*ChipPriority)(nil),
  266. (*BiasPriority)(nil),
  267. )
  268. var _ = serder.UseTypeUnionInternallyTagged(&ResourcePriorityTypeUnion, "type")
  269. func (d *ResourcePriorityBase) Noop() {}
  270. type RegionPriority struct {
  271. serder.Metadata `union:"region"`
  272. ResourcePriorityBase
  273. Type string `json:"type"`
  274. Options []string `json:"options"`
  275. }
  276. type ChipPriority struct {
  277. serder.Metadata `union:"chip"`
  278. ResourcePriorityBase
  279. Type string `json:"type"`
  280. Options []string `json:"options"`
  281. }
  282. type BiasPriority struct {
  283. serder.Metadata `union:"bias"`
  284. ResourcePriorityBase
  285. Type string `json:"type"`
  286. Options []string `json:"options"`
  287. }
  288. type TaskMessage struct {
  289. Status string `json:"status"`
  290. Message string `json:"message"`
  291. }
  292. type ReportMessage struct {
  293. TaskName string `json:"taskName"`
  294. TaskID string `json:"taskID"`
  295. Status bool `json:"status"`
  296. Message string `json:"message"`
  297. ClusterID schsdk.ClusterID `json:"clusterID"`
  298. Output string `json:"output"`
  299. }
  300. type UploadParams struct {
  301. DataType string `json:"dataType"`
  302. UploadInfo UploadInfo `json:"uploadInfo"`
  303. }
  304. type UploadInfo interface {
  305. Noop()
  306. }
  307. var UploadInfoTypeUnion = types.NewTypeUnion[UploadInfo](
  308. (*LocalUploadInfo)(nil),
  309. (*RemoteUploadInfo)(nil),
  310. )
  311. var _ = serder.UseTypeUnionInternallyTagged(&UploadInfoTypeUnion, "type")
  312. type LocalUploadInfo struct {
  313. serder.Metadata `union:"local"`
  314. UploadInfoBase
  315. Type string `json:"type"`
  316. LocalPath string `json:"localPath"`
  317. ObjectIDs []cdssdk.ObjectID `json:"objectIDs"`
  318. }
  319. type RemoteUploadInfo struct {
  320. serder.Metadata `union:"url"`
  321. UploadInfoBase
  322. Type string `json:"type"`
  323. Url string `json:"url"`
  324. Branch string `json:"branch"`
  325. DataName string `json:"dataName"`
  326. Cluster schsdk.ClusterID `json:"clusterID"`
  327. }
  328. type UploadInfoBase struct{}
  329. func (d *UploadInfoBase) Noop() {}
  330. type UploadPriority interface {
  331. Noop()
  332. }
  333. var UploadPriorityTypeUnion = types.NewTypeUnion[UploadPriority](
  334. (*Preferences)(nil),
  335. (*SpecifyCluster)(nil),
  336. )
  337. var _ = serder.UseTypeUnionInternallyTagged(&UploadPriorityTypeUnion, "type")
  338. type Preferences struct {
  339. serder.Metadata `union:"preference"`
  340. UploadPriorityBase
  341. Type string `json:"type"`
  342. ResourcePriorities []ResourcePriority `json:"priorities"`
  343. }
  344. type SpecifyCluster struct {
  345. serder.Metadata `union:"specify"`
  346. UploadPriorityBase
  347. Type string `json:"type"`
  348. Clusters []schsdk.ClusterID `json:"clusters"`
  349. }
  350. type UploadPriorityBase struct{}
  351. func (d *UploadPriorityBase) Noop() {}
  352. type QueryData struct {
  353. DataType string `json:"dataType" binding:"required"`
  354. UserID cdssdk.UserID `json:"userID" binding:"required"`
  355. Path string `json:"path"`
  356. PackageID cdssdk.PackageID `json:"packageID" binding:"required"`
  357. CurrentPage int `json:"currentPage"`
  358. PageSize int `json:"pageSize"`
  359. OrderBy string `json:"orderBy" binding:"required"`
  360. PackageName string `json:"packageName"`
  361. }
  362. type DataBinding interface {
  363. Noop()
  364. }
  365. var DataBindingTypeUnion = types.NewTypeUnion[DataBinding](
  366. (*DatasetBinding)(nil),
  367. (*ModelBinding)(nil),
  368. (*CodeBinding)(nil),
  369. (*ImageBinding)(nil),
  370. )
  371. var _ = serder.UseTypeUnionInternallyTagged(&DataBindingTypeUnion, "type")
  372. type DataBindingBase struct {
  373. RootPath string `json:"rootPath"`
  374. }
  375. func (d *DataBindingBase) Noop() {}
  376. type DatasetBinding struct {
  377. serder.Metadata `union:"dataset"`
  378. DataBindingBase
  379. Type string `json:"type"`
  380. Name string `json:"name"`
  381. OperateType string `json:"operateType"`
  382. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  383. Description string `json:"description"`
  384. Category string `json:"category"`
  385. PackageID cdssdk.PackageID `json:"packageID"`
  386. RepositoryName string `json:"repositoryName"`
  387. ConsumptionPoints int64 `json:"points"`
  388. }
  389. type ModelBinding struct {
  390. serder.Metadata `union:"model"`
  391. DataBindingBase
  392. Type string `json:"type"`
  393. Name string `json:"name"`
  394. OperateType string `json:"operateType"`
  395. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  396. Description string `json:"description"`
  397. Category string `json:"category"`
  398. ModelType string `json:"modelType"`
  399. Env string `json:"env"`
  400. Version string `json:"version"`
  401. PackageID cdssdk.PackageID `json:"packageID"`
  402. RepositoryName string `json:"repositoryName"`
  403. }
  404. type CodeBinding struct {
  405. serder.Metadata `union:"code"`
  406. DataBindingBase
  407. Type string `json:"type"`
  408. Name string `json:"name"`
  409. OperateType string `json:"operateType"`
  410. ClusterID schsdk.ClusterID `json:"clusterID"`
  411. Description string `json:"description"`
  412. ImageID schsdk.ImageID `json:"imageID"`
  413. BootstrapObjectID cdssdk.ObjectID `json:"bootstrapObjectID"`
  414. PackageID cdssdk.PackageID `json:"packageID"`
  415. Output string `json:"output"`
  416. // 当集群为openi的时候,需要传入分支
  417. Branch string `json:"branch"`
  418. }
  419. //type ImageBinding struct {
  420. // serder.Metadata `union:"image"`
  421. // DataBindingBase
  422. // Type string `json:"type"`
  423. // Name string `json:"name"`
  424. // ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  425. // Description string `json:"description"`
  426. // Architecture string `json:"architecture"`
  427. // ResourceType string `json:"resourceType"`
  428. // Tags []string `json:"tags"`
  429. // PackageID cdssdk.PackageID `json:"packageID"`
  430. //}
  431. type ImageBinding struct {
  432. serder.Metadata `union:"image"`
  433. DataBindingBase
  434. Type string `json:"type"`
  435. ID int64 `json:"id"`
  436. OperateType string `json:"operateType"`
  437. Name string `json:"name"`
  438. IDType string `json:"idType"`
  439. ImageID string `json:"imageID"`
  440. ClusterID schsdk.ClusterID `json:"clusterID"`
  441. }
  442. type Image struct {
  443. ImageID schsdk.ImageID `json:"imageID" gorm:"column:ImageID;primaryKey"`
  444. Name string `json:"name" gorm:"column:Name"`
  445. CreateTime time.Time `json:"createTime" gorm:"column:CreateTime"`
  446. ClusterImage []ClusterImage `gorm:"foreignKey:image_id;references:ImageID" json:"clusterImages"`
  447. }
  448. type ClusterImage struct {
  449. ImageID schsdk.ImageID `gorm:"column:image_id" json:"imageID"`
  450. ClusterID schsdk.ClusterID `gorm:"column:cluster_id" json:"clusterID"`
  451. OriginImageType string `gorm:"column:origin_image_type" json:"originImageType"`
  452. OriginImageID string `gorm:"column:origin_image_id" json:"originImageID"`
  453. OriginImageName string `gorm:"column:origin_image_name" json:"originImageName"`
  454. ClusterImageCard []ClusterImageCard `gorm:"foreignKey:origin_image_id;references:origin_image_id" json:"cards"`
  455. }
  456. func (ClusterImage) TableName() string {
  457. return "cluster_image"
  458. }
  459. type ClusterImageCard struct {
  460. OriginImageID string `gorm:"column:origin_image_id" json:"originImageID"`
  461. Card string `gorm:"column:card" json:"card"`
  462. }
  463. func (ClusterImageCard) TableName() string {
  464. return "cluster_image_card"
  465. }
  466. type QueryBindingFilters struct {
  467. Status string `json:"status"`
  468. Name string `json:"name"`
  469. }
  470. type QueryBindingDataParam interface {
  471. Noop()
  472. }
  473. var QueryBindingDataParamTypeUnion = types.NewTypeUnion[QueryBindingDataParam](
  474. (*PrivateLevel)(nil),
  475. (*ApplyLevel)(nil),
  476. (*PublicLevel)(nil),
  477. )
  478. var _ = serder.UseTypeUnionInternallyTagged(&QueryBindingDataParamTypeUnion, "type")
  479. type QueryBindingDataParamBase struct{}
  480. func (d *QueryBindingDataParamBase) Noop() {}
  481. type PrivateLevel struct {
  482. serder.Metadata `union:"private"`
  483. QueryBindingDataParamBase
  484. Type string `json:"type" binding:"required"`
  485. UserID cdssdk.UserID `json:"userID" binding:"required"`
  486. BindingID int64 `json:"bindingID" binding:"required"`
  487. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  488. }
  489. type ApplyLevel struct {
  490. serder.Metadata `union:"apply"`
  491. QueryBindingDataParamBase
  492. Type string `json:"type" binding:"required"`
  493. UserID cdssdk.UserID `json:"userID" binding:"required"`
  494. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  495. }
  496. type PublicLevel struct {
  497. serder.Metadata `union:"public"`
  498. QueryBindingDataParamBase
  499. UserID cdssdk.UserID `json:"userID" binding:"required"`
  500. Type string `json:"type" binding:"required"`
  501. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  502. }