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