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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. "github.com/pkg/errors"
  16. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
  17. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector"
  18. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference"
  19. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
  20. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
  21. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/timeutils"
  22. "gitlink.org.cn/JointCloud/pcm-modelarts/client/imagesservice"
  23. "gitlink.org.cn/JointCloud/pcm-modelarts/client/modelartsservice"
  24. "gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
  25. modelartsclient "gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
  26. "mime/multipart"
  27. "strconv"
  28. "strings"
  29. "time"
  30. )
  31. const (
  32. Ascend = "Ascend"
  33. Npu = "npu"
  34. )
  35. type ModelArtsLink struct {
  36. modelArtsRpc modelartsservice.ModelArtsService
  37. modelArtsImgRpc imagesservice.ImagesService
  38. platform string
  39. participantId int64
  40. pageIndex int32
  41. pageSize int32
  42. }
  43. func NewModelArtsLink(modelArtsRpc modelartsservice.ModelArtsService, modelArtsImgRpc imagesservice.ImagesService, name string, id int64, nickname string) *ModelArtsLink {
  44. return &ModelArtsLink{modelArtsRpc: modelArtsRpc, modelArtsImgRpc: modelArtsImgRpc, platform: nickname, participantId: id, pageIndex: 0, pageSize: 50}
  45. }
  46. func (m *ModelArtsLink) UploadImage(ctx context.Context, path string) (interface{}, error) {
  47. //TODO modelArts上传镜像
  48. return nil, nil
  49. }
  50. func (m *ModelArtsLink) DeleteImage(ctx context.Context, imageId string) (interface{}, error) {
  51. // TODO modelArts删除镜像
  52. return nil, nil
  53. }
  54. func (m *ModelArtsLink) QueryImageList(ctx context.Context) (interface{}, error) {
  55. // modelArts获取镜像列表
  56. req := &modelarts.ListRepoReq{
  57. Offset: "0",
  58. Limit: strconv.Itoa(int(m.pageSize)),
  59. Platform: m.platform,
  60. }
  61. resp, err := m.modelArtsImgRpc.ListReposDetails(ctx, req)
  62. if err != nil {
  63. return nil, err
  64. }
  65. return resp, nil
  66. }
  67. func (m *ModelArtsLink) SubmitTask(ctx context.Context, imageId string, cmd string, envs []string, params []string, resourceId string, datasetsId string, algorithmId string, aiType string) (interface{}, error) {
  68. // modelArts提交任务
  69. environments := make(map[string]string)
  70. parameters := make([]*modelarts.ParametersTrainJob, 0)
  71. for _, env := range envs {
  72. s := strings.Split(env, COMMA)
  73. environments[s[0]] = s[1]
  74. }
  75. for _, param := range params {
  76. s := strings.Split(param, COMMA)
  77. parameters = append(parameters, &modelarts.ParametersTrainJob{
  78. Name: s[0],
  79. Value: s[1],
  80. })
  81. }
  82. req := &modelarts.CreateTrainingJobReq{
  83. Kind: "job",
  84. Metadata: &modelarts.MetadataS{
  85. Name: TASK_NAME_PREFIX + utils.RandomString(10),
  86. WorkspaceId: "0",
  87. },
  88. Algorithm: &modelarts.Algorithms{
  89. Id: algorithmId,
  90. Engine: &modelarts.EngineCreateTraining{
  91. ImageUrl: imageId,
  92. },
  93. Command: cmd,
  94. Environments: environments,
  95. Parameters: parameters,
  96. },
  97. Spec: &modelarts.SpecsC{
  98. Resource: &modelarts.ResourceCreateTraining{
  99. FlavorId: resourceId,
  100. NodeCount: 1,
  101. },
  102. },
  103. Platform: m.platform,
  104. }
  105. resp, err := m.modelArtsRpc.CreateTrainingJob(ctx, req)
  106. if err != nil {
  107. return nil, err
  108. }
  109. return resp, nil
  110. }
  111. func (m *ModelArtsLink) QueryTask(ctx context.Context, taskId string) (interface{}, error) {
  112. // 获取任务
  113. req := &modelarts.DetailTrainingJobsReq{
  114. TrainingJobId: taskId,
  115. Platform: m.platform,
  116. }
  117. resp, err := m.modelArtsRpc.GetTrainingJobs(ctx, req)
  118. if err != nil {
  119. return nil, err
  120. }
  121. return resp, nil
  122. }
  123. func (m *ModelArtsLink) DeleteTask(ctx context.Context, taskId string) (interface{}, error) {
  124. // 删除任务
  125. req := &modelarts.DeleteTrainingJobReq{
  126. TrainingJobId: taskId,
  127. Platform: m.platform,
  128. }
  129. resp, err := m.modelArtsRpc.DeleteTrainingJob(ctx, req)
  130. if err != nil {
  131. return nil, err
  132. }
  133. return resp, nil
  134. }
  135. func (m *ModelArtsLink) QuerySpecs(ctx context.Context) (interface{}, error) {
  136. // octopus查询资源规格
  137. req := &modelarts.TrainingJobFlavorsReq{
  138. Platform: m.platform,
  139. }
  140. resp, err := m.modelArtsRpc.GetTrainingJobFlavors(ctx, req)
  141. if err != nil {
  142. return nil, err
  143. }
  144. return resp, nil
  145. }
  146. func (m *ModelArtsLink) GetResourceStats(ctx context.Context) (*collector.ResourceStats, error) {
  147. req := &modelarts.GetPoolsRuntimeMetricsReq{}
  148. resp, err := m.modelArtsRpc.GetPoolsRuntimeMetrics(ctx, req)
  149. if err != nil {
  150. return nil, err
  151. }
  152. if resp.ErrorMsg != "" {
  153. return nil, errors.New("failed to get algorithms")
  154. }
  155. resourceStats := &collector.ResourceStats{}
  156. CpuCoreTotalSum := int64(0)
  157. CpuCoreAvailSum := int64(0)
  158. MemTotalSum := float64(0)
  159. MemAvailSum := float64(0)
  160. var CpuCoreTotal int64
  161. var CpuCoreAvail int64
  162. var MemTotal float64
  163. var MemAvail float64
  164. for _, items := range resp.Items {
  165. //TODO The value of taskType is temporarily fixed to "pytorch"
  166. CpuCoreTotal, err = strconv.ParseInt(items.Table.Capacity.Value.Cpu, 10, 64)
  167. CpuCoreTotalSum += CpuCoreTotal
  168. CpuCoreAvail, err = strconv.ParseInt(items.Table.Allocated.Value.Cpu, 10, 64)
  169. CpuCoreAvailSum += CpuCoreAvail
  170. MemTotal, err = strconv.ParseFloat(items.Table.Capacity.Value.Memory, 64)
  171. MemTotalSum += MemTotal
  172. MemAvail, err = strconv.ParseFloat(items.Table.Allocated.Value.Memory, 64)
  173. MemAvailSum += MemAvail
  174. }
  175. resourceStats.CpuCoreTotal = CpuCoreTotalSum
  176. resourceStats.CpuCoreAvail = CpuCoreAvailSum
  177. resourceStats.MemTotal = MemTotalSum
  178. resourceStats.MemAvail = MemAvailSum
  179. req1 := &modelarts.GetResourceFlavorsReq{}
  180. resp1, err := m.modelArtsRpc.GetResourceFlavors(ctx, req1)
  181. num32, _ := strconv.Atoi(resp1.Items[0].Spec.Npu.Size)
  182. var cards []*collector.Card
  183. card := &collector.Card{
  184. Platform: MODELARTS,
  185. Type: CARD,
  186. Name: Npu,
  187. CardNum: int32(num32),
  188. TOpsAtFp16: float64(num32 * 320),
  189. }
  190. cards = append(cards, card)
  191. resourceStats.CardsAvail = cards
  192. return resourceStats, nil
  193. }
  194. func (m *ModelArtsLink) GetDatasetsSpecs(ctx context.Context) ([]*collector.DatasetsSpecs, error) {
  195. return nil, nil
  196. }
  197. func (m *ModelArtsLink) GetAlgorithms(ctx context.Context) ([]*collector.Algorithm, error) {
  198. var algorithms []*collector.Algorithm
  199. req := &modelarts.ListAlgorithmsReq{
  200. Platform: m.platform,
  201. Offset: m.pageIndex,
  202. Limit: m.pageSize,
  203. }
  204. resp, err := m.modelArtsRpc.ListAlgorithms(ctx, req)
  205. if err != nil {
  206. return nil, err
  207. }
  208. if resp.ErrorMsg != "" {
  209. return nil, errors.New("failed to get algorithms")
  210. }
  211. for _, a := range resp.Items {
  212. //TODO The value of taskType is temporarily fixed to "pytorch"
  213. algorithm := &collector.Algorithm{Name: a.Metadata.Name, Platform: MODELARTS, TaskType: "pytorch"}
  214. algorithms = append(algorithms, algorithm)
  215. }
  216. return algorithms, nil
  217. }
  218. func (m *ModelArtsLink) GetComputeCards(ctx context.Context) ([]string, error) {
  219. var cards []string
  220. cards = append(cards, Ascend)
  221. return cards, nil
  222. }
  223. func (m *ModelArtsLink) GetUserBalance(ctx context.Context) (float64, error) {
  224. return 0, nil
  225. }
  226. func (m *ModelArtsLink) DownloadAlgorithmCode(ctx context.Context, resourceType string, card string, taskType string, dataset string, algorithm string) (string, error) {
  227. return "", nil
  228. }
  229. func (m *ModelArtsLink) UploadAlgorithmCode(ctx context.Context, resourceType string, card string, taskType string, dataset string, algorithm string, code string) error {
  230. return nil
  231. }
  232. // Get AI Application List
  233. func (m *ModelArtsLink) GetModelId(ctx context.Context, option *option.InferOption) error {
  234. req := &modelarts.ListModelReq{
  235. Platform: m.platform,
  236. ModelName: option.ModelName,
  237. ModelType: "Image",
  238. Limit: int64(m.pageIndex),
  239. Offset: int64(m.pageSize),
  240. }
  241. ListModelResp, err := m.modelArtsRpc.ListModels(ctx, req)
  242. if err != nil {
  243. return err
  244. }
  245. if ListModelResp.Code != 200 {
  246. return errors.New("failed to get ModelId")
  247. }
  248. for _, ListModel := range ListModelResp.Models {
  249. if ListModel.ModelName == option.ModelName {
  250. option.ModelId = ListModel.ModelId
  251. return nil
  252. }
  253. }
  254. return nil
  255. }
  256. // 创建ai应用
  257. func (m *ModelArtsLink) CreateModel(ctx context.Context, option *option.InferOption) error {
  258. req := &modelarts.CreateModelReq{
  259. Platform: m.platform,
  260. ModelName: option.ModelName,
  261. ModelType: "PyTorch",
  262. ModelVersion: "0.0.1",
  263. SourceLocation: "",
  264. }
  265. ModelResp, err := m.modelArtsRpc.CreateModel(ctx, req)
  266. if err != nil {
  267. return err
  268. }
  269. if ModelResp.Code != 200 {
  270. return errors.New("failed to get ModelId")
  271. }
  272. option.ModelId = ModelResp.ModelId
  273. return nil
  274. }
  275. func (m *ModelArtsLink) GetSpecifications(ctx context.Context, option *option.AiOption, ifoption *option.InferOption) error {
  276. req := &modelarts.ListSpecificationsReq{
  277. //Platform: m.platform,
  278. IsPersonalCluster: false,
  279. InferType: "real-time",
  280. Limit: m.pageIndex,
  281. OffSet: m.pageSize,
  282. }
  283. ListSpecificationsResp, err := m.modelArtsRpc.ListSpecifications(ctx, req)
  284. if err != nil {
  285. return err
  286. }
  287. for _, ListSpecifications := range ListSpecificationsResp.Specifications {
  288. if ListSpecifications.Specification == "modelarts.kat1.xlarge" {
  289. ifoption.Specification = ListSpecifications.Specification
  290. return nil
  291. }
  292. }
  293. return nil
  294. }
  295. func (m *ModelArtsLink) GetTrainingTaskLog(ctx context.Context, taskId string, instanceNum string) (string, error) {
  296. req := &modelartsservice.GetTrainingJobLogsPreviewReq{
  297. Platform: m.platform,
  298. TaskId: "worker-0",
  299. TrainingJobId: taskId,
  300. }
  301. resp, err := m.modelArtsRpc.GetTrainingJobLogsPreview(ctx, req)
  302. if err != nil {
  303. return "", err
  304. }
  305. if strings.Contains(resp.Content, "404 Not Found") {
  306. resp.Content = "waiting for logs..."
  307. }
  308. return resp.Content, nil
  309. }
  310. func (m *ModelArtsLink) GetTrainingTask(ctx context.Context, taskId string) (*collector.Task, error) {
  311. resp, err := m.QueryTask(ctx, taskId)
  312. if err != nil {
  313. return nil, err
  314. }
  315. jobresp, ok := (resp).(*modelartsservice.JobResponse)
  316. if jobresp.ErrorMsg != "" || !ok {
  317. if jobresp.ErrorMsg != "" {
  318. return nil, errors.New(jobresp.ErrorMsg)
  319. } else {
  320. return nil, errors.New("get training task failed, empty error returned")
  321. }
  322. }
  323. var task collector.Task
  324. task.Id = jobresp.Metadata.Id
  325. switch strings.ToLower(jobresp.Status.Phase) {
  326. case "completed":
  327. milliTimestamp := int64(jobresp.Status.StartTime)
  328. task.Start = timeutils.MillisecondsToUTCString(milliTimestamp, time.DateTime)
  329. duration := int64(jobresp.Status.Duration)
  330. task.End = timeutils.MillisecondsToAddDurationToUTCString(milliTimestamp, duration, time.DateTime)
  331. task.Status = constants.Completed
  332. case "failed":
  333. milliTimestamp := int64(jobresp.Status.StartTime)
  334. task.Start = timeutils.MillisecondsToUTCString(milliTimestamp, time.DateTime)
  335. duration := int64(jobresp.Status.Duration)
  336. task.End = timeutils.MillisecondsToAddDurationToUTCString(milliTimestamp, duration, time.DateTime)
  337. task.Status = constants.Failed
  338. case "running":
  339. milliTimestamp := int64(jobresp.Status.StartTime)
  340. task.Start = timeutils.MillisecondsToUTCString(milliTimestamp, time.DateTime)
  341. task.Status = constants.Running
  342. case "stopped":
  343. task.Status = constants.Stopped
  344. case "pending":
  345. task.Status = constants.Pending
  346. case "terminated":
  347. //TODO Failed
  348. task.Status = constants.Failed
  349. default:
  350. task.Status = "undefined"
  351. }
  352. return &task, nil
  353. }
  354. func (m *ModelArtsLink) Execute(ctx context.Context, option *option.AiOption) (interface{}, error) {
  355. err := m.GenerateSubmitParams(ctx, option)
  356. if err != nil {
  357. return nil, err
  358. }
  359. task, err := m.SubmitTask(ctx, option.ImageId, option.Cmd, option.Envs, option.Params, option.ResourceId, option.DatasetsId, option.AlgorithmId, option.TaskType)
  360. if err != nil {
  361. return nil, err
  362. }
  363. return task, nil
  364. }
  365. func (m *ModelArtsLink) GenerateSubmitParams(ctx context.Context, option *option.AiOption) error {
  366. err := m.generateResourceId(ctx, option, nil)
  367. if err != nil {
  368. return err
  369. }
  370. err = m.generateAlgorithmId(ctx, option)
  371. if err != nil {
  372. return err
  373. }
  374. err = m.generateImageId(option)
  375. if err != nil {
  376. return err
  377. }
  378. err = m.generateCmd(option)
  379. if err != nil {
  380. return err
  381. }
  382. err = m.generateEnv(option)
  383. if err != nil {
  384. return err
  385. }
  386. err = m.generateParams(option)
  387. if err != nil {
  388. return err
  389. }
  390. return nil
  391. }
  392. func (m *ModelArtsLink) generateResourceId(ctx context.Context, option *option.AiOption, ifoption *option.InferOption) error {
  393. option.ResourceId = "modelarts.kat1.xlarge"
  394. return nil
  395. }
  396. func (m *ModelArtsLink) generateImageId(option *option.AiOption) error {
  397. return nil
  398. }
  399. func (m *ModelArtsLink) generateCmd(option *option.AiOption) error {
  400. return nil
  401. }
  402. func (m *ModelArtsLink) generateEnv(option *option.AiOption) error {
  403. return nil
  404. }
  405. func (m *ModelArtsLink) generateParams(option *option.AiOption) error {
  406. return nil
  407. }
  408. func (m *ModelArtsLink) generateAlgorithmId(ctx context.Context, option *option.AiOption) error {
  409. req := &modelarts.ListAlgorithmsReq{
  410. Platform: m.platform,
  411. Offset: m.pageIndex,
  412. Limit: m.pageSize,
  413. }
  414. resp, err := m.modelArtsRpc.ListAlgorithms(ctx, req)
  415. if err != nil {
  416. return err
  417. }
  418. if resp.ErrorMsg != "" {
  419. return errors.New("failed to get algorithmId")
  420. }
  421. for _, algorithm := range resp.Items {
  422. engVersion := algorithm.JobConfig.Engine.EngineVersion
  423. if strings.Contains(engVersion, option.TaskType) {
  424. ns := strings.Split(algorithm.Metadata.Name, DASH)
  425. if ns[0] != option.TaskType {
  426. continue
  427. }
  428. if ns[1] != option.DatasetsName {
  429. continue
  430. }
  431. if ns[2] != option.AlgorithmName {
  432. continue
  433. }
  434. option.AlgorithmId = algorithm.Metadata.Id
  435. return nil
  436. }
  437. }
  438. if option.AlgorithmId == "" {
  439. return errors.New("Algorithm does not exist")
  440. }
  441. return errors.New("failed to get AlgorithmId")
  442. }
  443. func (m *ModelArtsLink) GetClusterInferUrl(ctx context.Context, option *option.InferOption) (*inference.ClusterInferUrl, error) {
  444. var imageUrls []*inference.InferUrl
  445. urlReq := &modelartsclient.ImageReasoningUrlReq{
  446. ServiceName: option.ModelName,
  447. Type: option.ModelType,
  448. Card: "npu",
  449. }
  450. urlResp, err := m.modelArtsRpc.ImageReasoningUrl(ctx, urlReq)
  451. if err != nil {
  452. return nil, err
  453. }
  454. imageUrl := &inference.InferUrl{
  455. Url: urlResp.Url,
  456. Card: "npu",
  457. }
  458. imageUrls = append(imageUrls, imageUrl)
  459. clusterWithUrl := &inference.ClusterInferUrl{
  460. ClusterName: m.platform,
  461. ClusterType: TYPE_MODELARTS,
  462. InferUrls: imageUrls,
  463. }
  464. return clusterWithUrl, nil
  465. }
  466. func (m *ModelArtsLink) GetInferDeployInstanceList(ctx context.Context) ([]*inference.DeployInstance, error) {
  467. var insList []*inference.DeployInstance
  468. req := &modelarts.ListServicesReq{
  469. Platform: m.platform,
  470. OffSet: m.pageIndex,
  471. Limit: m.pageSize,
  472. }
  473. //list, err := m.modelArtsRpc.ListServices(ctx, req)
  474. resp, err := m.modelArtsRpc.ListServices(ctx, req)
  475. if err != nil {
  476. return nil, err
  477. }
  478. if resp.ErrorMsg != "" {
  479. return nil, errors.New(resp.Msg)
  480. }
  481. for _, services := range resp.Services {
  482. ins := &inference.DeployInstance{}
  483. ins.InstanceName = services.ServiceName
  484. ins.InstanceId = services.ServiceId
  485. ins.Status = services.Status
  486. ins.InferCard = "NPU"
  487. ins.ClusterName = m.platform
  488. ins.CreatedTime = string(services.StartTime)
  489. ins.ClusterType = TYPE_MODELARTS
  490. insList = append(insList, ins)
  491. }
  492. return insList, nil
  493. }
  494. func (m *ModelArtsLink) StartInferDeployInstance(ctx context.Context, id string) bool {
  495. req := &modelartsclient.UpdateServiceReq{
  496. ServiceId: id,
  497. Status: "running",
  498. }
  499. resp, err := m.modelArtsRpc.UpdateService(ctx, req)
  500. if err != nil || resp.Code != 0 {
  501. return false
  502. }
  503. if resp.Code == 0 {
  504. return true
  505. }
  506. return false
  507. }
  508. func (m *ModelArtsLink) StopInferDeployInstance(ctx context.Context, id string) bool {
  509. req := &modelartsclient.UpdateServiceReq{
  510. ServiceId: id,
  511. Status: "stopped",
  512. }
  513. resp, err := m.modelArtsRpc.UpdateService(ctx, req)
  514. if err != nil || resp.Code != 0 {
  515. return false
  516. }
  517. if resp.Code == 0 {
  518. return true
  519. }
  520. return false
  521. }
  522. func (m *ModelArtsLink) GetInferDeployInstance(ctx context.Context, id string) (*inference.DeployInstance, error) {
  523. req := &modelarts.ShowServiceReq{
  524. ServiceId: id,
  525. }
  526. resp, err := m.modelArtsRpc.ShowService(ctx, req)
  527. if err != nil {
  528. return nil, err
  529. }
  530. if resp.ErrorMsg != "" {
  531. return nil, errors.New(resp.Msg)
  532. }
  533. ins := &inference.DeployInstance{}
  534. ins.InstanceName = resp.ServiceName
  535. ins.InstanceId = resp.ServiceId
  536. ins.Status = resp.Status
  537. ins.InferCard = "NPU"
  538. ins.ClusterName = m.platform
  539. ins.CreatedTime = string(resp.StartTime)
  540. ins.ClusterType = TYPE_MODELARTS
  541. return ins, nil
  542. }
  543. func (m *ModelArtsLink) GetInferResult(ctx context.Context, url string, file multipart.File, fileName string) (string, error) {
  544. return "", nil
  545. }
  546. func (m *ModelArtsLink) CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error) {
  547. err := m.CreateModel(ctx, option)
  548. if err != nil {
  549. return "", err
  550. }
  551. configParam := &modelarts.ServiceConfig{
  552. Specification: "modelarts.kat1.xlarge",
  553. Weight: 100,
  554. ModelId: option.ModelId,
  555. InstanceCount: 1,
  556. }
  557. var configItems []*modelarts.ServiceConfig
  558. configItems = append(configItems, configParam)
  559. req := &modelarts.CreateServiceReq{
  560. Platform: m.platform,
  561. Config: configItems,
  562. InferType: "real-time",
  563. ServiceName: option.TaskName,
  564. }
  565. resp, err := m.modelArtsRpc.CreateService(ctx, req)
  566. if err != nil {
  567. return "", err
  568. }
  569. return resp.ServiceId, nil
  570. }
  571. func (m *ModelArtsLink) CheckModelExistence(ctx context.Context, name string, mtype string) bool {
  572. ifoption := &option.InferOption{
  573. ModelName: name,
  574. ModelType: mtype,
  575. }
  576. err := m.GetModelId(ctx, ifoption)
  577. if err != nil {
  578. return false
  579. }
  580. return true
  581. }

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.