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