|
|
@@ -27,6 +27,10 @@ import ( |
|
|
"strings" |
|
|
"strings" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
Ascend = "Ascend" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
type ModelArtsLink struct { |
|
|
type ModelArtsLink struct { |
|
|
modelArtsRpc modelartsservice.ModelArtsService |
|
|
modelArtsRpc modelartsservice.ModelArtsService |
|
|
modelArtsImgRpc imagesservice.ImagesService |
|
|
modelArtsImgRpc imagesservice.ImagesService |
|
|
@@ -36,8 +40,8 @@ type ModelArtsLink struct { |
|
|
pageSize int32 |
|
|
pageSize int32 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewModelArtsLink(modelArtsRpc modelartsservice.ModelArtsService, modelArtsImgRpc imagesservice.ImagesService, name string, id int64) *ModelArtsLink { |
|
|
|
|
|
return &ModelArtsLink{modelArtsRpc: modelArtsRpc, modelArtsImgRpc: modelArtsImgRpc, platform: name, participantId: id, pageIndex: 1, pageSize: 100} |
|
|
|
|
|
|
|
|
func NewModelArtsLink(modelArtsRpc modelartsservice.ModelArtsService, modelArtsImgRpc imagesservice.ImagesService, name string, id int64, nickname string) *ModelArtsLink { |
|
|
|
|
|
return &ModelArtsLink{modelArtsRpc: modelArtsRpc, modelArtsImgRpc: modelArtsImgRpc, platform: nickname, participantId: id, pageIndex: 0, pageSize: 50} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (m *ModelArtsLink) UploadImage(ctx context.Context, path string) (interface{}, error) { |
|
|
func (m *ModelArtsLink) UploadImage(ctx context.Context, path string) (interface{}, error) { |
|
|
@@ -87,6 +91,7 @@ func (m *ModelArtsLink) SubmitTask(ctx context.Context, imageId string, cmd stri |
|
|
WorkspaceId: "0", |
|
|
WorkspaceId: "0", |
|
|
}, |
|
|
}, |
|
|
Algorithm: &modelarts.Algorithms{ |
|
|
Algorithm: &modelarts.Algorithms{ |
|
|
|
|
|
Id: algorithmId, |
|
|
Engine: &modelarts.EngineCreateTraining{ |
|
|
Engine: &modelarts.EngineCreateTraining{ |
|
|
ImageUrl: imageId, |
|
|
ImageUrl: imageId, |
|
|
}, |
|
|
}, |
|
|
@@ -184,7 +189,9 @@ func (m *ModelArtsLink) GetAlgorithms(ctx context.Context) ([]*collector.Algorit |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (m *ModelArtsLink) GetComputeCards(ctx context.Context) ([]string, error) { |
|
|
func (m *ModelArtsLink) GetComputeCards(ctx context.Context) ([]string, error) { |
|
|
return nil, nil |
|
|
|
|
|
|
|
|
var cards []string |
|
|
|
|
|
cards = append(cards, Ascend) |
|
|
|
|
|
return cards, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (m *ModelArtsLink) GetUserBalance(ctx context.Context) (float64, error) { |
|
|
func (m *ModelArtsLink) GetUserBalance(ctx context.Context) (float64, error) { |
|
|
@@ -224,6 +231,10 @@ func (m *ModelArtsLink) GenerateSubmitParams(ctx context.Context, option *option |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
err = m.generateAlgorithmId(ctx, option) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
err = m.generateImageId(option) |
|
|
err = m.generateImageId(option) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
@@ -244,10 +255,7 @@ func (m *ModelArtsLink) GenerateSubmitParams(ctx context.Context, option *option |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (m *ModelArtsLink) generateResourceId(ctx context.Context, option *option.AiOption) error { |
|
|
func (m *ModelArtsLink) generateResourceId(ctx context.Context, option *option.AiOption) error { |
|
|
_, err := m.QuerySpecs(ctx) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
option.ResourceId = "modelarts.kat1.xlarge" |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -270,3 +278,42 @@ func (m *ModelArtsLink) generateParams(option *option.AiOption) error { |
|
|
|
|
|
|
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (m *ModelArtsLink) generateAlgorithmId(ctx context.Context, option *option.AiOption) error { |
|
|
|
|
|
req := &modelarts.ListAlgorithmsReq{ |
|
|
|
|
|
Platform: m.platform, |
|
|
|
|
|
Offset: m.pageIndex, |
|
|
|
|
|
Limit: m.pageSize, |
|
|
|
|
|
} |
|
|
|
|
|
resp, err := m.modelArtsRpc.ListAlgorithms(ctx, req) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
if resp.ErrorMsg != "" { |
|
|
|
|
|
return errors.New("failed to get algorithmId") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, algorithm := range resp.Items { |
|
|
|
|
|
engVersion := algorithm.JobConfig.Engine.EngineVersion |
|
|
|
|
|
if strings.Contains(engVersion, option.TaskType) { |
|
|
|
|
|
ns := strings.Split(algorithm.Metadata.Name, DASH) |
|
|
|
|
|
if ns[0] != option.TaskType { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
if ns[1] != option.DatasetsName { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
if ns[2] != option.AlgorithmName { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
option.AlgorithmId = algorithm.Metadata.Id |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if option.AlgorithmId == "" { |
|
|
|
|
|
return errors.New("Algorithm does not exist") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return errors.New("failed to get AlgorithmId") |
|
|
|
|
|
} |