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.

cloudbrain.go 2.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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package cloudbrain
  2. import (
  3. "code.gitea.io/gitea/modules/setting"
  4. "errors"
  5. "code.gitea.io/gitea/models"
  6. "code.gitea.io/gitea/modules/context"
  7. "code.gitea.io/gitea/modules/log"
  8. )
  9. const (
  10. Command = `pip3 install jupyterlab==2.2.5 -i https://pypi.tuna.tsinghua.edu.cn/simple;service ssh stop;jupyter lab --no-browser --ip=0.0.0.0 --allow-root --notebook-dir="/code" --port=80 --LabApp.token="" --LabApp.allow_origin="self https://cloudbrain.pcl.ac.cn"`
  11. CodeMountPath = "/code"
  12. DataSetMountPath = "/dataset"
  13. ModelMountPath = "/model"
  14. BenchMarkMountPath = "/benchmark"
  15. TaskInfoName = "/taskInfo"
  16. SubTaskName = "task1"
  17. Success = "S000"
  18. )
  19. func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, jobType string) error {
  20. dataActualPath := setting.Attachment.Minio.RealPath +
  21. setting.Attachment.Minio.Bucket + "/" +
  22. setting.Attachment.Minio.BasePath +
  23. models.AttachmentRelativePath(uuid) +
  24. uuid
  25. jobResult, err := CreateJob(jobName, models.CreateJobParams{
  26. JobName: jobName,
  27. RetryCount: 1,
  28. GpuType: setting.JobType,
  29. Image: image,
  30. TaskRoles: []models.TaskRole{
  31. {
  32. Name: SubTaskName,
  33. TaskNumber: 1,
  34. MinSucceededTaskCount: 1,
  35. MinFailedTaskCount: 1,
  36. CPUNumber: 2,
  37. GPUNumber: 1,
  38. MemoryMB: 16384,
  39. ShmMB: 8192,
  40. Command: command,
  41. NeedIBDevice: false,
  42. IsMainRole: false,
  43. UseNNI: false,
  44. },
  45. },
  46. Volumes: []models.Volume{
  47. {
  48. HostPath: models.StHostPath{
  49. Path: codePath,
  50. MountPath: CodeMountPath,
  51. ReadOnly: false,
  52. },
  53. },
  54. {
  55. HostPath: models.StHostPath{
  56. Path: dataActualPath,
  57. MountPath: DataSetMountPath,
  58. ReadOnly: true,
  59. },
  60. },
  61. {
  62. HostPath: models.StHostPath{
  63. Path: modelPath,
  64. MountPath: ModelMountPath,
  65. ReadOnly: false,
  66. },
  67. },
  68. {
  69. HostPath: models.StHostPath{
  70. Path: benchmarkPath,
  71. MountPath: BenchMarkMountPath,
  72. ReadOnly: true,
  73. },
  74. },
  75. },
  76. })
  77. if err != nil {
  78. log.Error("CreateJob failed:", err.Error())
  79. return err
  80. }
  81. if jobResult.Code != Success {
  82. log.Error("CreateJob(%s) failed:%s", jobName, jobResult.Msg)
  83. return errors.New(jobResult.Msg)
  84. }
  85. var jobID = jobResult.Payload["jobId"].(string)
  86. err = models.CreateCloudbrain(&models.Cloudbrain{
  87. Status: string(models.JobWaiting),
  88. UserID: ctx.User.ID,
  89. RepoID: ctx.Repo.Repository.ID,
  90. JobID: jobID,
  91. JobName: jobName,
  92. SubTaskName: SubTaskName,
  93. JobType: jobType,
  94. })
  95. if err != nil {
  96. return err
  97. }
  98. return nil
  99. }