updated imageinference logics
Former-commit-id: 3dde5aa691fa23f3ebae3772620640d96ab70570
This commit is contained in:
parent
1f0e6c07d0
commit
739948d184
|
@ -10,7 +10,9 @@ import (
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/strategy"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/strategy"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ImageInferenceLogic struct {
|
type ImageInferenceLogic struct {
|
||||||
|
@ -34,21 +36,24 @@ func NewImageInferenceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Im
|
||||||
|
|
||||||
func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInferenceReq) (resp *types.ImageInferenceResp, err error) {
|
func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInferenceReq) (resp *types.ImageInferenceResp, err error) {
|
||||||
resp = &types.ImageInferenceResp{}
|
resp = &types.ImageInferenceResp{}
|
||||||
if len(req.Instances) == 0 {
|
if len(req.InstanceIds) == 0 {
|
||||||
return nil, errors.New("instances are empty")
|
return nil, errors.New("instances are empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
opt := &option.InferOption{
|
var instanceList []*models.AiInferDeployInstance
|
||||||
TaskName: req.TaskName,
|
for _, id := range req.InstanceIds {
|
||||||
TaskDesc: req.TaskDesc,
|
instance, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(id)
|
||||||
//AdapterId: req.AdapterId,
|
if err != nil {
|
||||||
//AiClusterIds: req.AiClusterIds,
|
return nil, err
|
||||||
//ModelName: req.ModelName,
|
}
|
||||||
ModelType: req.ModelType,
|
instanceList = append(instanceList, instance)
|
||||||
Strategy: req.Strategy,
|
|
||||||
StaticWeightMap: req.StaticWeightMap,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(instanceList) == 0 {
|
||||||
|
return nil, errors.New("instances are empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
// process uploaded images
|
||||||
var ts []*imageInference.ImageFile
|
var ts []*imageInference.ImageFile
|
||||||
|
|
||||||
uploadedFiles := r.MultipartForm.File
|
uploadedFiles := r.MultipartForm.File
|
||||||
|
@ -76,17 +81,35 @@ func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInfere
|
||||||
ts = append(ts, &t)
|
ts = append(ts, &t)
|
||||||
}
|
}
|
||||||
|
|
||||||
//_, ok := l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[opt.AdapterId]
|
//single adapter logic
|
||||||
//if !ok {
|
if len(req.StaticWeightMap) != 1 {
|
||||||
// return nil, errors.New("AdapterId does not exist")
|
return nil, errors.New("staticWeightMap != 1")
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
|
adapterId := strconv.FormatInt(instanceList[0].AdapterId, 10)
|
||||||
|
staticWeightMap, ok := req.StaticWeightMap[adapterId]
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("set staticWeightMap failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
// create InferOption
|
||||||
|
opt := &option.InferOption{
|
||||||
|
TaskName: req.TaskName,
|
||||||
|
TaskDesc: req.TaskDesc,
|
||||||
|
AdapterId: adapterId,
|
||||||
|
//AiClusterIds: req.AiClusterIds,
|
||||||
|
//ModelName: req.ModelName,
|
||||||
|
ModelType: req.ModelType,
|
||||||
|
Strategy: req.Strategy,
|
||||||
|
StaticWeightMap: staticWeightMap,
|
||||||
|
}
|
||||||
|
|
||||||
adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId)
|
adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set strategy
|
||||||
if opt.Strategy != "" {
|
if opt.Strategy != "" {
|
||||||
return nil, errors.New("strategy is empty")
|
return nil, errors.New("strategy is empty")
|
||||||
}
|
}
|
||||||
|
@ -116,7 +139,8 @@ func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInfere
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imageInfer, err := imageInference.New(imageInference.NewImageClassification(), ts, clusters, req.Instances, opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, adapterName)
|
// create inference struct
|
||||||
|
imageInfer, err := imageInference.New(imageInference.NewImageClassification(), ts, clusters, instanceList, opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, adapterName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ type ImageInference struct {
|
||||||
inference IImageInference
|
inference IImageInference
|
||||||
files []*ImageFile
|
files []*ImageFile
|
||||||
clusters []*strategy.AssignedCluster
|
clusters []*strategy.AssignedCluster
|
||||||
instances []types.DeployInstance
|
instances []*models.AiInferDeployInstance
|
||||||
opt *option.InferOption
|
opt *option.InferOption
|
||||||
storage *database.AiStorage
|
storage *database.AiStorage
|
||||||
inferAdapter map[string]map[string]inference.ICluster
|
inferAdapter map[string]map[string]inference.ICluster
|
||||||
|
@ -58,7 +58,7 @@ func New(
|
||||||
inference IImageInference,
|
inference IImageInference,
|
||||||
files []*ImageFile,
|
files []*ImageFile,
|
||||||
clusters []*strategy.AssignedCluster,
|
clusters []*strategy.AssignedCluster,
|
||||||
instances []types.DeployInstance,
|
instances []*models.AiInferDeployInstance,
|
||||||
opt *option.InferOption,
|
opt *option.InferOption,
|
||||||
storage *database.AiStorage,
|
storage *database.AiStorage,
|
||||||
inferAdapter map[string]map[string]inference.ICluster,
|
inferAdapter map[string]map[string]inference.ICluster,
|
||||||
|
@ -199,9 +199,12 @@ func (i *ImageInference) filterClusters() ([]*FilteredCluster, error) {
|
||||||
var inferurls []*inference.InferUrl
|
var inferurls []*inference.InferUrl
|
||||||
var clustertype string
|
var clustertype string
|
||||||
for _, instance := range i.instances {
|
for _, instance := range i.instances {
|
||||||
if cluster.ClusterId == instance.ClusterId {
|
clusterId := strconv.FormatInt(instance.ClusterId, 10)
|
||||||
|
adapterId := strconv.FormatInt(instance.AdapterId, 10)
|
||||||
|
|
||||||
|
if cluster.ClusterId == clusterId {
|
||||||
r := http.Request{}
|
r := http.Request{}
|
||||||
deployInstance, err := i.inferAdapter[instance.AdapterId][instance.ClusterId].GetInferDeployInstance(r.Context(), instance.InstanceId)
|
deployInstance, err := i.inferAdapter[adapterId][clusterId].GetInferDeployInstance(r.Context(), instance.InstanceId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue