Skip to content

Commit

Permalink
Add params support for Server resource (#214)
Browse files Browse the repository at this point in the history
Required for providing additional params to e.g. basaran image.
  • Loading branch information
samos123 committed Aug 23, 2023
1 parent a2af101 commit 6ba4616
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/v1/server_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
)

Expand All @@ -21,6 +22,9 @@ type ServerSpec struct {

// Model references the Model object to be served.
Model ObjectRef `json:"model,omitempty"`

// Params will be passed into the loading process as environment variables.
Params map[string]intstr.IntOrString `json:"params,omitempty"`
}

// ServerStatus defines the observed state of Server
Expand Down Expand Up @@ -53,6 +57,10 @@ type Server struct {
Status ServerStatus `json:"status,omitempty"`
}

func (s *Server) GetParams() map[string]intstr.IntOrString {
return s.Spec.Params
}

func (s *Server) GetBuild() *Build {
return s.Spec.Build
}
Expand Down
7 changes: 7 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cmd/controllermanager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ func main() {
Scheme: mgr.GetScheme(),
Cloud: cld,
SCI: sciClient,
ParamsReconciler: &controller.ParamsReconciler{
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
},
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Server")
os.Exit(1)
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/substratus.ai_servers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ spec:
required:
- name
type: object
params:
additionalProperties:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
description: Params will be passed into the loading process as environment
variables.
type: object
resources:
description: Resources are the compute resources required by the container.
properties:
Expand Down
1 change: 1 addition & 0 deletions docs/api/generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ _Appears in:_
| `build` _[Build](#build)_ | Build specifies how to build an image. |
| `resources` _[Resources](#resources)_ | Resources are the compute resources required by the container. |
| `model` _[ObjectRef](#objectref)_ | Model references the Model object to be served. |
| `params` _object (keys:string, values:IntOrString)_ | Params will be passed into the loading process as environment variables. |


### ServerStatus
Expand Down
13 changes: 13 additions & 0 deletions examples/falcon-7b-instruct/server-4bit-any-gpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: substratus.ai/v1
kind: Server
metadata:
name: falcon-7b-instruct
spec:
image: substratusai/model-server-basaran
model:
name: falcon-7b-instruct
params:
load_in_4bit: "true"
resources:
gpu:
count: 1
4 changes: 4 additions & 0 deletions internal/controller/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func TestMain(m *testing.M) {
Scheme: mgr.GetScheme(),
Cloud: testCloud,
SCI: sciClient,
ParamsReconciler: &controller.ParamsReconciler{
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
},
}).SetupWithManager(mgr)
requireNoError(err)
err = (&controller.BuildReconciler{
Expand Down
11 changes: 11 additions & 0 deletions internal/controller/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type ServerReconciler struct {
Cloud cloud.Cloud
SCI sci.ControllerClient

*ParamsReconciler

// log should be used outside the context of Reconcile()
log logr.Logger
}
Expand Down Expand Up @@ -61,6 +63,10 @@ func (r *ServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
return ctrl.Result{}, nil
}

if result, err := r.ReconcileParamsConfigMap(ctx, &server); !result.success {
return result.Result, err
}

if result, err := r.reconcileServer(ctx, &server); !result.success {
return result.Result, err
}
Expand Down Expand Up @@ -142,6 +148,7 @@ func (r *ServerReconciler) serverDeployment(server *apiv1.Server, model *apiv1.M
Image: server.GetImage(),
ImagePullPolicy: "Always",
Command: server.Spec.Command,
Env: paramsToEnv(server.Spec.Params),
Ports: []corev1.ContainerPort{
{
Name: modelServerHTTPServePortName,
Expand All @@ -166,6 +173,10 @@ func (r *ServerReconciler) serverDeployment(server *apiv1.Server, model *apiv1.M
},
}

if err := mountParamsConfigMap(&deploy.Spec.Template.Spec, server, containerName); err != nil {
return nil, fmt.Errorf("mounting params configmap: %w", err)
}

if err := r.Cloud.MountBucket(&deploy.Spec.Template.ObjectMeta, &deploy.Spec.Template.Spec, model, cloud.MountBucketConfig{
Name: "model",
Mounts: []cloud.BucketMount{
Expand Down

0 comments on commit 6ba4616

Please sign in to comment.