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