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 3.7 kB

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
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package modelarts
  2. import (
  3. "path"
  4. "strconv"
  5. "code.gitea.io/gitea/models"
  6. "code.gitea.io/gitea/modules/context"
  7. "code.gitea.io/gitea/modules/log"
  8. "code.gitea.io/gitea/modules/setting"
  9. )
  10. const (
  11. //notebook
  12. storageTypeOBS = "obs"
  13. autoStopDuration = 4 * 60 * 60
  14. flavor = "modelarts.kat1.xlarge"
  15. profileID = "Python3-ascend910-arm"
  16. DataSetMountPath = "/home/ma-user/work"
  17. NotebookEnv = "Python3"
  18. NotebookType = "Ascend"
  19. FlavorInfo = "Ascend: 1*Ascend 910 CPU: 24 核 96GiB (modelarts.kat1.xlarge)"
  20. //train-job
  21. engineID = 118
  22. Engine = "Ascend-Powered-Engine"
  23. EngineVersions = "{\"version\":[{\"id\":118,\"value\":\"MindSpore-1.0.0-c75-python3.7-euleros2.8-aarch64\"}," +
  24. "{\"id\":119,\"value\":\"MindSpore-1.1.1-c76-python3.7-euleros2.8-aarch64\"}" +
  25. "{\"id\":120,\"value\":\"MindSpore-1.1.1-c76-tr5-python3.7-euleros2.8-aarch64\"}" +
  26. "{\"id\":117,\"value\":\"TF-1.15-c75-python3.7-euleros2.8-aarch64\"}" +
  27. "]}"
  28. FlavorInfos = "{\"flavor\":[{\"id\":1,\"value\":\"Ascend : 2 * Ascend 910 CPU:48 核 512GiB\"}," +
  29. "{\"id\":2,\"value\":\"Ascend : 8 * Ascend 910 CPU:192 核 2048GiB\"}" +
  30. "{\"id\":3,\"value\":\"Ascend : 4 * Ascend 910 CPU:96 核 1024GiB\"}" +
  31. "{\"id\":4,\"value\":\"Ascend : 1 * Ascend 910 CPU:24 核 256GiB\"}" +
  32. "]}"
  33. CodePath = "/code/"
  34. OutputPath = "/output/"
  35. JobPath = "/job/"
  36. )
  37. type GenerateTrainJobReq struct {
  38. JobName string
  39. Uuid string
  40. Description string
  41. CodeObsPath string
  42. BootFile string
  43. DataUrl string
  44. TrainUrl string
  45. WorkServerNumber int
  46. EngineID int64
  47. }
  48. type VersionInfo struct {
  49. Version []struct {
  50. ID int `json:"id"`
  51. Value string `json:"value"`
  52. } `json:"version"`
  53. }
  54. type Flavor struct {
  55. Info []struct {
  56. ID int `json:"id"`
  57. Value string `json:"value"`
  58. } `json:"flavor"`
  59. }
  60. func GenerateTask(ctx *context.Context, jobName, uuid, description string) error {
  61. dataActualPath := setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/"
  62. jobResult, err := createNotebook(models.CreateNotebookParams{
  63. JobName: jobName,
  64. Description:description,
  65. ProfileID: profileID,
  66. Flavor: flavor,
  67. Spec: models.Spec{
  68. Storage: models.Storage{
  69. Type: storageTypeOBS,
  70. Location:models.Location{
  71. Path: dataActualPath,
  72. },
  73. },
  74. AutoStop: models.AutoStop{
  75. Enable: true,
  76. Duration: autoStopDuration,
  77. },
  78. },
  79. })
  80. if err != nil {
  81. log.Error("CreateJob failed: %v", err.Error())
  82. return err
  83. }
  84. err = models.CreateCloudbrain(&models.Cloudbrain{
  85. Status: string(models.JobWaiting),
  86. UserID: ctx.User.ID,
  87. RepoID: ctx.Repo.Repository.ID,
  88. JobID: jobResult.ID,
  89. JobName: jobName,
  90. JobType: string(models.JobTypeDebug),
  91. Type: models.TypeCloudBrainNotebook,
  92. })
  93. if err != nil {
  94. return err
  95. }
  96. return nil
  97. }
  98. func GenerateTrainJob(ctx *context.Context, req *GenerateTrainJobReq) error {
  99. jobResult, err := createTrainJob(models.CreateTrainJobParams{
  100. JobName: req.JobName,
  101. Description: req.Description,
  102. Config: models.Config{
  103. WorkServerNum: req.WorkServerNumber,
  104. AppUrl: req.CodeObsPath,
  105. BootFileUrl: req.CodeObsPath + req.BootFile,
  106. DataUrl: req.DataUrl,
  107. EngineID: req.EngineID,
  108. TrainUrl: req.TrainUrl,
  109. },
  110. })
  111. if err != nil {
  112. log.Error("CreateJob failed: %v", err.Error())
  113. return err
  114. }
  115. err = models.CreateCloudbrain(&models.Cloudbrain{
  116. Status: strconv.Itoa(jobResult.Status),
  117. UserID: ctx.User.ID,
  118. RepoID: ctx.Repo.Repository.ID,
  119. JobID: strconv.FormatInt(jobResult.JobID, 10),
  120. JobName: req.JobName,
  121. JobType: string(models.JobTypeDebug),
  122. Type: models.TypeCloudBrainTrainJob,
  123. })
  124. if err != nil {
  125. return err
  126. }
  127. return nil
  128. }