updated imageinference logics
Former-commit-id: 1bb4a47ac943ee12a0d92ce37820af58b155641e
This commit is contained in:
parent
a60e97134d
commit
3c3d45fe62
|
@ -82,48 +82,41 @@ func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInfere
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
|
|
||||||
var cs []*strategy.AssignedCluster
|
adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId)
|
||||||
var adapterName string
|
if err != nil {
|
||||||
if opt.Strategy != "" {
|
return nil, err
|
||||||
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()
|
|
||||||
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:]...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
name, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
adapterName = name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//else {
|
if opt.Strategy != "" {
|
||||||
// for i, instance := range req.Instances {
|
return nil, errors.New("strategy is empty")
|
||||||
//
|
}
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
imageInfer, err := imageInference.New(imageInference.NewImageClassification(), ts, cs, req.Instances, opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, adapterName)
|
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()
|
||||||
|
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:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TEXTTOIMAGE = "text-to-image"
|
TEXTTOIMAGE = "generate_image"
|
||||||
TEXTTOIMAGE_AiTYPE = "14"
|
TEXTTOIMAGE_AiTYPE = "14"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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…
Reference in New Issue