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.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. Copyright (c) [2023] [pcm]
  3. [pcm-coordinator] is licensed under Mulan PSL v2.
  4. You can use this software according to the terms and conditions of the Mulan PSL v2.
  5. You may obtain a copy of Mulan PSL v2 at:
  6. http://license.coscl.org.cn/MulanPSL2
  7. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  8. EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  9. MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  10. See the Mulan PSL v2 for more details.
  11. */
  12. package storeLink
  13. import (
  14. "context"
  15. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/schedulers/option"
  16. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/collector"
  17. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
  18. "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
  19. "gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/modelarts"
  20. "strconv"
  21. "strings"
  22. )
  23. type ModelArtsLink struct {
  24. ctx context.Context
  25. svcCtx *svc.ServiceContext
  26. platform string
  27. participantId int64
  28. pageIndex int32
  29. pageSize int32
  30. }
  31. func NewModelArtsLink(ctx context.Context, svcCtx *svc.ServiceContext, name string, id int64) *ModelArtsLink {
  32. return &ModelArtsLink{ctx: ctx, svcCtx: svcCtx, platform: name, participantId: id, pageIndex: 1, pageSize: 100}
  33. }
  34. func (o *ModelArtsLink) UploadImage(path string) (interface{}, error) {
  35. //TODO modelArts上传镜像
  36. return nil, nil
  37. }
  38. func (o *ModelArtsLink) DeleteImage(imageId string) (interface{}, error) {
  39. // TODO modelArts删除镜像
  40. return nil, nil
  41. }
  42. func (o *ModelArtsLink) QueryImageList() (interface{}, error) {
  43. // modelArts获取镜像列表
  44. req := &modelarts.ListRepoReq{
  45. Offset: "0",
  46. Limit: strconv.Itoa(int(o.pageSize)),
  47. Platform: o.platform,
  48. }
  49. resp, err := o.svcCtx.ModelArtsImgRpc.ListReposDetails(o.ctx, req)
  50. if err != nil {
  51. return nil, err
  52. }
  53. return resp, nil
  54. }
  55. func (o *ModelArtsLink) SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (interface{}, error) {
  56. // modelArts提交任务
  57. environments := make(map[string]string)
  58. parameters := make([]*modelarts.ParametersTrainJob, 0)
  59. for _, env := range envs {
  60. s := strings.Split(env, COMMA)
  61. environments[s[0]] = s[1]
  62. }
  63. for _, param := range params {
  64. s := strings.Split(param, COMMA)
  65. parameters = append(parameters, &modelarts.ParametersTrainJob{
  66. Name: s[0],
  67. Value: s[1],
  68. })
  69. }
  70. req := &modelarts.CreateTrainingJobReq{
  71. Kind: "job",
  72. Metadata: &modelarts.MetadataS{
  73. Name: TASK_NAME_PREFIX + utils.RandomString(10),
  74. WorkspaceId: "0",
  75. },
  76. Algorithm: &modelarts.Algorithms{
  77. Engine: &modelarts.EngineCreateTraining{
  78. ImageUrl: imageId,
  79. },
  80. Command: cmd,
  81. Environments: environments,
  82. Parameters: parameters,
  83. },
  84. Spec: &modelarts.SpecsC{
  85. Resource: &modelarts.ResourceCreateTraining{
  86. FlavorId: resourceId,
  87. NodeCount: 1,
  88. },
  89. },
  90. Platform: o.platform,
  91. }
  92. resp, err := o.svcCtx.ModelArtsRpc.CreateTrainingJob(o.ctx, req)
  93. if err != nil {
  94. return nil, err
  95. }
  96. return resp, nil
  97. }
  98. func (o *ModelArtsLink) QueryTask(taskId string) (interface{}, error) {
  99. // 获取任务
  100. req := &modelarts.DetailTrainingJobsReq{
  101. TrainingJobId: taskId,
  102. Platform: o.platform,
  103. }
  104. resp, err := o.svcCtx.ModelArtsRpc.GetTrainingJobs(o.ctx, req)
  105. if err != nil {
  106. return nil, err
  107. }
  108. return resp, nil
  109. }
  110. func (o *ModelArtsLink) DeleteTask(taskId string) (interface{}, error) {
  111. // 删除任务
  112. req := &modelarts.DeleteTrainingJobReq{
  113. TrainingJobId: taskId,
  114. Platform: o.platform,
  115. }
  116. resp, err := o.svcCtx.ModelArtsRpc.DeleteTrainingJob(o.ctx, req)
  117. if err != nil {
  118. return nil, err
  119. }
  120. return resp, nil
  121. }
  122. func (o *ModelArtsLink) QuerySpecs() (interface{}, error) {
  123. // octopus查询资源规格
  124. req := &modelarts.TrainingJobFlavorsReq{
  125. Platform: o.platform,
  126. }
  127. resp, err := o.svcCtx.ModelArtsRpc.GetTrainingJobFlavors(o.ctx, req)
  128. if err != nil {
  129. return nil, err
  130. }
  131. return resp, nil
  132. }
  133. func (o *ModelArtsLink) GetResourceSpecs() (*collector.ResourceSpecs, error) {
  134. return nil, nil
  135. }
  136. func (o *ModelArtsLink) Execute(option option.AiOption) (interface{}, error) {
  137. return nil, nil
  138. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.