From 5df65ad595e8f7d765b4a73440334daeeedf7cfc Mon Sep 17 00:00:00 2001 From: bjwswang Date: Wed, 13 Dec 2023 14:44:48 +0000 Subject: [PATCH] feat: able to configure worker type when create and update Signed-off-by: bjwswang --- api/base/v1alpha1/worker.go | 4 + .../go-server/graph/generated/generated.go | 106 +++++++++++++++++- .../go-server/graph/generated/models_gen.go | 18 +++ .../go-server/graph/schema/worker.gql | 4 + .../go-server/graph/schema/worker.graphqls | 27 +++++ graphql-server/go-server/pkg/worker/worker.go | 17 +++ 6 files changed, 174 insertions(+), 2 deletions(-) diff --git a/api/base/v1alpha1/worker.go b/api/base/v1alpha1/worker.go index 0fd121f17..4e4f52d74 100644 --- a/api/base/v1alpha1/worker.go +++ b/api/base/v1alpha1/worker.go @@ -35,6 +35,10 @@ const ( LabelWorkerType = Group + "/worker-type" ) +func DefaultWorkerType() WorkerType { + return WorkerTypeFastchatNormal +} + func (worker Worker) Type() WorkerType { if worker.Spec.Type == "" { // use `fastchat` by default diff --git a/graphql-server/go-server/graph/generated/generated.go b/graphql-server/go-server/graph/generated/generated.go index af2f7898a..f80604ac1 100644 --- a/graphql-server/go-server/graph/generated/generated.go +++ b/graphql-server/go-server/graph/generated/generated.go @@ -458,6 +458,7 @@ type ComplexityRoot struct { Namespace func(childComplexity int) int Resources func(childComplexity int) int Status func(childComplexity int) int + Type func(childComplexity int) int UpdateTimestamp func(childComplexity int) int } @@ -2664,6 +2665,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Worker.Status(childComplexity), true + case "Worker.type": + if e.complexity.Worker.Type == nil { + break + } + + return e.complexity.Worker.Type(childComplexity), true + case "Worker.updateTimestamp": if e.complexity.Worker.UpdateTimestamp == nil { break @@ -4550,6 +4558,15 @@ type Worker { """更新时间""" updateTimestamp: Time + """ + Worker类型 + 支持两种类型: + - "fastchat" : fastchat提供的通用的推理服务模式 + - "fastchat-vllm" : fastchat提供的采用VLLM推理加速的推理服务模式 + 规则: 如果为空,则默认为 "fastchat" + """ + type: String + """ worker对应的模型 规则: 相同namespace下的模型名称 @@ -4594,6 +4611,15 @@ input CreateWorkerInput{ """模型资源描述""" description: String + """ + Worker类型 + 支持两种类型: + - "fastchat" : fastchat提供的通用的推理服务模式 + - "fastchat-vllm" : fastchat提供的采用VLLM推理加速的推理服务模式 + 规则: 如果为空,则默认为 "fastchat" + """ + type: String + """ worker对应的模型 规则: 必须指定模型准确的namespace @@ -4625,6 +4651,15 @@ input UpdateWorkerInput { """模型资源描述""" description: String + """ + Worker类型 + 支持两种类型: + - "fastchat" : fastchat提供的通用的推理服务模式 + - "fastchat-vllm" : fastchat提供的采用VLLM推理加速的推理服务模式 + 规则: 如果为空,则不更新;如果type类型与当前类型相同,则不更新 + """ + type: String + """ worker运行所需的资源 """ @@ -18087,6 +18122,47 @@ func (ec *executionContext) fieldContext_Worker_updateTimestamp(ctx context.Cont return fc, nil } +func (ec *executionContext) _Worker_type(ctx context.Context, field graphql.CollectedField, obj *Worker) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Worker_type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Type, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Worker_type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Worker", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Worker_model(ctx context.Context, field graphql.CollectedField, obj *Worker) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Worker_model(ctx, field) if err != nil { @@ -18378,6 +18454,8 @@ func (ec *executionContext) fieldContext_WorkerMutation_createWorker(ctx context return ec.fieldContext_Worker_creationTimestamp(ctx, field) case "updateTimestamp": return ec.fieldContext_Worker_updateTimestamp(ctx, field) + case "type": + return ec.fieldContext_Worker_type(ctx, field) case "model": return ec.fieldContext_Worker_model(ctx, field) case "modelTypes": @@ -18465,6 +18543,8 @@ func (ec *executionContext) fieldContext_WorkerMutation_updateWorker(ctx context return ec.fieldContext_Worker_creationTimestamp(ctx, field) case "updateTimestamp": return ec.fieldContext_Worker_updateTimestamp(ctx, field) + case "type": + return ec.fieldContext_Worker_type(ctx, field) case "model": return ec.fieldContext_Worker_model(ctx, field) case "modelTypes": @@ -18604,6 +18684,8 @@ func (ec *executionContext) fieldContext_WorkerQuery_getWorker(ctx context.Conte return ec.fieldContext_Worker_creationTimestamp(ctx, field) case "updateTimestamp": return ec.fieldContext_Worker_updateTimestamp(ctx, field) + case "type": + return ec.fieldContext_Worker_type(ctx, field) case "model": return ec.fieldContext_Worker_model(ctx, field) case "modelTypes": @@ -21887,7 +21969,7 @@ func (ec *executionContext) unmarshalInputCreateWorkerInput(ctx context.Context, asMap[k] = v } - fieldsInOrder := [...]string{"name", "namespace", "displayName", "description", "model", "resources"} + fieldsInOrder := [...]string{"name", "namespace", "displayName", "description", "type", "model", "resources"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -21930,6 +22012,15 @@ func (ec *executionContext) unmarshalInputCreateWorkerInput(ctx context.Context, return it, err } it.Description = data + case "type": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("type")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Type = data case "model": var err error @@ -23613,7 +23704,7 @@ func (ec *executionContext) unmarshalInputUpdateWorkerInput(ctx context.Context, asMap[k] = v } - fieldsInOrder := [...]string{"name", "namespace", "labels", "annotations", "displayName", "description", "resources"} + fieldsInOrder := [...]string{"name", "namespace", "labels", "annotations", "displayName", "description", "type", "resources"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -23674,6 +23765,15 @@ func (ec *executionContext) unmarshalInputUpdateWorkerInput(ctx context.Context, return it, err } it.Description = data + case "type": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("type")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Type = data case "resources": var err error @@ -27746,6 +27846,8 @@ func (ec *executionContext) _Worker(ctx context.Context, sel ast.SelectionSet, o out.Values[i] = ec._Worker_creationTimestamp(ctx, field, obj) case "updateTimestamp": out.Values[i] = ec._Worker_updateTimestamp(ctx, field, obj) + case "type": + out.Values[i] = ec._Worker_type(ctx, field, obj) case "model": out.Values[i] = ec._Worker_model(ctx, field, obj) if out.Values[i] == graphql.Null { diff --git a/graphql-server/go-server/graph/generated/models_gen.go b/graphql-server/go-server/graph/generated/models_gen.go index c6c15d964..8db446c2c 100644 --- a/graphql-server/go-server/graph/generated/models_gen.go +++ b/graphql-server/go-server/graph/generated/models_gen.go @@ -217,6 +217,12 @@ type CreateWorkerInput struct { DisplayName *string `json:"displayName,omitempty"` // 模型资源描述 Description *string `json:"description,omitempty"` + // Worker类型 + // 支持两种类型: + // - "fastchat" : fastchat提供的通用的推理服务模式 + // - "fastchat-vllm" : fastchat提供的采用VLLM推理加速的推理服务模式 + // 规则: 如果为空,则默认为 "fastchat" + Type *string `json:"type,omitempty"` // worker对应的模型 // 规则: 必须指定模型准确的namespace // 规则: 必填 @@ -1056,6 +1062,12 @@ type UpdateWorkerInput struct { DisplayName *string `json:"displayName,omitempty"` // 模型资源描述 Description *string `json:"description,omitempty"` + // Worker类型 + // 支持两种类型: + // - "fastchat" : fastchat提供的通用的推理服务模式 + // - "fastchat-vllm" : fastchat提供的采用VLLM推理加速的推理服务模式 + // 规则: 如果为空,则不更新;如果type类型与当前类型相同,则不更新 + Type *string `json:"type,omitempty"` // worker运行所需的资源 Resources *ResourcesInput `json:"resources,omitempty"` } @@ -1136,6 +1148,12 @@ type Worker struct { CreationTimestamp *time.Time `json:"creationTimestamp,omitempty"` // 更新时间 UpdateTimestamp *time.Time `json:"updateTimestamp,omitempty"` + // Worker类型 + // 支持两种类型: + // - "fastchat" : fastchat提供的通用的推理服务模式 + // - "fastchat-vllm" : fastchat提供的采用VLLM推理加速的推理服务模式 + // 规则: 如果为空,则默认为 "fastchat" + Type *string `json:"type,omitempty"` // worker对应的模型 // 规则: 相同namespace下的模型名称 // 规则: 必填 diff --git a/graphql-server/go-server/graph/schema/worker.gql b/graphql-server/go-server/graph/schema/worker.gql index 3459b3db8..29c56f0dd 100644 --- a/graphql-server/go-server/graph/schema/worker.gql +++ b/graphql-server/go-server/graph/schema/worker.gql @@ -19,6 +19,7 @@ query listWorkers($input: ListWorkerInput!){ status message updateTimestamp + type model { name namespace @@ -50,6 +51,7 @@ query getWorker($name: String!, $namespace: String!) { creator displayName description + type status message updateTimestamp @@ -82,6 +84,7 @@ mutation createWorker($input: CreateWorkerInput!) { creator displayName description + type status message updateTimestamp @@ -114,6 +117,7 @@ mutation updateWorker($input: UpdateWorkerInput) { creator displayName description + type status message updateTimestamp diff --git a/graphql-server/go-server/graph/schema/worker.graphqls b/graphql-server/go-server/graph/schema/worker.graphqls index f4e7dcbd0..67baa239e 100644 --- a/graphql-server/go-server/graph/schema/worker.graphqls +++ b/graphql-server/go-server/graph/schema/worker.graphqls @@ -65,6 +65,15 @@ type Worker { """更新时间""" updateTimestamp: Time + """ + Worker类型 + 支持两种类型: + - "fastchat" : fastchat提供的通用的推理服务模式 + - "fastchat-vllm" : fastchat提供的采用VLLM推理加速的推理服务模式 + 规则: 如果为空,则默认为 "fastchat" + """ + type: String + """ worker对应的模型 规则: 相同namespace下的模型名称 @@ -109,6 +118,15 @@ input CreateWorkerInput{ """模型资源描述""" description: String + """ + Worker类型 + 支持两种类型: + - "fastchat" : fastchat提供的通用的推理服务模式 + - "fastchat-vllm" : fastchat提供的采用VLLM推理加速的推理服务模式 + 规则: 如果为空,则默认为 "fastchat" + """ + type: String + """ worker对应的模型 规则: 必须指定模型准确的namespace @@ -140,6 +158,15 @@ input UpdateWorkerInput { """模型资源描述""" description: String + """ + Worker类型 + 支持两种类型: + - "fastchat" : fastchat提供的通用的推理服务模式 + - "fastchat-vllm" : fastchat提供的采用VLLM推理加速的推理服务模式 + 规则: 如果为空,则不更新;如果type类型与当前类型相同,则不更新 + """ + type: String + """ worker运行所需的资源 """ diff --git a/graphql-server/go-server/pkg/worker/worker.go b/graphql-server/go-server/pkg/worker/worker.go index 1bcfd7e2d..5a1209290 100644 --- a/graphql-server/go-server/pkg/worker/worker.go +++ b/graphql-server/go-server/pkg/worker/worker.go @@ -73,6 +73,8 @@ func worker2model(ctx context.Context, c dynamic.Interface, obj *unstructured.Un NvidiaGpu: &nvidiaGPUStr, } + workerType := string(worker.Type()) + // wrap Worker w := generated.Worker{ ID: &id, @@ -83,6 +85,7 @@ func worker2model(ctx context.Context, c dynamic.Interface, obj *unstructured.Un Annotations: graphqlutils.MapStr2Any(obj.GetAnnotations()), DisplayName: &worker.Spec.DisplayName, Description: &worker.Spec.Description, + Type: &workerType, Status: &status, CreationTimestamp: &creationtimestamp, UpdateTimestamp: &updateTime, @@ -128,6 +131,12 @@ func CreateWorker(ctx context.Context, c dynamic.Interface, input generated.Crea } } + // Use `fastchat` as the default worker type + workerType := v1alpha1.DefaultWorkerType() + if input.Type != nil { + workerType = v1alpha1.WorkerType(*input.Type) + } + worker := v1alpha1.Worker{ ObjectMeta: metav1.ObjectMeta{ Name: input.Name, @@ -142,6 +151,7 @@ func CreateWorker(ctx context.Context, c dynamic.Interface, input generated.Crea DisplayName: displayName, Description: description, }, + Type: workerType, Model: &v1alpha1.TypedObjectReference{ Name: input.Model.Name, Namespace: &modelNs, @@ -196,6 +206,13 @@ func UpdateWorker(ctx context.Context, c dynamic.Interface, input *generated.Upd worker.Spec.Description = *input.Description } + // worker type + if input.Type != nil { + if worker.Type() != v1alpha1.WorkerType(*input.Type) { + worker.Spec.Type = v1alpha1.WorkerType(*input.Type) + } + } + // resources if input.Resources != nil { // cpu & memory