Browse Source

updated imageinference logics

Former-commit-id: 1bb4a47ac9
pull/290/head
tzwang 1 year ago
parent
commit
3c3d45fe62
5 changed files with 48 additions and 36 deletions
  1. +26
    -33
      internal/logic/inference/imageinferencelogic.go
  2. +14
    -2
      internal/scheduler/service/inference/imageInference/imageInference.go
  3. +1
    -1
      internal/scheduler/service/inference/textInference/textToImage.go
  4. +2
    -0
      internal/scheduler/service/inference/textInference/textToText.go
  5. +5
    -0
      internal/storeLink/octopus.go

+ 26
- 33
internal/logic/inference/imageinferencelogic.go View File

@@ -82,48 +82,41 @@ func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInfere
//} //}
// //


var cs []*strategy.AssignedCluster
var adapterName string
adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId)
if err != nil {
return nil, err
}

if opt.Strategy != "" { if opt.Strategy != "" {
var strat strategy.Strategy
switch opt.Strategy {
case strategy.STATIC_WEIGHT:
strat = strategy.NewStaticWeightStrategy(opt.StaticWeightMap, int32(len(ts)))
if err != nil {
return nil, err
}
default:
return nil, errors.New("no strategy has been chosen")
}
clusters, err := strat.Schedule()
return nil, errors.New("strategy is empty")
}

var strat strategy.Strategy
switch opt.Strategy {
case strategy.STATIC_WEIGHT:
strat = strategy.NewStaticWeightStrategy(opt.StaticWeightMap, int32(len(ts)))
if err != nil { if err != nil {
return nil, err return nil, err
} }
default:
return nil, errors.New("no strategy has been chosen")
}
clusters, err := strat.Schedule()
if err != nil {
return nil, err
}


if clusters == nil || len(clusters) == 0 {
return nil, errors.New("clusters is nil")
}

for i := len(clusters) - 1; i >= 0; i-- {
if clusters[i].Replicas == 0 {
clusters = append(clusters[:i], clusters[i+1:]...)
}
}
if clusters == nil || len(clusters) == 0 {
return nil, errors.New("clusters is nil")
}


name, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId)
if err != nil {
return nil, err
for i := len(clusters) - 1; i >= 0; i-- {
if clusters[i].Replicas == 0 {
clusters = append(clusters[:i], clusters[i+1:]...)
} }
adapterName = name
} }


//else {
// for i, instance := range req.Instances {
//
// }
//}

imageInfer, err := imageInference.New(imageInference.NewImageClassification(), ts, cs, req.Instances, opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, adapterName)
imageInfer, err := imageInference.New(imageInference.NewImageClassification(), ts, clusters, req.Instances, opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, adapterName)
if err != nil { if err != nil {
return nil, err return nil, err
} }


+ 14
- 2
internal/scheduler/service/inference/imageInference/imageInference.go View File

@@ -131,7 +131,7 @@ func (i *ImageInference) saveTask() (int64, error) {
return 0, err return 0, err
} }


i.storage.AddNoticeInfo(i.opt.AdapterId, i.adapterName, "", "", i.opt.TaskName, "create", "任务创建中")
i.storage.AddNoticeInfo("", "", "", "", i.opt.TaskName, "create", "任务创建中")


return id, nil return id, nil
} }
@@ -197,21 +197,33 @@ func (i *ImageInference) filterClusters() ([]*FilteredCluster, error) {
var cs []*FilteredCluster var cs []*FilteredCluster
for _, cluster := range i.clusters { for _, cluster := range i.clusters {
var inferurls []*inference.InferUrl var inferurls []*inference.InferUrl
var clustertype string
for _, instance := range i.instances { for _, instance := range i.instances {
if cluster.ClusterId == instance.ClusterId { if cluster.ClusterId == instance.ClusterId {
r := http.Request{} r := http.Request{}
deployInstance, err := i.inferAdapter[instance.AdapterId][instance.ClusterId].GetInferDeployInstance(r.Context(), instance.InstanceId) deployInstance, err := i.inferAdapter[instance.AdapterId][instance.ClusterId].GetInferDeployInstance(r.Context(), instance.InstanceId)
if err != nil { if err != nil {
return nil, err
continue
} }
var url inference.InferUrl var url inference.InferUrl
url.Url = deployInstance.InferUrl url.Url = deployInstance.InferUrl
url.Card = deployInstance.InferCard url.Card = deployInstance.InferCard
inferurls = append(inferurls, &url) inferurls = append(inferurls, &url)

clustertype = deployInstance.ClusterType
} }
} }
if len(inferurls) == 0 {
continue
}

i.inference.AppendRoute(inferurls)

var f FilteredCluster var f FilteredCluster
f.urls = inferurls f.urls = inferurls
f.clusterName = cluster.ClusterName
f.clusterType = clustertype
f.imageNum = cluster.Replicas
cs = append(cs, &f) cs = append(cs, &f)
} }
return cs, nil return cs, nil


+ 1
- 1
internal/scheduler/service/inference/textInference/textToImage.go View File

@@ -9,7 +9,7 @@ import (
) )


const ( const (
TEXTTOIMAGE = "text-to-image"
TEXTTOIMAGE = "generate_image"
TEXTTOIMAGE_AiTYPE = "14" TEXTTOIMAGE_AiTYPE = "14"
) )




+ 2
- 0
internal/scheduler/service/inference/textInference/textToText.go View File

@@ -79,9 +79,11 @@ func filterClusters(opt *option.InferOption, storage *database.AiStorage, inferA
wg.Done() wg.Done()
return return
} }

for i, _ := range clusterInferUrl.InferUrls { for i, _ := range clusterInferUrl.InferUrls {
clusterInferUrl.InferUrls[i].Url = clusterInferUrl.InferUrls[i].Url + inference.FORWARD_SLASH + CHAT clusterInferUrl.InferUrls[i].Url = clusterInferUrl.InferUrls[i].Url + inference.FORWARD_SLASH + CHAT
} }

clusterName, _ := storage.GetClusterNameById(cId) clusterName, _ := storage.GetClusterNameById(cId)


var f FilteredCluster var f FilteredCluster


+ 5
- 0
internal/storeLink/octopus.go View File

@@ -1154,11 +1154,16 @@ func (o *OctopusLink) GetInferDeployInstance(ctx context.Context, id string) (*i
if resp.Payload == nil { if resp.Payload == nil {
return nil, errors.New("instance does not exist") return nil, errors.New("instance does not exist")
} }

url := strings.Replace(resp.Payload.Notebook.Tasks[0].Url, FORWARD_SLASH, "", -1)
inferUrl := DOMAIN + url

ins.InstanceName = resp.Payload.Notebook.Name ins.InstanceName = resp.Payload.Notebook.Name
ins.InstanceId = resp.Payload.Notebook.Id ins.InstanceId = resp.Payload.Notebook.Id
ins.ClusterName = o.platform ins.ClusterName = o.platform
ins.Status = resp.Payload.Notebook.Status ins.Status = resp.Payload.Notebook.Status
ins.ClusterType = TYPE_OCTOPUS ins.ClusterType = TYPE_OCTOPUS
ins.InferUrl = inferUrl


return ins, nil return ins, nil
} }


Loading…
Cancel
Save