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

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