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