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