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 16 kB

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