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

1 year ago
1 year ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. JobTypeResource = "Resource"
  10. JobTypeInstance = "Instance"
  11. JobTypeFinetuning = "Finetuning"
  12. JobTypeDataPreprocess = "DataPreprocess"
  13. FileInfoTypePackage = "Package"
  14. FileInfoTypeLocalFile = "LocalFile"
  15. FileInfoTypeResource = "Resource"
  16. FileInfoTypeImage = "Image"
  17. FILE = "file"
  18. FOLDER = "folder"
  19. MemoryUtilization = "MemoryUtilization"
  20. GPUUtilization = "GPUUtilization"
  21. CPUUtilization = "CPUUtilization"
  22. )
  23. type JobID string
  24. type JobSetID string
  25. type ImageID int64
  26. // 计算中心ID
  27. type CCID int64
  28. type ModelID string
  29. type ModelName string
  30. type ECSInstanceID string
  31. type NodeID int64
  32. type Address string
  33. type ClusterID string
  34. type JobSetInfo struct {
  35. Jobs []JobInfo `json:"jobs"`
  36. }
  37. type JobInfo interface {
  38. GetLocalJobID() string
  39. GetTargetLocalJobID() []string
  40. }
  41. var JobInfoTypeUnion = types.NewTypeUnion[JobInfo](
  42. (*NormalJobInfo)(nil),
  43. (*DataReturnJobInfo)(nil),
  44. (*MultiInstanceJobInfo)(nil),
  45. (*InstanceJobInfo)(nil),
  46. (*UpdateMultiInstanceJobInfo)(nil),
  47. (*FinetuningJobInfo)(nil),
  48. (*DataPreprocessJobInfo)(nil),
  49. (*PCMJobInfo)(nil),
  50. (*HPCJobInfo)(nil),
  51. )
  52. var _ = serder.UseTypeUnionInternallyTagged(&JobInfoTypeUnion, "type")
  53. type JobInfoBase struct {
  54. LocalJobID string `json:"localJobID"`
  55. TargetLocalJobIDs []string `json:"targetLocalJobIDs"`
  56. }
  57. func (i *JobInfoBase) GetLocalJobID() string {
  58. return i.LocalJobID
  59. }
  60. func (i *JobInfoBase) GetTargetLocalJobID() []string {
  61. return i.TargetLocalJobIDs
  62. }
  63. type NormalJobInfo struct {
  64. serder.Metadata `union:"Normal"`
  65. JobInfoBase
  66. Type string `json:"type"`
  67. Files JobFilesInfo `json:"files"`
  68. Runtime JobRuntimeInfo `json:"runtime"`
  69. Resources JobResourcesInfo `json:"resources"`
  70. Services JobServicesInfo `json:"services"`
  71. ModelJobInfo ModelJobInfo `json:"modelJobInfo"`
  72. }
  73. type PCMJobInfo struct {
  74. serder.Metadata `union:"PCM"`
  75. JobInfoBase
  76. Type string `json:"type"`
  77. Name string `json:"name"`
  78. Description string `json:"description"`
  79. Files JobFilesInfo `json:"files"`
  80. JobResources JobResources `json:"jobResources"`
  81. }
  82. type HPCJobInfo struct {
  83. serder.Metadata `union:"HPC"`
  84. JobInfoBase
  85. Type string `json:"type"`
  86. Name string `json:"name"`
  87. ClusterID ClusterID `json:"clusterID"`
  88. Backend string `json:"backend"`
  89. App string `json:"app"`
  90. OperateType string `json:"operateType"`
  91. Parameters HPCParameter `json:"parameters"`
  92. }
  93. type HPCParameter struct {
  94. JobName string `json:"jobName"`
  95. JobDir string `json:"jobDir"`
  96. Partition string `json:"partition"`
  97. Ntasks string `json:"ntasks"`
  98. Nodes string `json:"nodes"`
  99. BamFile string `json:"bamFile"`
  100. HPCBindingFiles []HPCBindingFile `json:"hpcBindingFiles"`
  101. }
  102. type HPCBindingFile struct {
  103. ParamName string `json:"paramName"`
  104. BindingID int64 `json:"bindingID"`
  105. }
  106. type JobResources struct {
  107. //任务分配策略:负载均衡、积分优先、随机分配等,dataLocality, leastLoadFirst
  108. ScheduleStrategy string `json:"scheduleStrategy"`
  109. Clusters []ClusterInfo `json:"clusters"`
  110. }
  111. type ClusterInfo struct {
  112. ClusterID ClusterID `json:"clusterID"`
  113. Resources []JobResource `json:"resources"`
  114. //Files JobFilesInfo `json:"files"`
  115. Code JobFileInfo `json:"code"`
  116. Runtime PCMJobRuntimeInfo `json:"runtime"`
  117. }
  118. type PCMJobRuntimeInfo struct {
  119. Command string `json:"command"`
  120. Envs map[string]interface{} `json:"envs"`
  121. Params map[string]interface{} `json:"params"`
  122. }
  123. //type Resource struct {
  124. // Resource []JobResource `json:"resource"`
  125. //}
  126. type JobResource interface {
  127. Noop()
  128. }
  129. var JobResourceTypeUnion = types.NewTypeUnion[JobResource](
  130. (*CPU)(nil),
  131. (*GPU)(nil),
  132. (*NPU)(nil),
  133. (*MLU)(nil),
  134. (*DCU)(nil),
  135. (*MEMORY)(nil),
  136. (*PRICE)(nil),
  137. (*STORAGE)(nil),
  138. )
  139. var _ = serder.UseTypeUnionInternallyTagged(&JobResourceTypeUnion, "type")
  140. type JobResourceBase struct{}
  141. func (d *JobResourceBase) Noop() {}
  142. type CPU struct {
  143. serder.Metadata `union:"CPU"`
  144. JobResourceBase
  145. Type string `json:"type"`
  146. Name string `json:"name"`
  147. Number int64 `json:"number"`
  148. }
  149. type STORAGE struct {
  150. serder.Metadata `union:"STORAGE"`
  151. JobResourceBase
  152. Type string `json:"type"`
  153. Name string `json:"name"`
  154. Number int64 `json:"number"`
  155. }
  156. type GPU struct {
  157. serder.Metadata `union:"GPU"`
  158. JobResourceBase
  159. Type string `json:"type"`
  160. Name string `json:"name"`
  161. Number int64 `json:"number"`
  162. }
  163. type NPU struct {
  164. serder.Metadata `union:"NPU"`
  165. JobResourceBase
  166. Type string `json:"type"`
  167. Name string `json:"name"`
  168. Number int64 `json:"number"`
  169. }
  170. type MEMORY struct {
  171. serder.Metadata `union:"MEMORY"`
  172. JobResourceBase
  173. Type string `json:"type"`
  174. Name string `json:"name"`
  175. Number int64 `json:"number"`
  176. }
  177. type DCU struct {
  178. serder.Metadata `union:"DCU"`
  179. JobResourceBase
  180. Type string `json:"type"`
  181. Name string `json:"name"`
  182. Number int64 `json:"number"`
  183. }
  184. type MLU struct {
  185. serder.Metadata `union:"MLU"`
  186. JobResourceBase
  187. Type string `json:"type"`
  188. Name string `json:"name"`
  189. Number int64 `json:"number"`
  190. }
  191. type PRICE struct {
  192. serder.Metadata `union:"PRICE"`
  193. JobResourceBase
  194. Type string `json:"type"`
  195. Name string `json:"name"`
  196. Number int64 `json:"number"`
  197. }
  198. // FinetuningJobInfo 模型微调
  199. type FinetuningJobInfo struct {
  200. serder.Metadata `union:"Finetuning"`
  201. JobInfoBase
  202. Type string `json:"type"`
  203. Files JobFilesInfo `json:"files"`
  204. Runtime JobRuntimeInfo `json:"runtime"`
  205. Resources JobResourcesInfo `json:"resources"`
  206. Services JobServicesInfo `json:"services"`
  207. ModelJobInfo ModelJobInfo `json:"modelJobInfo"`
  208. }
  209. // DataPreprocessJobInfo 数据预处理
  210. type DataPreprocessJobInfo struct {
  211. serder.Metadata `union:"DataPreprocess"`
  212. JobInfoBase
  213. Type string `json:"type"`
  214. Files JobFilesInfo `json:"files"`
  215. Runtime JobRuntimeInfo `json:"runtime"`
  216. Resources JobResourcesInfo `json:"resources"`
  217. Services JobServicesInfo `json:"services"`
  218. }
  219. type DataReturnJobInfo struct {
  220. serder.Metadata `union:"DataReturn"`
  221. JobInfoBase
  222. Type string `json:"type"`
  223. BucketID cdssdk.BucketID `json:"bucketID"`
  224. BindingType string `json:"bindingType"`
  225. TargetLocalJobID string `json:"targetLocalJobID"`
  226. }
  227. // MultiInstanceJobInfo 多实例(推理任务)
  228. type MultiInstanceJobInfo struct {
  229. serder.Metadata `union:"MultiInstance"`
  230. JobInfoBase
  231. Type string `json:"type"`
  232. Files JobFilesInfo `json:"files"`
  233. Runtime JobRuntimeInfo `json:"runtime"`
  234. Resources JobResourcesInfo `json:"resources"`
  235. ModelJobInfo ModelJobInfo `json:"modelJobInfo"`
  236. }
  237. // UpdateMultiInstanceJobInfo 更新模型
  238. type UpdateMultiInstanceJobInfo struct {
  239. serder.Metadata `union:"UpdateModel"`
  240. JobInfoBase
  241. Type string `json:"type"`
  242. Files JobFilesInfo `json:"files"`
  243. Runtime JobRuntimeInfo `json:"runtime"`
  244. MultiInstanceJobSetID JobSetID `json:"multiInstanceJobSetID"`
  245. UpdateType string `json:"updateType"`
  246. SubJobs []JobID `json:"subJobs"`
  247. Operate string `json:"operate"`
  248. }
  249. type ModelJobInfo struct {
  250. Type string `json:"type"`
  251. ModelID ModelID `json:"modelID"`
  252. CustomModelName ModelName `json:"customModelName"`
  253. Command string `json:"command"`
  254. }
  255. // InstanceJobInfo 单实例(推理任务)
  256. type InstanceJobInfo struct {
  257. serder.Metadata `union:"Instance"`
  258. JobInfoBase
  259. Type string `json:"type"`
  260. LocalJobID string `json:"multiInstJobID"`
  261. Files JobFilesInfo `json:"files"`
  262. Runtime JobRuntimeInfo `json:"runtime"`
  263. Resources JobResourcesInfo `json:"resources"`
  264. ModelJobInfo ModelJobInfo `json:"modelJobInfo"`
  265. }
  266. type JobFilesInfo struct {
  267. Dataset JobFileInfo `json:"dataset"`
  268. Code JobFileInfo `json:"code"`
  269. Image JobFileInfo `json:"image"`
  270. Model JobFileInfo `json:"model"`
  271. }
  272. type JobFileInfo interface {
  273. Noop()
  274. }
  275. var FileInfoTypeUnion = types.NewTypeUnion[JobFileInfo](
  276. (*PackageJobFileInfo)(nil),
  277. (*LocalJobFileInfo)(nil),
  278. (*DataReturnJobFileInfo)(nil),
  279. (*ImageJobFileInfo)(nil),
  280. (*BindingJobFileInfo)(nil),
  281. )
  282. var _ = serder.UseTypeUnionInternallyTagged(&FileInfoTypeUnion, "type")
  283. type JobFileInfoBase struct{}
  284. func (i *JobFileInfoBase) Noop() {}
  285. type BindingJobFileInfo struct {
  286. serder.Metadata `union:"Binding"`
  287. JobFileInfoBase
  288. Type string `json:"type"`
  289. BindingID int64 `json:"bindingID"`
  290. }
  291. type PackageJobFileInfo struct {
  292. serder.Metadata `union:"Package"`
  293. JobFileInfoBase
  294. Type string `json:"type"`
  295. PackageID cdssdk.PackageID `json:"packageID"`
  296. }
  297. type LocalJobFileInfo struct {
  298. serder.Metadata `union:"LocalFile"`
  299. JobFileInfoBase
  300. Type string `json:"type"`
  301. LocalPath string `json:"localPath"`
  302. }
  303. type DataReturnJobFileInfo struct {
  304. serder.Metadata `union:"DataReturn"`
  305. JobFileInfoBase
  306. Type string `json:"type"`
  307. DataReturnLocalJobID string `json:"dataReturnLocalJobID"`
  308. }
  309. type ImageJobFileInfo struct {
  310. serder.Metadata `union:"Image"`
  311. JobFileInfoBase
  312. Type string `json:"type"`
  313. ImageID ImageID `json:"imageID"`
  314. }
  315. type JobRuntimeInfo struct {
  316. Command string `json:"command"`
  317. Envs []KVPair `json:"envs"`
  318. Params []KVPair `json:"params"`
  319. }
  320. type KVPair struct {
  321. Key string `json:"key"`
  322. Value string `json:"value"`
  323. }
  324. // CPU、GPU、NPU、MLU单位为:核
  325. // Storage、Memory单位为:字节
  326. type JobResourcesInfo struct {
  327. CPU float64 `json:"cpu"`
  328. GPU float64 `json:"gpu"`
  329. NPU float64 `json:"npu"`
  330. MLU float64 `json:"mlu"`
  331. Storage int64 `json:"storage"`
  332. Memory int64 `json:"memory"`
  333. }
  334. type JobSetFilesUploadScheme struct {
  335. LocalFileSchemes []LocalFileUploadScheme `json:"localFileUploadSchemes"`
  336. }
  337. type JobFilesUploadScheme struct {
  338. LocalFileSchemes []LocalFileUploadScheme `json:"localFileUploadSchemes"`
  339. }
  340. type LocalFileUploadScheme struct {
  341. LocalPath string `json:"localPath"`
  342. UploadToCDStorageID cdssdk.StorageID `json:"uploadToCDSStorageID"`
  343. }
  344. type JobServicesInfo struct {
  345. ServicePortInfos []ServicePortInfo `json:"servicePortInfos"`
  346. }
  347. type ServicePortInfo struct {
  348. Name string `json:"name"`
  349. Port int64 `json:"port"`
  350. }
  351. type JobSetServiceInfo struct {
  352. Name string `json:"name"`
  353. Port int64 `json:"port"`
  354. CDSStorageID cdssdk.StorageID `json:"cdsStorageID"`
  355. LocalJobID string `json:"localJobID"`
  356. }
  357. type Bootstrap interface {
  358. GetBootstrapType() string
  359. }
  360. type DirectBootstrap struct {
  361. serder.Metadata `union:"Direct"`
  362. Type string `json:"type"`
  363. }
  364. type NoEnvBootstrap struct {
  365. serder.Metadata `union:"NoEnv"`
  366. Type string `json:"type"`
  367. ScriptPackageID cdssdk.PackageID `json:"scriptPackageID"`
  368. ScriptFileName string `json:"scriptFileName"`
  369. }
  370. var BootstrapTypeUnion = types.NewTypeUnion[Bootstrap](
  371. (*DirectBootstrap)(nil),
  372. (*NoEnvBootstrap)(nil),
  373. )
  374. var _ = serder.UseTypeUnionInternallyTagged(&BootstrapTypeUnion, "type")
  375. func (b *DirectBootstrap) GetBootstrapType() string {
  376. return b.Type
  377. }
  378. func (b *NoEnvBootstrap) GetBootstrapType() string {
  379. return b.Type
  380. }
  381. const (
  382. JobDataInEnv = "SCH_DATA_IN"
  383. JobDataOutEnv = "SCH_DATA_OUT"
  384. FinetuningOutEnv = "FINETUNING_OUT"
  385. AccessPath = "ACCESS_PATH"
  386. )
  387. type Rclone struct {
  388. CDSRcloneID string `json:"cds_rcloneID"`
  389. CDSRcloneConfigID string `json:"cds_rcloneConfigID"`
  390. }
  391. type InferencePlatform struct {
  392. PlatformName string `json:"platformName"`
  393. ApiBaseUrl string `json:"apiBaseUrl"`
  394. ApiKey string `json:"apiKey"`
  395. ApiProxy string `json:"apiProxy"`
  396. LlmModel string `json:"llmModel"`
  397. EmbedModel string `json:"embedModel"`
  398. ChunkMaxLength string `json:"chunkMaxLength"`
  399. StartChunkThreshold string `json:"startChunkThreshold"`
  400. SimilarityThreshold string `json:"similarityThreshold"`
  401. EntriesPerFile string `json:"entriesPerFile"`
  402. }