You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

modelarts.go 18 kB

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