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