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