updated imageinfer api
Former-commit-id: 0f843ea0e844dc065bbb7ce1639bb3381f6aa856
This commit is contained in:
parent
63fab9b14c
commit
b412019647
|
@ -13,7 +13,9 @@ import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ImageInferenceLogic struct {
|
type ImageInferenceLogic struct {
|
||||||
|
@ -88,7 +90,6 @@ func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInfere
|
||||||
var strat strategy.Strategy
|
var strat strategy.Strategy
|
||||||
switch opt.Strategy {
|
switch opt.Strategy {
|
||||||
case strategy.STATIC_WEIGHT:
|
case strategy.STATIC_WEIGHT:
|
||||||
//todo resources should match cluster StaticWeightMap
|
|
||||||
strat = strategy.NewStaticWeightStrategy(opt.StaticWeightMap, int32(len(ts)))
|
strat = strategy.NewStaticWeightStrategy(opt.StaticWeightMap, int32(len(ts)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -145,6 +146,7 @@ func infer(opt *option.InferOption, clusters []*strategy.AssignedCluster, ts []s
|
||||||
go func() {
|
go func() {
|
||||||
imageUrls, err := collectorMap[c.ClusterId].GetImageInferUrl(ctx, opt)
|
imageUrls, err := collectorMap[c.ClusterId].GetImageInferUrl(ctx, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
wg.Done()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
clusterName, _ := svcCtx.Scheduler.AiStorages.GetClusterNameById(c.ClusterId)
|
clusterName, _ := svcCtx.Scheduler.AiStorages.GetClusterNameById(c.ClusterId)
|
||||||
|
@ -199,6 +201,10 @@ func infer(opt *option.InferOption, clusters []*strategy.AssignedCluster, ts []s
|
||||||
results = append(results, s)
|
results = append(results, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(results, func(p, q int) bool {
|
||||||
|
return results[p].ClusterName < results[q].ClusterName
|
||||||
|
})
|
||||||
|
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,6 +229,8 @@ func sendInferReq(images []struct {
|
||||||
r, err := getInferResult(c.urls[0].Url, t.file, t.imageResult.ImageName)
|
r, err := getInferResult(c.urls[0].Url, t.file, t.imageResult.ImageName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.imageResult.ImageResult = err.Error()
|
t.imageResult.ImageResult = err.Error()
|
||||||
|
t.imageResult.ClusterName = c.clusterName
|
||||||
|
t.imageResult.Card = c.urls[0].Card
|
||||||
ch <- t.imageResult
|
ch <- t.imageResult
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return
|
return
|
||||||
|
@ -239,6 +247,8 @@ func sendInferReq(images []struct {
|
||||||
r, err := getInferResult(c.urls[idx].Url, t.file, t.imageResult.ImageName)
|
r, err := getInferResult(c.urls[idx].Url, t.file, t.imageResult.ImageName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.imageResult.ImageResult = err.Error()
|
t.imageResult.ImageResult = err.Error()
|
||||||
|
t.imageResult.ClusterName = c.clusterName
|
||||||
|
t.imageResult.Card = c.urls[idx].Card
|
||||||
ch <- t.imageResult
|
ch <- t.imageResult
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return
|
return
|
||||||
|
@ -257,7 +267,7 @@ func sendInferReq(images []struct {
|
||||||
|
|
||||||
func getInferResult(url string, file multipart.File, fileName string) (string, error) {
|
func getInferResult(url string, file multipart.File, fileName string) (string, error) {
|
||||||
var res Res
|
var res Res
|
||||||
req := GetACHttpRequest()
|
req := GetRestyRequest(10)
|
||||||
_, err := req.
|
_, err := req.
|
||||||
SetFileReader("file", fileName, file).
|
SetFileReader("file", fileName, file).
|
||||||
SetResult(&res).
|
SetResult(&res).
|
||||||
|
@ -269,8 +279,8 @@ func getInferResult(url string, file multipart.File, fileName string) (string, e
|
||||||
return res.Result, nil
|
return res.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetACHttpRequest() *resty.Request {
|
func GetRestyRequest(timeoutSeconds int64) *resty.Request {
|
||||||
client := resty.New()
|
client := resty.New().SetTimeout(time.Duration(timeoutSeconds) * time.Second)
|
||||||
request := client.R()
|
request := client.R()
|
||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
|
|
|
@ -872,21 +872,28 @@ func setResourceIdByCard(option *option.AiOption, specs *octopus.GetResourceSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OctopusLink) GetImageInferUrl(ctx context.Context, option *option.InferOption) ([]*collector.ImageInferUrl, error) {
|
func (o *OctopusLink) GetImageInferUrl(ctx context.Context, option *option.InferOption) ([]*collector.ImageInferUrl, error) {
|
||||||
|
req := &octopus.GetNotebookListReq{
|
||||||
|
Platform: o.platform,
|
||||||
|
PageIndex: o.pageIndex,
|
||||||
|
PageSize: o.pageSize,
|
||||||
|
}
|
||||||
|
list, err := o.octopusRpc.GetNotebookList(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
var imageUrls []*collector.ImageInferUrl
|
var imageUrls []*collector.ImageInferUrl
|
||||||
imageUrl := &collector.ImageInferUrl{
|
for _, notebook := range list.Payload.GetNotebooks() {
|
||||||
Url: "http://0.0.0.0:8888/image",
|
if strings.Contains(notebook.AlgorithmName, option.ModelName) {
|
||||||
Card: "mlu",
|
names := strings.Split(notebook.AlgorithmName, UNDERSCORE)
|
||||||
|
imageUrl := &collector.ImageInferUrl{
|
||||||
|
Url: DOMAIN + notebook.Tasks[0].Url + FORWARD_SLASH + "image",
|
||||||
|
Card: names[2],
|
||||||
|
}
|
||||||
|
imageUrls = append(imageUrls, imageUrl)
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
imageUrl1 := &collector.ImageInferUrl{
|
|
||||||
Url: "http://0.0.0.0:8888/image",
|
|
||||||
Card: "gcu",
|
|
||||||
}
|
|
||||||
imageUrl2 := &collector.ImageInferUrl{
|
|
||||||
Url: "http://0.0.0.0:8888/image",
|
|
||||||
Card: "biv100",
|
|
||||||
}
|
|
||||||
imageUrls = append(imageUrls, imageUrl)
|
|
||||||
imageUrls = append(imageUrls, imageUrl1)
|
|
||||||
imageUrls = append(imageUrls, imageUrl2)
|
|
||||||
return imageUrls, nil
|
return imageUrls, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue