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