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

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