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 4.4 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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. ResourcePools = "{\"resource_pool\":[{\"id\":\"pool1328035d\", \"value\":\"专属资源池\"}]}"
  22. Engines = "{\"engine\":[{\"id\":1, \"value\":\"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\":[{\"code\":\"modelarts.bm.910.arm.public.2\",\"value\":\"Ascend : 2 * Ascend 910 CPU:48 核 512GiB\"}," +
  29. "{\"code\":\"modelarts.bm.910.arm.public.8\",\"value\":\"Ascend : 8 * Ascend 910 CPU:192 核 2048GiB\"}," +
  30. "{\"code\":\"modelarts.bm.910.arm.public.4\",\"value\":\"Ascend : 4 * Ascend 910 CPU:96 核 1024GiB\"}," +
  31. "{\"code\":\"modelarts.bm.910.arm.public.1\",\"value\":\"Ascend : 1 * Ascend 910 CPU:24 核 256GiB\"}" +
  32. "]}"
  33. CodePath = "/code/"
  34. OutputPath = "/output/"
  35. LogPath = "/log/"
  36. JobPath = "/job/"
  37. )
  38. type GenerateTrainJobReq struct {
  39. JobName string
  40. Uuid string
  41. Description string
  42. CodeObsPath string
  43. BootFile string
  44. DataUrl string
  45. TrainUrl string
  46. FlavorCode string
  47. LogUrl string
  48. PoolID string
  49. WorkServerNumber int
  50. EngineID int64
  51. }
  52. type VersionInfo struct {
  53. Version []struct {
  54. ID int `json:"id"`
  55. Value string `json:"value"`
  56. } `json:"version"`
  57. }
  58. type Flavor struct {
  59. Info []struct {
  60. Code string `json:"code"`
  61. Value string `json:"value"`
  62. } `json:"flavor"`
  63. }
  64. type Engine struct {
  65. Info []struct {
  66. ID int `json:"id"`
  67. Value string `json:"value"`
  68. } `json:"engine"`
  69. }
  70. type ResourcePool struct {
  71. Info []struct {
  72. ID string `json:"id"`
  73. Value string `json:"value"`
  74. } `json:"resource_pool"`
  75. }
  76. func GenerateTask(ctx *context.Context, jobName, uuid, description string) error {
  77. dataActualPath := setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/"
  78. jobResult, err := createNotebook(models.CreateNotebookParams{
  79. JobName: jobName,
  80. Description:description,
  81. ProfileID: profileID,
  82. Flavor: flavor,
  83. Spec: models.Spec{
  84. Storage: models.Storage{
  85. Type: storageTypeOBS,
  86. Location:models.Location{
  87. Path: dataActualPath,
  88. },
  89. },
  90. AutoStop: models.AutoStop{
  91. Enable: true,
  92. Duration: autoStopDuration,
  93. },
  94. },
  95. })
  96. if err != nil {
  97. log.Error("CreateJob failed: %v", err.Error())
  98. return err
  99. }
  100. err = models.CreateCloudbrain(&models.Cloudbrain{
  101. Status: string(models.JobWaiting),
  102. UserID: ctx.User.ID,
  103. RepoID: ctx.Repo.Repository.ID,
  104. JobID: jobResult.ID,
  105. JobName: jobName,
  106. JobType: string(models.JobTypeDebug),
  107. Type: models.TypeCloudBrainNotebook,
  108. })
  109. if err != nil {
  110. return err
  111. }
  112. return nil
  113. }
  114. func GenerateTrainJob(ctx *context.Context, req *GenerateTrainJobReq) error {
  115. jobResult, err := createTrainJob(models.CreateTrainJobParams{
  116. JobName: req.JobName,
  117. Description: req.Description,
  118. Config: models.Config{
  119. WorkServerNum: req.WorkServerNumber,
  120. AppUrl: req.CodeObsPath,
  121. BootFileUrl: req.BootFile,
  122. DataUrl: req.DataUrl,
  123. EngineID: req.EngineID,
  124. TrainUrl: req.TrainUrl,
  125. LogUrl: req.LogUrl,
  126. PoolID: req.PoolID,
  127. Flavor: models.Flavor{
  128. Code: req.FlavorCode,
  129. },
  130. },
  131. })
  132. if err != nil {
  133. log.Error("CreateJob failed: %v", err.Error())
  134. return err
  135. }
  136. err = models.CreateCloudbrain(&models.Cloudbrain{
  137. Status: strconv.Itoa(jobResult.Status),
  138. UserID: ctx.User.ID,
  139. RepoID: ctx.Repo.Repository.ID,
  140. JobID: strconv.FormatInt(jobResult.JobID, 10),
  141. JobName: req.JobName,
  142. JobType: string(models.JobTypeDebug),
  143. Type: models.TypeCloudBrainTrainJob,
  144. })
  145. if err != nil {
  146. return err
  147. }
  148. return nil
  149. }