Former-commit-id: cfb3f225fc29a5d431ac85487adaf3e3c3ee6a19
This commit is contained in:
zhangwei 2024-09-04 16:57:33 +08:00
commit 1b02a8c91c
9 changed files with 102 additions and 47 deletions

View File

@ -79,10 +79,8 @@ type (
TextToTextInferenceReq{ TextToTextInferenceReq{
TaskName string `form:"taskName"` TaskName string `form:"taskName"`
TaskDesc string `form:"taskDesc"` TaskDesc string `form:"taskDesc"`
ModelName string `form:"modelName"`
ModelType string `form:"modelType"` ModelType string `form:"modelType"`
AdapterId string `form:"adapterId"` InstanceId int64 `form:"instanceId"`
AiClusterIds []string `form:"aiClusterIds"`
} }
TextToTextInferenceResp{ TextToTextInferenceResp{
@ -200,7 +198,7 @@ type (
AdapterAvail { AdapterAvail {
AdapterId string `json:"adapterId"` AdapterId string `json:"adapterId"`
AdapterName string `json:"taskName"` AdapterName string `json:"adapterName"`
Clusters []*ClusterAvail `json:"clusters"` Clusters []*ClusterAvail `json:"clusters"`
} }

View File

@ -95,7 +95,7 @@ func (l *CreateDeployTaskLogic) createDeployInstance(taskId int64, adapterId str
return err return err
} }
_, err = l.svcCtx.Scheduler.AiStorages.SaveInferDeployInstance(taskId, ins.InstanceId, ins.InstanceName, aid, adapterName, cid, clusterName, ins.ModelName, ins.ModelType, ins.InferCard) _, err = l.svcCtx.Scheduler.AiStorages.SaveInferDeployInstance(taskId, ins.InstanceId, ins.InstanceName, aid, adapterName, cid, clusterName, ins.ModelName, ins.ModelType, ins.InferCard, ins.ClusterType)
if err != nil { if err != nil {
return err return err
} }

View File

@ -52,7 +52,10 @@ func (l *DeployInstanceListLogic) DeployInstanceList(req *types.DeployInstanceLi
return nil, errors.New(err.Error()) return nil, errors.New(err.Error())
} }
deployTasks := l.GenerateDeployTasks(tasklist) deployTasks, err := l.GenerateDeployTasks(tasklist)
if err != nil {
return nil, errors.New(err.Error())
}
slices := make([][]*models.AiInferDeployInstance, len(deployTasks)) slices := make([][]*models.AiInferDeployInstance, len(deployTasks))
for i := 0; i < len(deployTasks); i++ { for i := 0; i < len(deployTasks); i++ {
slices[i] = deployTasks[i].Instances slices[i] = deployTasks[i].Instances
@ -83,12 +86,20 @@ func (l *DeployInstanceListLogic) DeployInstanceList(req *types.DeployInstanceLi
return return
} }
func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeployInstanceTask) []*DeployTask { func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeployInstanceTask) ([]*DeployTask, error) {
var tasks []*DeployTask var tasks []*DeployTask
for _, t := range tasklist { for _, t := range tasklist {
list, err := l.svcCtx.Scheduler.AiStorages.GetInstanceListByDeployTaskId(t.Id) list, err := l.svcCtx.Scheduler.AiStorages.GetInstanceListByDeployTaskId(t.Id)
if err != nil { if err != nil {
logx.Errorf("db GetInstanceListByDeployTaskId error") logx.Errorf("db GetInstanceListByDeployTaskId error")
return nil, errors.New(err.Error())
}
if len(list) == 0 {
err := l.svcCtx.Scheduler.AiStorages.DeleteDeployTaskById(t.Id)
if err != nil {
logx.Errorf("db DeleteByDeployTaskId error")
return nil, errors.New(err.Error())
}
continue continue
} }
deployTask := &DeployTask{ deployTask := &DeployTask{
@ -99,12 +110,12 @@ func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeplo
} }
tasks = append(tasks, deployTask) tasks = append(tasks, deployTask)
} }
return tasks return tasks, nil
} }
type DeployTask struct { type DeployTask struct {
Id int64 `json:"id,string"` Id int64 `json:"id,string"`
Name string `json:"name,string"` Name string `json:"name"`
Desc string `json:"desc,string"` Desc string `json:"desc"`
Instances []*models.AiInferDeployInstance `json:"instances,string"` Instances []*models.AiInferDeployInstance `json:"instances,string"`
} }

View File

@ -9,6 +9,7 @@ import (
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference/textInference" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference/textInference"
"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"
"strconv"
) )
type TextToTextInferenceLogic struct { type TextToTextInferenceLogic struct {
@ -27,27 +28,31 @@ func NewTextToTextInferenceLogic(ctx context.Context, svcCtx *svc.ServiceContext
func (l *TextToTextInferenceLogic) TextToTextInference(req *types.TextToTextInferenceReq) (resp *types.TextToTextInferenceResp, err error) { func (l *TextToTextInferenceLogic) TextToTextInference(req *types.TextToTextInferenceReq) (resp *types.TextToTextInferenceResp, err error) {
resp = &types.TextToTextInferenceResp{} resp = &types.TextToTextInferenceResp{}
opt := &option.InferOption{
TaskName: req.TaskName, instance, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(req.InstanceId)
TaskDesc: req.TaskDesc, if err != nil {
AdapterId: req.AdapterId, return nil, err
AiClusterIds: req.AiClusterIds, }
ModelName: req.ModelName, if instance == nil {
ModelType: req.ModelType, return nil, errors.New("instance is empty ")
} }
_, ok := l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[opt.AdapterId] adapterId := strconv.FormatInt(instance.AdapterId, 10)
if !ok {
return nil, errors.New("AdapterId does not exist") opt := &option.InferOption{
TaskName: req.TaskName,
TaskDesc: req.TaskDesc,
ModelType: req.ModelType,
AdapterId: adapterId,
} }
adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId) adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(opt.AdapterId)
inType, err := textInference.NewTextToText(opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap) infer, err := textInference.NewTextToText(opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, instance)
if err != nil { if err != nil {
return nil, err return nil, err
} }
textInfer, err := textInference.New(inType, opt, l.svcCtx.Scheduler.AiStorages, l.svcCtx.Scheduler.AiService.InferenceAdapterMap, adapterName) textInfer, err := textInference.New(infer, opt, l.svcCtx.Scheduler.AiStorages, adapterName)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -374,7 +374,7 @@ func (s *AiStorage) AddNoticeInfo(adapterId string, adapterName string, clusterI
} }
func (s *AiStorage) SaveInferDeployInstance(taskId int64, instanceId string, instanceName string, adapterId int64, func (s *AiStorage) SaveInferDeployInstance(taskId int64, instanceId string, instanceName string, adapterId int64,
adapterName string, clusterId int64, clusterName string, modelName string, modelType string, inferCard string) (int64, error) { adapterName string, clusterId int64, clusterName string, modelName string, modelType string, inferCard string, clusterType string) (int64, error) {
startTime := time.Now().Format(time.RFC3339) startTime := time.Now().Format(time.RFC3339)
// 构建主任务结构体 // 构建主任务结构体
insModel := models.AiInferDeployInstance{ insModel := models.AiInferDeployInstance{
@ -388,7 +388,8 @@ func (s *AiStorage) SaveInferDeployInstance(taskId int64, instanceId string, ins
ModelName: modelName, ModelName: modelName,
ModelType: modelType, ModelType: modelType,
InferCard: inferCard, InferCard: inferCard,
Status: constants.Stopped, ClusterType: clusterType,
Status: constants.Deploying,
CreateTime: startTime, CreateTime: startTime,
UpdateTime: startTime, UpdateTime: startTime,
} }
@ -464,6 +465,15 @@ func (s *AiStorage) UpdateDeployTask(task *models.AiDeployInstanceTask, needUpda
return nil return nil
} }
func (s *AiStorage) DeleteDeployTaskById(id int64) error {
tx := s.DbEngin.Delete(&models.AiDeployInstanceTask{}, id)
if tx.Error != nil {
logx.Errorf(tx.Error.Error())
return tx.Error
}
return nil
}
func (s *AiStorage) UpdateDeployTaskById(id int64) error { func (s *AiStorage) UpdateDeployTaskById(id int64) error {
task, err := s.GetDeployTaskById(id) task, err := s.GetDeployTaskById(id)
if err != nil { if err != nil {

View File

@ -17,30 +17,28 @@ type FilteredCluster struct {
urls []*inference.InferUrl urls []*inference.InferUrl
clusterId string clusterId string
clusterName string clusterName string
clusterType string
} }
type TextInference struct { type TextInference struct {
inference ITextInference inference ITextInference
opt *option.InferOption opt *option.InferOption
storage *database.AiStorage storage *database.AiStorage
inferAdapter map[string]map[string]inference.ICluster errMap map[string]string
errMap map[string]string adapterName string
adapterName string
} }
func New( func New(
inference ITextInference, inference ITextInference,
opt *option.InferOption, opt *option.InferOption,
storage *database.AiStorage, storage *database.AiStorage,
inferAdapter map[string]map[string]inference.ICluster,
adapterName string) (*TextInference, error) { adapterName string) (*TextInference, error) {
return &TextInference{ return &TextInference{
inference: inference, inference: inference,
opt: opt, opt: opt,
storage: storage, storage: storage,
inferAdapter: inferAdapter, adapterName: adapterName,
adapterName: adapterName, errMap: make(map[string]string),
errMap: make(map[string]string),
}, nil }, nil
} }

View File

@ -22,11 +22,12 @@ type TextToText struct {
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
instance *models.AiInferDeployInstance
cs []*FilteredCluster cs []*FilteredCluster
} }
func NewTextToText(opt *option.InferOption, storage *database.AiStorage, inferAdapter map[string]map[string]inference.ICluster) (*TextToText, error) { func NewTextToText(opt *option.InferOption, storage *database.AiStorage, inferAdapter map[string]map[string]inference.ICluster, instance *models.AiInferDeployInstance) (*TextToText, error) {
cs, err := filterClusters(opt, storage, inferAdapter) cs, err := filterClusters(inferAdapter, instance)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -64,7 +65,35 @@ func (tt *TextToText) SaveAiTask(id int64, adapterName string) error {
return nil return nil
} }
func filterClusters(opt *option.InferOption, storage *database.AiStorage, inferAdapter map[string]map[string]inference.ICluster) ([]*FilteredCluster, error) { func filterClusters(inferAdapter map[string]map[string]inference.ICluster, instance *models.AiInferDeployInstance) ([]*FilteredCluster, error) {
var cs []*FilteredCluster
var inferurls []*inference.InferUrl
clusterId := strconv.FormatInt(instance.ClusterId, 10)
adapterId := strconv.FormatInt(instance.AdapterId, 10)
r := http.Request{}
deployInstance, err := inferAdapter[adapterId][clusterId].GetInferDeployInstance(r.Context(), instance.InstanceId)
if err != nil {
return nil, err
}
var url inference.InferUrl
url.Url = deployInstance.InferUrl + inference.FORWARD_SLASH + CHAT
url.Card = deployInstance.InferCard
inferurls = append(inferurls, &url)
clusterType := deployInstance.ClusterType
clusterName := deployInstance.ClusterName
var f FilteredCluster
f.urls = inferurls
f.clusterId = clusterId
f.clusterName = clusterName
f.clusterType = clusterType
cs = append(cs, &f)
return cs, nil
}
func filterClustersTemp(opt *option.InferOption, storage *database.AiStorage, inferAdapter map[string]map[string]inference.ICluster) ([]*FilteredCluster, error) {
var wg sync.WaitGroup var wg sync.WaitGroup
var ch = make(chan *FilteredCluster, len(opt.AiClusterIds)) var ch = make(chan *FilteredCluster, len(opt.AiClusterIds))
var cs []*FilteredCluster var cs []*FilteredCluster

View File

@ -1158,10 +1158,14 @@ func (o *OctopusLink) GetInferDeployInstance(ctx context.Context, id string) (*i
url := strings.Replace(resp.Payload.Notebook.Tasks[0].Url, FORWARD_SLASH, "", -1) url := strings.Replace(resp.Payload.Notebook.Tasks[0].Url, FORWARD_SLASH, "", -1)
inferUrl := DOMAIN + url inferUrl := DOMAIN + url
var modelType string
var modelName string
var card string var card string
if resp.Payload.Notebook.Desc != "" { if resp.Payload.Notebook.Desc != "" {
str := strings.Split(resp.Payload.Notebook.Desc, FORWARD_SLASH) str := strings.Split(resp.Payload.Notebook.Desc, FORWARD_SLASH)
if len(str) == 3 { if len(str) == 3 {
modelType = str[0]
modelName = str[1]
card = str[2] card = str[2]
} }
} }
@ -1171,6 +1175,8 @@ func (o *OctopusLink) GetInferDeployInstance(ctx context.Context, id string) (*i
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.ModelType = modelType
ins.ModelName = modelName
ins.InferUrl = inferUrl ins.InferUrl = inferUrl
ins.InferCard = card ins.InferCard = card

View File

@ -5977,12 +5977,10 @@ type InferenceResult struct {
} }
type TextToTextInferenceReq struct { type TextToTextInferenceReq struct {
TaskName string `form:"taskName"` TaskName string `form:"taskName"`
TaskDesc string `form:"taskDesc"` TaskDesc string `form:"taskDesc"`
ModelName string `form:"modelName"` ModelType string `form:"modelType"`
ModelType string `form:"modelType"` InstanceId int64 `form:"instanceId"`
AdapterId string `form:"adapterId"`
AiClusterIds []string `form:"aiClusterIds"`
} }
type TextToTextInferenceResp struct { type TextToTextInferenceResp struct {
@ -6097,7 +6095,7 @@ type GetAdaptersByModelResp struct {
type AdapterAvail struct { type AdapterAvail struct {
AdapterId string `json:"adapterId"` AdapterId string `json:"adapterId"`
AdapterName string `json:"taskName"` AdapterName string `json:"adapterName"`
Clusters []*ClusterAvail `json:"clusters"` Clusters []*ClusterAvail `json:"clusters"`
} }