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