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