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

1 year ago
1 year ago
6 months ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. package schsdk
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/types"
  4. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  5. "gitlink.org.cn/cloudream/common/utils/serder"
  6. )
  7. const (
  8. JobTypeNormal = "Normal"
  9. JobTypePCM = "PCM"
  10. JobTypeResource = "Resource"
  11. JobTypeInstance = "Instance"
  12. JobTypeFinetuning = "Finetuning"
  13. JobTypeDataPreprocess = "DataPreprocess"
  14. JobTypeDataReturn = "DataReturn"
  15. FileInfoTypePackage = "Package"
  16. FileInfoTypeLocalFile = "LocalFile"
  17. FileInfoTypeResource = "Resource"
  18. FileInfoTypeImage = "Image"
  19. FILE = "file"
  20. FOLDER = "folder"
  21. MemoryUtilization = "MemoryUtilization"
  22. GPUUtilization = "GPUUtilization"
  23. CPUUtilization = "CPUUtilization"
  24. )
  25. type JobID string
  26. type JobSetID string
  27. type DataID int64
  28. type ImageID int64
  29. // 计算中心ID
  30. type CCID int64
  31. type ModelID string
  32. type ModelName string
  33. type ECSInstanceID string
  34. type NodeID int64
  35. type Address string
  36. type ClusterID string
  37. type JobSetInfo struct {
  38. Jobs []JobInfo `json:"jobs"`
  39. }
  40. type JobInfo interface {
  41. GetLocalJobID() string
  42. GetTargetLocalJobIDs() []string
  43. SetTargetLocalJob(info TargetJobInfo)
  44. GetTargetInputParams(targetID string) map[string]string
  45. }
  46. var JobInfoTypeUnion = types.NewTypeUnion[JobInfo](
  47. (*NormalJobInfo)(nil),
  48. (*DataReturnJobInfo)(nil),
  49. (*MultiInstanceJobInfo)(nil),
  50. (*InstanceJobInfo)(nil),
  51. (*UpdateMultiInstanceJobInfo)(nil),
  52. (*FinetuningJobInfo)(nil),
  53. (*DataPreprocessJobInfo)(nil),
  54. (*AIJobInfo)(nil),
  55. (*HPCJobInfo)(nil),
  56. (*BindingJobInfo)(nil),
  57. (*PCMInferenceJobInfo)(nil),
  58. (*CompleteJobInfo)(nil),
  59. )
  60. var _ = serder.UseTypeUnionInternallyTagged(&JobInfoTypeUnion, "type")
  61. type JobInfoBase struct {
  62. LocalJobID string `json:"localJobID"`
  63. TargetJob []TargetJobInfo `json:"targetJob"`
  64. }
  65. type TargetJobInfo struct {
  66. TargetJobID string `json:"targetJobID"`
  67. InputParams map[string]string `json:"inputParams"`
  68. }
  69. func (i *JobInfoBase) GetLocalJobID() string {
  70. return i.LocalJobID
  71. }
  72. func (i *JobInfoBase) GetTargetInputParams(targetID string) map[string]string {
  73. for _, v := range i.TargetJob {
  74. if v.TargetJobID == targetID {
  75. return v.InputParams
  76. }
  77. }
  78. return nil
  79. }
  80. func (i *JobInfoBase) GetTargetLocalJobIDs() []string {
  81. var IDs []string
  82. for _, v := range i.TargetJob {
  83. IDs = append(IDs, v.TargetJobID)
  84. }
  85. return IDs
  86. }
  87. func (i *JobInfoBase) SetTargetLocalJob(info TargetJobInfo) {
  88. for _, target := range i.TargetJob {
  89. // 已经存在,则不用再添加
  90. if target.TargetJobID == info.TargetJobID {
  91. return
  92. }
  93. }
  94. i.TargetJob = append(i.TargetJob, info)
  95. }
  96. type NormalJobInfo struct {
  97. serder.Metadata `union:"Normal"`
  98. JobInfoBase
  99. Type string `json:"type"`
  100. Files JobFilesInfo `json:"files"`
  101. Runtime JobRuntimeInfo `json:"runtime"`
  102. Resources JobResourcesInfo `json:"resources"`
  103. Services JobServicesInfo `json:"services"`
  104. ModelJobInfo ModelJobInfo `json:"modelJobInfo"`
  105. }
  106. type PCMInferenceJobInfo struct {
  107. serder.Metadata `union:"PCM_Inference"`
  108. JobInfoBase
  109. Type string `json:"type"`
  110. Name string `json:"name"`
  111. Description string `json:"description"`
  112. Files JobFilesInfo `json:"files"`
  113. JobResources JobResources `json:"jobResources"`
  114. BindingID DataID `json:"bindingID"`
  115. }
  116. type AIJobInfo struct {
  117. serder.Metadata `union:"AI"`
  118. JobInfoBase
  119. Type string `json:"type"`
  120. Name string `json:"name"`
  121. Description string `json:"description"`
  122. Files JobFilesInfo `json:"files"`
  123. JobResources JobResources `json:"jobResources"`
  124. ResourceChoice ResourceChoice `json:"resourceChoice"`
  125. }
  126. type CompleteJobInfo struct {
  127. serder.Metadata `union:"Finish"`
  128. JobInfoBase
  129. Type string `json:"type"`
  130. }
  131. type ResourceChoice struct {
  132. Type string `json:"type"`
  133. ResourceScopes []ResourceScope `json:"resourceScopes"`
  134. }
  135. type ResourceScope struct {
  136. Name string `json:"name"`
  137. Min float64 `json:"min"`
  138. Max float64 `json:"max"`
  139. }
  140. type BindingJobInfo struct {
  141. serder.Metadata `union:"Binding"`
  142. JobInfoBase
  143. Type string `json:"type"`
  144. Info DataBinding `json:"info"`
  145. Name string `json:"name"` // 临时使用
  146. }
  147. type DataBinding interface {
  148. Noop()
  149. }
  150. var DataBindingTypeUnion = types.NewTypeUnion[DataBinding](
  151. (*ModelBinding)(nil),
  152. )
  153. var _ = serder.UseTypeUnionInternallyTagged(&DataBindingTypeUnion, "type")
  154. type DataBindingBase struct{}
  155. func (d *DataBindingBase) Noop() {}
  156. type ModelBinding struct {
  157. serder.Metadata `union:"model"`
  158. DataBindingBase
  159. Type string `json:"type"`
  160. Name string `json:"name"`
  161. Description string `json:"description"`
  162. ClusterIDs []ClusterID `json:"clusterIDs"`
  163. Category string `json:"category"`
  164. ModelType string `json:"modelType"`
  165. Env string `json:"env"`
  166. Version string `json:"version"`
  167. RepositoryName string `json:"repositoryName"`
  168. }
  169. type HPCJobInfo struct {
  170. serder.Metadata `union:"HPC"`
  171. JobInfoBase
  172. Type string `json:"type"`
  173. Name string `json:"name"`
  174. Description string `json:"description"`
  175. ClusterID ClusterID `json:"clusterID"`
  176. Backend string `json:"backend"`
  177. App string `json:"app"`
  178. OperateType string `json:"operateType"`
  179. ScriptContent string `json:"scriptContent"`
  180. Parameters HPCParameter `json:"parameters"`
  181. }
  182. type HPCParameter struct {
  183. JobName string `json:"jobName"`
  184. JobDir string `json:"jobDir"`
  185. Partition string `json:"partition"`
  186. Ntasks string `json:"ntasks"`
  187. Nodes string `json:"nodes"`
  188. BamFile string `json:"bamFile"`
  189. HashType string `json:"hashType"`
  190. AttackMode string `json:"attackMode"`
  191. HashInput string `json:"hashInput"`
  192. Mask string `json:"mask"`
  193. Dictionary string `json:"dictionary"`
  194. Dictionary2 string `json:"dictionary2"`
  195. HPCBindingFiles []HPCBindingFile `json:"hpcBindingFiles"`
  196. }
  197. type HPCBindingFile struct {
  198. ParamName string `json:"paramName"`
  199. Resource HPCFile `json:"resource"`
  200. }
  201. type HPCFile interface {
  202. Noop()
  203. }
  204. var HPCFileTypeUnion = types.NewTypeUnion[HPCFile](
  205. (*HPCObject)(nil),
  206. (*HPCPath)(nil),
  207. )
  208. var _ = serder.UseTypeUnionInternallyTagged(&HPCFileTypeUnion, "type")
  209. type HPCFileBase struct{}
  210. func (d *HPCFileBase) Noop() {}
  211. type HPCObject struct {
  212. serder.Metadata `union:"object"`
  213. HPCFileBase
  214. Type string `json:"type"`
  215. ObjectID cdssdk.ObjectID `json:"objectID"`
  216. }
  217. type HPCPath struct {
  218. serder.Metadata `union:"path"`
  219. HPCFileBase
  220. Type string `json:"type"`
  221. PackageID cdssdk.PackageID `json:"packageID"`
  222. Path string `json:"path"`
  223. }
  224. type JobResources struct {
  225. //任务分配策略:负载均衡、积分优先、随机分配等,dataLocality, leastLoadFirst
  226. ScheduleStrategy string `json:"scheduleStrategy"`
  227. Clusters []ClusterInfo `json:"clusters"`
  228. }
  229. type ClusterInfo struct {
  230. ClusterID ClusterID `json:"clusterID"`
  231. Resources []JobResource `json:"resources"`
  232. //Files JobFilesInfo `json:"files"`
  233. Code JobFileInfo `json:"code"`
  234. Runtime PCMJobRuntimeInfo `json:"runtime"`
  235. }
  236. type PCMJobRuntimeInfo struct {
  237. Command string `json:"command"`
  238. Envs map[string]interface{} `json:"envs"`
  239. Params map[string]interface{} `json:"params"`
  240. }
  241. //type Resource struct {
  242. // Resource []JobResource `json:"resource"`
  243. //}
  244. type JobResource interface {
  245. Noop()
  246. }
  247. var JobResourceTypeUnion = types.NewTypeUnion[JobResource](
  248. (*CPU)(nil),
  249. (*GPU)(nil),
  250. (*NPU)(nil),
  251. (*MLU)(nil),
  252. (*DCU)(nil),
  253. (*MEMORY)(nil),
  254. (*PRICE)(nil),
  255. (*STORAGE)(nil),
  256. )
  257. var _ = serder.UseTypeUnionInternallyTagged(&JobResourceTypeUnion, "type")
  258. type JobResourceBase struct{}
  259. func (d *JobResourceBase) Noop() {}
  260. type CPU struct {
  261. serder.Metadata `union:"CPU"`
  262. JobResourceBase
  263. Type string `json:"type"`
  264. Name string `json:"name"`
  265. Number int64 `json:"number"`
  266. }
  267. type STORAGE struct {
  268. serder.Metadata `union:"STORAGE"`
  269. JobResourceBase
  270. Type string `json:"type"`
  271. Name string `json:"name"`
  272. Number int64 `json:"number"`
  273. }
  274. type GPU struct {
  275. serder.Metadata `union:"GPU"`
  276. JobResourceBase
  277. Type string `json:"type"`
  278. Name string `json:"name"`
  279. Number int64 `json:"number"`
  280. }
  281. type NPU struct {
  282. serder.Metadata `union:"NPU"`
  283. JobResourceBase
  284. Type string `json:"type"`
  285. Name string `json:"name"`
  286. Number int64 `json:"number"`
  287. }
  288. type MEMORY struct {
  289. serder.Metadata `union:"MEMORY"`
  290. JobResourceBase
  291. Type string `json:"type"`
  292. Name string `json:"name"`
  293. Number int64 `json:"number"`
  294. }
  295. type DCU struct {
  296. serder.Metadata `union:"DCU"`
  297. JobResourceBase
  298. Type string `json:"type"`
  299. Name string `json:"name"`
  300. Number int64 `json:"number"`
  301. }
  302. type MLU struct {
  303. serder.Metadata `union:"MLU"`
  304. JobResourceBase
  305. Type string `json:"type"`
  306. Name string `json:"name"`
  307. Number int64 `json:"number"`
  308. }
  309. type PRICE struct {
  310. serder.Metadata `union:"PRICE"`
  311. JobResourceBase
  312. Type string `json:"type"`
  313. Name string `json:"name"`
  314. Number int64 `json:"number"`
  315. }
  316. // FinetuningJobInfo 模型微调
  317. type FinetuningJobInfo struct {
  318. serder.Metadata `union:"Finetuning"`
  319. JobInfoBase
  320. Type string `json:"type"`
  321. Files JobFilesInfo `json:"files"`
  322. Runtime JobRuntimeInfo `json:"runtime"`
  323. Resources JobResourcesInfo `json:"resources"`
  324. Services JobServicesInfo `json:"services"`
  325. ModelJobInfo ModelJobInfo `json:"modelJobInfo"`
  326. }
  327. // DataPreprocessJobInfo 数据预处理
  328. type DataPreprocessJobInfo struct {
  329. serder.Metadata `union:"DataPreprocess"`
  330. JobInfoBase
  331. Type string `json:"type"`
  332. Files JobFilesInfo `json:"files"`
  333. Runtime JobRuntimeInfo `json:"runtime"`
  334. Resources JobResourcesInfo `json:"resources"`
  335. Services JobServicesInfo `json:"services"`
  336. }
  337. type DataReturnJobInfo struct {
  338. serder.Metadata `union:"DataReturn"`
  339. JobInfoBase
  340. Type string `json:"type"`
  341. BucketID cdssdk.BucketID `json:"bucketID"`
  342. TargetLocalJobID string `json:"targetLocalJobID"`
  343. ReportMessage []ReportMessage `json:"reportMessage"`
  344. }
  345. // MultiInstanceJobInfo 多实例(推理任务)
  346. type MultiInstanceJobInfo struct {
  347. serder.Metadata `union:"MultiInstance"`
  348. JobInfoBase
  349. Type string `json:"type"`
  350. Files JobFilesInfo `json:"files"`
  351. Runtime JobRuntimeInfo `json:"runtime"`
  352. Resources JobResourcesInfo `json:"resources"`
  353. ModelJobInfo ModelJobInfo `json:"modelJobInfo"`
  354. }
  355. // UpdateMultiInstanceJobInfo 更新模型
  356. type UpdateMultiInstanceJobInfo struct {
  357. serder.Metadata `union:"UpdateModel"`
  358. JobInfoBase
  359. Type string `json:"type"`
  360. Files JobFilesInfo `json:"files"`
  361. Runtime JobRuntimeInfo `json:"runtime"`
  362. MultiInstanceJobSetID JobSetID `json:"multiInstanceJobSetID"`
  363. UpdateType string `json:"updateType"`
  364. SubJobs []JobID `json:"subJobs"`
  365. Operate string `json:"operate"`
  366. }
  367. type ModelJobInfo struct {
  368. Type string `json:"type"`
  369. ModelID ModelID `json:"modelID"`
  370. CustomModelName ModelName `json:"customModelName"`
  371. Command string `json:"command"`
  372. }
  373. // InstanceJobInfo 单实例(推理任务)
  374. type InstanceJobInfo struct {
  375. serder.Metadata `union:"Instance"`
  376. JobInfoBase
  377. Type string `json:"type"`
  378. LocalJobID string `json:"multiInstJobID"`
  379. Files JobFilesInfo `json:"files"`
  380. Runtime JobRuntimeInfo `json:"runtime"`
  381. Resources JobResourcesInfo `json:"resources"`
  382. ModelJobInfo ModelJobInfo `json:"modelJobInfo"`
  383. }
  384. type JobFilesInfo struct {
  385. Dataset JobFileInfo `json:"dataset"`
  386. Code JobFileInfo `json:"code"`
  387. Image JobFileInfo `json:"image"`
  388. Model JobFileInfo `json:"model"`
  389. }
  390. type JobFileInfo interface {
  391. Noop()
  392. }
  393. var FileInfoTypeUnion = types.NewTypeUnion[JobFileInfo](
  394. (*PackageJobFileInfo)(nil),
  395. (*LocalJobFileInfo)(nil),
  396. (*DataReturnJobFileInfo)(nil),
  397. (*ImageJobFileInfo)(nil),
  398. (*BindingJobFileInfo)(nil),
  399. )
  400. var _ = serder.UseTypeUnionInternallyTagged(&FileInfoTypeUnion, "type")
  401. type JobFileInfoBase struct{}
  402. func (i *JobFileInfoBase) Noop() {}
  403. type BindingJobFileInfo struct {
  404. serder.Metadata `union:"Binding"`
  405. JobFileInfoBase
  406. Type string `json:"type"`
  407. BindingID int64 `json:"bindingID"`
  408. // 用于参数回显
  409. BindingName string `json:"bindingName"`
  410. }
  411. type PackageJobFileInfo struct {
  412. serder.Metadata `union:"Package"`
  413. JobFileInfoBase
  414. Type string `json:"type"`
  415. PackageID cdssdk.PackageID `json:"packageID"`
  416. }
  417. type LocalJobFileInfo struct {
  418. serder.Metadata `union:"LocalFile"`
  419. JobFileInfoBase
  420. Type string `json:"type"`
  421. LocalPath string `json:"localPath"`
  422. }
  423. type DataReturnJobFileInfo struct {
  424. serder.Metadata `union:"DataReturn"`
  425. JobFileInfoBase
  426. Type string `json:"type"`
  427. DataReturnLocalJobID string `json:"dataReturnLocalJobID"`
  428. }
  429. type ImageJobFileInfo struct {
  430. serder.Metadata `union:"Image"`
  431. JobFileInfoBase
  432. Type string `json:"type"`
  433. ImageID ImageID `json:"imageID"`
  434. // 用于参数回显
  435. ImageName string `json:"imageName"`
  436. }
  437. type JobRuntimeInfo struct {
  438. Command string `json:"command"`
  439. Envs []KVPair `json:"envs"`
  440. Params []KVPair `json:"params"`
  441. }
  442. type KVPair struct {
  443. Key string `json:"key"`
  444. Value string `json:"value"`
  445. }
  446. // CPU、GPU、NPU、MLU单位为:核
  447. // Storage、Memory单位为:字节
  448. type JobResourcesInfo struct {
  449. CPU float64 `json:"cpu"`
  450. GPU float64 `json:"gpu"`
  451. NPU float64 `json:"npu"`
  452. MLU float64 `json:"mlu"`
  453. Storage int64 `json:"storage"`
  454. Memory int64 `json:"memory"`
  455. }
  456. type JobSetFilesUploadScheme struct {
  457. LocalFileSchemes []LocalFileUploadScheme `json:"localFileUploadSchemes"`
  458. }
  459. type JobFilesUploadScheme struct {
  460. LocalFileSchemes []LocalFileUploadScheme `json:"localFileUploadSchemes"`
  461. }
  462. type LocalFileUploadScheme struct {
  463. LocalPath string `json:"localPath"`
  464. UploadToCDStorageID cdssdk.StorageID `json:"uploadToCDSStorageID"`
  465. }
  466. type JobServicesInfo struct {
  467. ServicePortInfos []ServicePortInfo `json:"servicePortInfos"`
  468. }
  469. type ServicePortInfo struct {
  470. Name string `json:"name"`
  471. Port int64 `json:"port"`
  472. }
  473. type JobSetServiceInfo struct {
  474. Name string `json:"name"`
  475. Port int64 `json:"port"`
  476. CDSStorageID cdssdk.StorageID `json:"cdsStorageID"`
  477. LocalJobID string `json:"localJobID"`
  478. }
  479. type Bootstrap interface {
  480. GetBootstrapType() string
  481. }
  482. type DirectBootstrap struct {
  483. serder.Metadata `union:"Direct"`
  484. Type string `json:"type"`
  485. }
  486. type NoEnvBootstrap struct {
  487. serder.Metadata `union:"NoEnv"`
  488. Type string `json:"type"`
  489. ScriptPackageID cdssdk.PackageID `json:"scriptPackageID"`
  490. ScriptFileName string `json:"scriptFileName"`
  491. }
  492. var BootstrapTypeUnion = types.NewTypeUnion[Bootstrap](
  493. (*DirectBootstrap)(nil),
  494. (*NoEnvBootstrap)(nil),
  495. )
  496. var _ = serder.UseTypeUnionInternallyTagged(&BootstrapTypeUnion, "type")
  497. func (b *DirectBootstrap) GetBootstrapType() string {
  498. return b.Type
  499. }
  500. func (b *NoEnvBootstrap) GetBootstrapType() string {
  501. return b.Type
  502. }
  503. const (
  504. JobDataInEnv = "SCH_DATA_IN"
  505. JobDataOutEnv = "SCH_DATA_OUT"
  506. FinetuningOutEnv = "FINETUNING_OUT"
  507. AccessPath = "ACCESS_PATH"
  508. )
  509. type Rclone struct {
  510. CDSRcloneID string `json:"cds_rcloneID"`
  511. CDSRcloneConfigID string `json:"cds_rcloneConfigID"`
  512. }
  513. type InferencePlatform struct {
  514. PlatformName string `json:"platformName"`
  515. ApiBaseUrl string `json:"apiBaseUrl"`
  516. ApiKey string `json:"apiKey"`
  517. ApiProxy string `json:"apiProxy"`
  518. LlmModel string `json:"llmModel"`
  519. EmbedModel string `json:"embedModel"`
  520. ChunkMaxLength string `json:"chunkMaxLength"`
  521. StartChunkThreshold string `json:"startChunkThreshold"`
  522. SimilarityThreshold string `json:"similarityThreshold"`
  523. EntriesPerFile string `json:"entriesPerFile"`
  524. }
  525. type JobOutput interface {
  526. Output()
  527. }
  528. var JobOutputTypeUnion = types.NewTypeUnion[JobOutput](
  529. (*AIJobOutput)(nil),
  530. (*BindingJobOutput)(nil),
  531. )
  532. var _ = serder.UseTypeUnionInternallyTagged(&JobOutputTypeUnion, "type")
  533. type JobOutputBase struct{}
  534. func (d *JobOutputBase) Output() {}
  535. type PublicOutput struct {
  536. serder.Metadata `union:"object"`
  537. JobOutputBase
  538. Type string `json:"type"`
  539. }
  540. type AIJobOutput struct {
  541. serder.Metadata `union:"object"`
  542. JobOutputBase
  543. Type string `json:"type"`
  544. }
  545. type BindingJobOutput struct {
  546. serder.Metadata `union:"binding"`
  547. JobOutputBase
  548. Type string `json:"type"`
  549. BindingID DataID `json:"bindingID"`
  550. }
  551. type DataReturnJobOutput struct {
  552. serder.Metadata `union:"DataReturn"`
  553. JobOutputBase
  554. Type string `json:"type"`
  555. ReportMessage []ReportMessage `json:"reportMessage"`
  556. }
  557. type ReportMessage struct {
  558. TaskName string `json:"taskName"`
  559. TaskID string `json:"taskID"`
  560. Status bool `json:"status"`
  561. Message string `json:"message"`
  562. ClusterID ClusterID `json:"clusterID"`
  563. Output string `json:"output"`
  564. }