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