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