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.

modelarts.go 18 kB

4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. package modelarts
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "path"
  7. "strconv"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/context"
  10. "code.gitea.io/gitea/modules/log"
  11. "code.gitea.io/gitea/modules/notification"
  12. "code.gitea.io/gitea/modules/setting"
  13. "code.gitea.io/gitea/modules/storage"
  14. )
  15. const (
  16. //notebook
  17. storageTypeOBS = "obs"
  18. autoStopDuration = 4 * 60 * 60
  19. autoStopDurationMs = 4 * 60 * 60 * 1000
  20. DataSetMountPath = "/home/ma-user/work"
  21. NotebookEnv = "Python3"
  22. NotebookType = "Ascend"
  23. FlavorInfo = "Ascend: 1*Ascend 910 CPU: 24 核 96GiB (modelarts.kat1.xlarge)"
  24. //train-job
  25. // ResourcePools = "{\"resource_pool\":[{\"id\":\"pool1328035d\", \"value\":\"专属资源池\"}]}"
  26. // Engines = "{\"engine\":[{\"id\":1, \"value\":\"Ascend-Powered-Engine\"}]}"
  27. // EngineVersions = "{\"version\":[{\"id\":118,\"value\":\"MindSpore-1.0.0-c75-python3.7-euleros2.8-aarch64\"}," +
  28. // "{\"id\":119,\"value\":\"MindSpore-1.1.1-c76-python3.7-euleros2.8-aarch64\"}," +
  29. // "{\"id\":120,\"value\":\"MindSpore-1.1.1-c76-tr5-python3.7-euleros2.8-aarch64\"}," +
  30. // "{\"id\":117,\"value\":\"TF-1.15-c75-python3.7-euleros2.8-aarch64\"}" +
  31. // "]}"
  32. // TrainJobFlavorInfo = "{\"flavor\":[{\"code\":\"modelarts.bm.910.arm.public.2\",\"value\":\"Ascend : 2 * Ascend 910 CPU:48 核 512GiB\"}," +
  33. // "{\"code\":\"modelarts.bm.910.arm.public.8\",\"value\":\"Ascend : 8 * Ascend 910 CPU:192 核 2048GiB\"}," +
  34. // "{\"code\":\"modelarts.bm.910.arm.public.4\",\"value\":\"Ascend : 4 * Ascend 910 CPU:96 核 1024GiB\"}," +
  35. // "{\"code\":\"modelarts.bm.910.arm.public.1\",\"value\":\"Ascend : 1 * Ascend 910 CPU:24 核 256GiB\"}" +
  36. // "]}"
  37. CodePath = "/code/"
  38. OutputPath = "/output/"
  39. ResultPath = "/result/"
  40. LogPath = "/log/"
  41. JobPath = "/job/"
  42. OrderDesc = "desc" //向下查询
  43. OrderAsc = "asc" //向上查询
  44. Lines = 500
  45. TrainUrl = "train_url"
  46. DataUrl = "data_url"
  47. ResultUrl = "result_url"
  48. CkptUrl = "ckpt_url"
  49. DeviceTarget = "device_target"
  50. Ascend = "Ascend"
  51. PerPage = 10
  52. IsLatestVersion = "1"
  53. NotLatestVersion = "0"
  54. DebugType = -1
  55. VersionCount = 1
  56. SortByCreateTime = "create_time"
  57. ConfigTypeCustom = "custom"
  58. TotalVersionCount = 1
  59. )
  60. var (
  61. poolInfos *models.PoolInfos
  62. FlavorInfos *models.FlavorInfos
  63. ImageInfos *models.ImageInfosModelArts
  64. )
  65. type GenerateTrainJobReq struct {
  66. JobName string
  67. DisplayJobName string
  68. Uuid string
  69. Description string
  70. CodeObsPath string
  71. BootFile string
  72. BootFileUrl string
  73. DataUrl string
  74. TrainUrl string
  75. FlavorCode string
  76. LogUrl string
  77. PoolID string
  78. WorkServerNumber int
  79. EngineID int64
  80. Parameters []models.Parameter
  81. CommitID string
  82. IsLatestVersion string
  83. Params string
  84. BranchName string
  85. PreVersionId int64
  86. PreVersionName string
  87. FlavorName string
  88. VersionCount int
  89. EngineName string
  90. TotalVersionCount int
  91. }
  92. type GenerateInferenceJobReq struct {
  93. JobName string
  94. DisplayJobName string
  95. Uuid string
  96. Description string
  97. CodeObsPath string
  98. BootFile string
  99. BootFileUrl string
  100. DataUrl string
  101. TrainUrl string
  102. FlavorCode string
  103. LogUrl string
  104. PoolID string
  105. WorkServerNumber int
  106. EngineID int64
  107. Parameters []models.Parameter
  108. CommitID string
  109. Params string
  110. BranchName string
  111. FlavorName string
  112. EngineName string
  113. LabelName string
  114. IsLatestVersion string
  115. VersionCount int
  116. TotalVersionCount int
  117. ModelName string
  118. ModelVersion string
  119. CkptName string
  120. ResultUrl string
  121. }
  122. type VersionInfo struct {
  123. Version []struct {
  124. ID int `json:"id"`
  125. Value string `json:"value"`
  126. } `json:"version"`
  127. }
  128. type Flavor struct {
  129. Info []struct {
  130. Code string `json:"code"`
  131. Value string `json:"value"`
  132. } `json:"flavor"`
  133. }
  134. type Engine struct {
  135. Info []struct {
  136. ID int `json:"id"`
  137. Value string `json:"value"`
  138. } `json:"engine"`
  139. }
  140. type ResourcePool struct {
  141. Info []struct {
  142. ID string `json:"id"`
  143. Value string `json:"value"`
  144. } `json:"resource_pool"`
  145. }
  146. // type Parameter struct {
  147. // Label string `json:"label"`
  148. // Value string `json:"value"`
  149. // }
  150. // type Parameters struct {
  151. // Parameter []Parameter `json:"parameter"`
  152. // }
  153. type Parameters struct {
  154. Parameter []struct {
  155. Label string `json:"label"`
  156. Value string `json:"value"`
  157. } `json:"parameter"`
  158. }
  159. func GenerateTask(ctx *context.Context, jobName, uuid, description, flavor string) error {
  160. var dataActualPath string
  161. if uuid != "" {
  162. dataActualPath = setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/"
  163. } else {
  164. userPath := setting.UserBasePath + ctx.User.Name + "/"
  165. isExist, err := storage.ObsHasObject(userPath)
  166. if err != nil {
  167. log.Error("ObsHasObject failed:%v", err.Error(), ctx.Data["MsgID"])
  168. return err
  169. }
  170. if !isExist {
  171. if err = storage.ObsCreateObject(userPath); err != nil {
  172. log.Error("ObsCreateObject failed:%v", err.Error(), ctx.Data["MsgID"])
  173. return err
  174. }
  175. }
  176. dataActualPath = setting.Bucket + "/" + userPath
  177. }
  178. if poolInfos == nil {
  179. json.Unmarshal([]byte(setting.PoolInfos), &poolInfos)
  180. }
  181. jobResult, err := CreateJob(models.CreateNotebookParams{
  182. JobName: jobName,
  183. Description: description,
  184. ProfileID: setting.ProfileID,
  185. Flavor: flavor,
  186. Pool: models.Pool{
  187. ID: poolInfos.PoolInfo[0].PoolId,
  188. Name: poolInfos.PoolInfo[0].PoolName,
  189. Type: poolInfos.PoolInfo[0].PoolType,
  190. },
  191. Spec: models.Spec{
  192. Storage: models.Storage{
  193. Type: storageTypeOBS,
  194. Location: models.Location{
  195. Path: dataActualPath,
  196. },
  197. },
  198. AutoStop: models.AutoStop{
  199. Enable: true,
  200. Duration: autoStopDuration,
  201. },
  202. },
  203. })
  204. if err != nil {
  205. log.Error("CreateJob failed: %v", err.Error())
  206. return err
  207. }
  208. err = models.CreateCloudbrain(&models.Cloudbrain{
  209. Status: string(models.JobWaiting),
  210. UserID: ctx.User.ID,
  211. RepoID: ctx.Repo.Repository.ID,
  212. JobID: jobResult.ID,
  213. JobName: jobName,
  214. JobType: string(models.JobTypeDebug),
  215. Type: models.TypeCloudBrainTwo,
  216. Uuid: uuid,
  217. ComputeResource: models.NPUResource,
  218. })
  219. if err != nil {
  220. return err
  221. }
  222. notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, jobResult.ID, jobName, models.ActionCreateDebugNPUTask)
  223. return nil
  224. }
  225. func GenerateNotebook2(ctx *context.Context, displayJobName, jobName, uuid, description, flavor, imageId string) error {
  226. if poolInfos == nil {
  227. json.Unmarshal([]byte(setting.PoolInfos), &poolInfos)
  228. }
  229. imageName, err := GetNotebookImageName(imageId)
  230. if err != nil {
  231. log.Error("GetNotebookImageName failed: %v", err.Error())
  232. return err
  233. }
  234. jobResult, err := createNotebook2(models.CreateNotebook2Params{
  235. JobName: jobName,
  236. Description: description,
  237. Flavor: flavor,
  238. Duration: autoStopDurationMs,
  239. ImageID: imageId,
  240. PoolID: poolInfos.PoolInfo[0].PoolId,
  241. Feature: models.NotebookFeature,
  242. Volume: models.VolumeReq{
  243. Capacity: setting.Capacity,
  244. Category: models.EVSCategory,
  245. Ownership: models.ManagedOwnership,
  246. },
  247. WorkspaceID: "0",
  248. })
  249. if err != nil {
  250. log.Error("createNotebook2 failed: %v", err.Error())
  251. return err
  252. }
  253. err = models.CreateCloudbrain(&models.Cloudbrain{
  254. Status: jobResult.Status,
  255. UserID: ctx.User.ID,
  256. RepoID: ctx.Repo.Repository.ID,
  257. JobID: jobResult.ID,
  258. JobName: jobName,
  259. DisplayJobName: displayJobName,
  260. JobType: string(models.JobTypeDebug),
  261. Type: models.TypeCloudBrainTwo,
  262. Uuid: uuid,
  263. ComputeResource: models.NPUResource,
  264. Image: imageName,
  265. Description: description,
  266. })
  267. if err != nil {
  268. return err
  269. }
  270. task, err := models.GetCloudbrainByName(jobName)
  271. if err != nil {
  272. log.Error("GetCloudbrainByName failed: %v", err.Error())
  273. return err
  274. }
  275. stringId := strconv.FormatInt(task.ID, 10)
  276. notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, stringId, displayJobName, models.ActionCreateDebugNPUTask)
  277. return nil
  278. }
  279. func GenerateTrainJob(ctx *context.Context, req *GenerateTrainJobReq) (err error) {
  280. jobResult, err := createTrainJob(models.CreateTrainJobParams{
  281. JobName: req.JobName,
  282. Description: req.Description,
  283. Config: models.Config{
  284. WorkServerNum: req.WorkServerNumber,
  285. AppUrl: req.CodeObsPath,
  286. BootFileUrl: req.BootFileUrl,
  287. DataUrl: req.DataUrl,
  288. EngineID: req.EngineID,
  289. TrainUrl: req.TrainUrl,
  290. LogUrl: req.LogUrl,
  291. PoolID: req.PoolID,
  292. CreateVersion: true,
  293. Flavor: models.Flavor{
  294. Code: req.FlavorCode,
  295. },
  296. Parameter: req.Parameters,
  297. },
  298. })
  299. if err != nil {
  300. log.Error("CreateJob failed: %v", err.Error())
  301. return err
  302. }
  303. attach, err := models.GetAttachmentByUUID(req.Uuid)
  304. if err != nil {
  305. log.Error("GetAttachmentByUUID(%s) failed:%v", strconv.FormatInt(jobResult.JobID, 10), err.Error())
  306. return err
  307. }
  308. jobId := strconv.FormatInt(jobResult.JobID, 10)
  309. err = models.CreateCloudbrain(&models.Cloudbrain{
  310. Status: TransTrainJobStatus(jobResult.Status),
  311. UserID: ctx.User.ID,
  312. RepoID: ctx.Repo.Repository.ID,
  313. JobID: jobId,
  314. JobName: req.JobName,
  315. DisplayJobName: req.DisplayJobName,
  316. JobType: string(models.JobTypeTrain),
  317. Type: models.TypeCloudBrainTwo,
  318. VersionID: jobResult.VersionID,
  319. VersionName: jobResult.VersionName,
  320. Uuid: req.Uuid,
  321. DatasetName: attach.Name,
  322. CommitID: req.CommitID,
  323. IsLatestVersion: req.IsLatestVersion,
  324. ComputeResource: models.NPUResource,
  325. EngineID: req.EngineID,
  326. TrainUrl: req.TrainUrl,
  327. BranchName: req.BranchName,
  328. Parameters: req.Params,
  329. BootFile: req.BootFile,
  330. DataUrl: req.DataUrl,
  331. LogUrl: req.LogUrl,
  332. FlavorCode: req.FlavorCode,
  333. Description: req.Description,
  334. WorkServerNumber: req.WorkServerNumber,
  335. FlavorName: req.FlavorName,
  336. EngineName: req.EngineName,
  337. VersionCount: req.VersionCount,
  338. TotalVersionCount: req.TotalVersionCount,
  339. })
  340. if err != nil {
  341. log.Error("CreateCloudbrain(%s) failed:%v", req.DisplayJobName, err.Error())
  342. return err
  343. }
  344. notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, jobId, req.DisplayJobName, models.ActionCreateTrainTask)
  345. return nil
  346. }
  347. func GenerateTrainJobVersion(ctx *context.Context, req *GenerateTrainJobReq, jobId string) (err error) {
  348. jobResult, err := createTrainJobVersion(models.CreateTrainJobVersionParams{
  349. Description: req.Description,
  350. Config: models.TrainJobVersionConfig{
  351. WorkServerNum: req.WorkServerNumber,
  352. AppUrl: req.CodeObsPath,
  353. BootFileUrl: req.BootFileUrl,
  354. DataUrl: req.DataUrl,
  355. EngineID: req.EngineID,
  356. TrainUrl: req.TrainUrl,
  357. LogUrl: req.LogUrl,
  358. PoolID: req.PoolID,
  359. Flavor: models.Flavor{
  360. Code: req.FlavorCode,
  361. },
  362. Parameter: req.Parameters,
  363. PreVersionId: req.PreVersionId,
  364. },
  365. }, jobId)
  366. if err != nil {
  367. log.Error("CreateJob failed: %v", err.Error())
  368. return err
  369. }
  370. attach, err := models.GetAttachmentByUUID(req.Uuid)
  371. if err != nil {
  372. log.Error("GetAttachmentByUUID(%s) failed:%v", strconv.FormatInt(jobResult.JobID, 10), err.Error())
  373. return err
  374. }
  375. var jobTypes []string
  376. jobTypes = append(jobTypes, string(models.JobTypeTrain))
  377. repo := ctx.Repo.Repository
  378. VersionTaskList, VersionListCount, err := models.CloudbrainsVersionList(&models.CloudbrainsOptions{
  379. RepoID: repo.ID,
  380. Type: models.TypeCloudBrainTwo,
  381. JobTypes: jobTypes,
  382. JobID: strconv.FormatInt(jobResult.JobID, 10),
  383. })
  384. if err != nil {
  385. ctx.ServerError("Cloudbrain", err)
  386. return err
  387. }
  388. //将当前版本的isLatestVersion设置为"1"和任务数量更新,任务数量包括当前版本数VersionCount和历史创建的总版本数TotalVersionCount
  389. err = models.CreateCloudbrain(&models.Cloudbrain{
  390. Status: TransTrainJobStatus(jobResult.Status),
  391. UserID: ctx.User.ID,
  392. RepoID: ctx.Repo.Repository.ID,
  393. JobID: strconv.FormatInt(jobResult.JobID, 10),
  394. JobName: req.JobName,
  395. DisplayJobName: req.DisplayJobName,
  396. JobType: string(models.JobTypeTrain),
  397. Type: models.TypeCloudBrainTwo,
  398. VersionID: jobResult.VersionID,
  399. VersionName: jobResult.VersionName,
  400. Uuid: req.Uuid,
  401. DatasetName: attach.Name,
  402. CommitID: req.CommitID,
  403. IsLatestVersion: req.IsLatestVersion,
  404. PreVersionName: req.PreVersionName,
  405. ComputeResource: models.NPUResource,
  406. EngineID: req.EngineID,
  407. TrainUrl: req.TrainUrl,
  408. BranchName: req.BranchName,
  409. Parameters: req.Params,
  410. BootFile: req.BootFile,
  411. DataUrl: req.DataUrl,
  412. LogUrl: req.LogUrl,
  413. PreVersionId: req.PreVersionId,
  414. FlavorCode: req.FlavorCode,
  415. Description: req.Description,
  416. WorkServerNumber: req.WorkServerNumber,
  417. FlavorName: req.FlavorName,
  418. EngineName: req.EngineName,
  419. TotalVersionCount: VersionTaskList[0].TotalVersionCount + 1,
  420. VersionCount: VersionListCount + 1,
  421. })
  422. if err != nil {
  423. log.Error("CreateCloudbrain(%s) failed:%v", req.JobName, err.Error())
  424. return err
  425. }
  426. //将训练任务的上一版本的isLatestVersion设置为"0"
  427. err = models.SetVersionCountAndLatestVersion(strconv.FormatInt(jobResult.JobID, 10), VersionTaskList[0].VersionName, VersionCount, NotLatestVersion, TotalVersionCount)
  428. if err != nil {
  429. ctx.ServerError("Update IsLatestVersion failed", err)
  430. return err
  431. }
  432. return err
  433. }
  434. func TransTrainJobStatus(status int) string {
  435. switch status {
  436. case 0:
  437. return "UNKNOWN"
  438. case 1:
  439. return "INIT"
  440. case 2:
  441. return "IMAGE_CREATING"
  442. case 3:
  443. return "IMAGE_FAILED"
  444. case 4:
  445. return "SUBMIT_TRYING"
  446. case 5:
  447. return "SUBMIT_FAILED"
  448. case 6:
  449. return "DELETE_FAILED"
  450. case 7:
  451. return "WAITING"
  452. case 8:
  453. return "RUNNING"
  454. case 9:
  455. return "KILLING"
  456. case 10:
  457. return "COMPLETED"
  458. case 11:
  459. return "FAILED"
  460. case 12:
  461. return "KILLED"
  462. case 13:
  463. return "CANCELED"
  464. case 14:
  465. return "LOST"
  466. case 15:
  467. return "SCALING"
  468. case 16:
  469. return "SUBMIT_MODEL_FAILED"
  470. case 17:
  471. return "DEPLOY_SERVICE_FAILED"
  472. case 18:
  473. return "CHECK_INIT"
  474. case 19:
  475. return "CHECK_RUNNING"
  476. case 20:
  477. return "CHECK_RUNNING_COMPLETED"
  478. case 21:
  479. return "CHECK_FAILED"
  480. default:
  481. return strconv.Itoa(status)
  482. }
  483. }
  484. func GetOutputPathByCount(TotalVersionCount int) (VersionOutputPath string) {
  485. talVersionCountToString := fmt.Sprintf("%04d", TotalVersionCount)
  486. VersionOutputPath = "V" + talVersionCountToString
  487. return VersionOutputPath
  488. }
  489. func GenerateInferenceJob(ctx *context.Context, req *GenerateInferenceJobReq) (err error) {
  490. jobResult, err := createInferenceJob(models.CreateInferenceJobParams{
  491. JobName: req.JobName,
  492. Description: req.Description,
  493. InfConfig: models.InfConfig{
  494. WorkServerNum: req.WorkServerNumber,
  495. AppUrl: req.CodeObsPath,
  496. BootFileUrl: req.BootFileUrl,
  497. DataUrl: req.DataUrl,
  498. EngineID: req.EngineID,
  499. // TrainUrl: req.TrainUrl,
  500. LogUrl: req.LogUrl,
  501. PoolID: req.PoolID,
  502. CreateVersion: true,
  503. Flavor: models.Flavor{
  504. Code: req.FlavorCode,
  505. },
  506. Parameter: req.Parameters,
  507. },
  508. })
  509. if err != nil {
  510. log.Error("CreateJob failed: %v", err.Error())
  511. return err
  512. }
  513. attach, err := models.GetAttachmentByUUID(req.Uuid)
  514. if err != nil {
  515. log.Error("GetAttachmentByUUID(%s) failed:%v", strconv.FormatInt(jobResult.JobID, 10), err.Error())
  516. return err
  517. }
  518. jobID := strconv.FormatInt(jobResult.JobID, 10)
  519. err = models.CreateCloudbrain(&models.Cloudbrain{
  520. Status: TransTrainJobStatus(jobResult.Status),
  521. UserID: ctx.User.ID,
  522. RepoID: ctx.Repo.Repository.ID,
  523. JobID: jobID,
  524. JobName: req.JobName,
  525. DisplayJobName: req.DisplayJobName,
  526. JobType: string(models.JobTypeInference),
  527. Type: models.TypeCloudBrainTwo,
  528. VersionID: jobResult.VersionID,
  529. VersionName: jobResult.VersionName,
  530. Uuid: req.Uuid,
  531. DatasetName: attach.Name,
  532. CommitID: req.CommitID,
  533. EngineID: req.EngineID,
  534. TrainUrl: req.TrainUrl,
  535. BranchName: req.BranchName,
  536. Parameters: req.Params,
  537. BootFile: req.BootFile,
  538. DataUrl: req.DataUrl,
  539. LogUrl: req.LogUrl,
  540. FlavorCode: req.FlavorCode,
  541. Description: req.Description,
  542. WorkServerNumber: req.WorkServerNumber,
  543. FlavorName: req.FlavorName,
  544. EngineName: req.EngineName,
  545. LabelName: req.LabelName,
  546. IsLatestVersion: req.IsLatestVersion,
  547. ComputeResource: models.NPUResource,
  548. VersionCount: req.VersionCount,
  549. TotalVersionCount: req.TotalVersionCount,
  550. ModelName: req.ModelName,
  551. ModelVersion: req.ModelVersion,
  552. CkptName: req.CkptName,
  553. ResultUrl: req.ResultUrl,
  554. })
  555. if err != nil {
  556. log.Error("CreateCloudbrain(%s) failed:%v", req.JobName, err.Error())
  557. return err
  558. }
  559. notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, jobID, req.DisplayJobName, models.ActionCreateInferenceTask)
  560. return nil
  561. }
  562. func GetNotebookImageName(imageId string) (string, error) {
  563. var validImage = false
  564. var imageName = ""
  565. if ImageInfos == nil {
  566. json.Unmarshal([]byte(setting.ImageInfos), &ImageInfos)
  567. }
  568. for _, imageInfo := range ImageInfos.ImageInfo {
  569. if imageInfo.Id == imageId {
  570. validImage = true
  571. imageName = imageInfo.Value
  572. }
  573. }
  574. if !validImage {
  575. log.Error("the image id(%s) is invalid", imageId)
  576. return imageName, errors.New("the image id is invalid")
  577. }
  578. return imageName, nil
  579. }