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