Merge pull request 'updated texttotextinference logics' (#301) from tzwang/pcm-coordinator:master into master

Former-commit-id: bcdc325f56973b49109a903a89c86b161b9a14f4
This commit is contained in:
tzwang 2024-09-04 16:40:06 +08:00
commit 90613ec81c
6 changed files with 68 additions and 40 deletions

View File

@ -79,10 +79,8 @@ type (
TextToTextInferenceReq{
TaskName string `form:"taskName"`
TaskDesc string `form:"taskDesc"`
ModelName string `form:"modelName"`
ModelType string `form:"modelType"`
AdapterId string `form:"adapterId"`
AiClusterIds []string `form:"aiClusterIds"`
InstanceId int64 `form:"instanceId"`
}
TextToTextInferenceResp{

View File

@ -114,8 +114,8 @@ func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeplo
}
type DeployTask struct {
Id int64 `json:"id,string"`
Name string
Desc string
Id int64 `json:"id,string"`
Name string `json:"name"`
Desc string `json:"desc"`
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/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"strconv"
)
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) {
resp = &types.TextToTextInferenceResp{}
opt := &option.InferOption{
TaskName: req.TaskName,
TaskDesc: req.TaskDesc,
AdapterId: req.AdapterId,
AiClusterIds: req.AiClusterIds,
ModelName: req.ModelName,
ModelType: req.ModelType,
instance, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(req.InstanceId)
if err != nil {
return nil, err
}
if instance == nil {
return nil, errors.New("instance is empty ")
}
_, ok := l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[opt.AdapterId]
if !ok {
return nil, errors.New("AdapterId does not exist")
adapterId := strconv.FormatInt(instance.AdapterId, 10)
opt := &option.InferOption{
TaskName: req.TaskName,
TaskDesc: req.TaskDesc,
ModelType: req.ModelType,
AdapterId: 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 {
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 {
return nil, err
}

View File

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

View File

@ -22,11 +22,12 @@ type TextToText struct {
opt *option.InferOption
storage *database.AiStorage
inferAdapter map[string]map[string]inference.ICluster
instance *models.AiInferDeployInstance
cs []*FilteredCluster
}
func NewTextToText(opt *option.InferOption, storage *database.AiStorage, inferAdapter map[string]map[string]inference.ICluster) (*TextToText, error) {
cs, err := filterClusters(opt, storage, inferAdapter)
func NewTextToText(opt *option.InferOption, storage *database.AiStorage, inferAdapter map[string]map[string]inference.ICluster, instance *models.AiInferDeployInstance) (*TextToText, error) {
cs, err := filterClusters(inferAdapter, instance)
if err != nil {
return nil, err
}
@ -64,7 +65,35 @@ func (tt *TextToText) SaveAiTask(id int64, adapterName string) error {
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 ch = make(chan *FilteredCluster, len(opt.AiClusterIds))
var cs []*FilteredCluster

View File

@ -5976,12 +5976,10 @@ type InferenceResult struct {
}
type TextToTextInferenceReq struct {
TaskName string `form:"taskName"`
TaskDesc string `form:"taskDesc"`
ModelName string `form:"modelName"`
ModelType string `form:"modelType"`
AdapterId string `form:"adapterId"`
AiClusterIds []string `form:"aiClusterIds"`
TaskName string `form:"taskName"`
TaskDesc string `form:"taskDesc"`
ModelType string `form:"modelType"`
InstanceId int64 `form:"instanceId"`
}
type TextToTextInferenceResp struct {