Skip to content

Commit be5d1b5

Browse files
authored
Add support for custom inference engine port (#1140)
Signed-off-by: Varun Gupta <[email protected]>
1 parent a727878 commit be5d1b5

File tree

5 files changed

+83
-4
lines changed

5 files changed

+83
-4
lines changed

development/app/config/templates/deployment/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ spec:
1919
labels:
2020
adapter.model.aibrix.ai/enabled: "true"
2121
model.aibrix.ai/name: "llama2-7b"
22+
model.aibrix.ai/port: "8000"
2223
app: "mock-llama2-7b"
2324
spec:
2425
serviceAccountName: mocked-app-sa

development/vllm/macos/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ spec:
1919
labels:
2020
adapter.model.aibrix.ai/enabled: "true"
2121
model.aibrix.ai/name: "facebook-opt-125m"
22+
model.aibrix.ai/port: "8000"
2223
app: "mock-facebook-opt-125m"
2324
spec:
2425
serviceAccountName: mocked-app-sa

pkg/types/router_context.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ import (
2323
"sync/atomic"
2424
"time"
2525

26+
"github.com/vllm-project/aibrix/pkg/utils"
2627
v1 "k8s.io/api/core/v1"
2728
)
2829

29-
const podMetricPort = "8000"
30-
3130
var nilPod = &v1.Pod{}
3231

3332
// RoutingAlgorithm defines the routing algorithms
@@ -93,7 +92,7 @@ func (r *RoutingContext) HasRouted() bool {
9392
}
9493

9594
func (r *RoutingContext) targetAddress(pod *v1.Pod) string {
96-
return fmt.Sprintf("%v:%v", pod.Status.PodIP, podMetricPort)
95+
return fmt.Sprintf("%v:%v", pod.Status.PodIP, utils.GetModelPortForPod(r.RequestID, pod))
9796
}
9897

9998
func (r *RoutingContext) reset(ctx context.Context, algorithms RoutingAlgorithm, model string, message string, requestID string, user *string) {

pkg/utils/pod.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package utils
1919
import (
2020
"context"
2121
"fmt"
22+
"strconv"
2223
"strings"
2324

2425
"k8s.io/klog/v2"
@@ -30,7 +31,9 @@ import (
3031
)
3132

3233
const (
33-
NAMESPACE = "aibrix-system"
34+
NAMESPACE = "aibrix-system"
35+
modelPortIdentifier = "model.aibrix.ai/port"
36+
defaultPodMetricPort = 8000
3437
)
3538

3639
// GeneratePodKey generates a key in the format "namespace/name" for a given pod.
@@ -238,3 +241,20 @@ func SelectRandomPod(pods []*v1.Pod, randomFn func(int) int) (*v1.Pod, error) {
238241
randomPod := readyPods[randomFn(len(readyPods))]
239242
return randomPod, nil
240243
}
244+
245+
func GetModelPortForPod(requestID string, pod *v1.Pod) int64 {
246+
value, ok := pod.Labels[modelPortIdentifier]
247+
if !ok {
248+
klog.Warningf("requestID: %v, pod: %v is missing port identifier label: %v, hence default to port: %v",
249+
requestID, pod.Name, modelPortIdentifier, defaultPodMetricPort)
250+
return defaultPodMetricPort
251+
}
252+
253+
modelPort, err := strconv.ParseInt(value, 10, 32)
254+
if err != nil {
255+
klog.Warningf("requestID: %v, pod: %v has incorrect value: %v for port identifier label: %v, hence default to port: %v",
256+
requestID, pod.Name, value, modelPortIdentifier, defaultPodMetricPort)
257+
modelPort = defaultPodMetricPort
258+
}
259+
return modelPort
260+
}

pkg/utils/pod_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ package utils
1818
import (
1919
"fmt"
2020
"math/rand"
21+
"testing"
2122
"time"
2223

2324
. "github.com/onsi/ginkgo"
2425
. "github.com/onsi/gomega"
26+
"github.com/stretchr/testify/assert"
2527
v1 "k8s.io/api/core/v1"
2628
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2729
)
@@ -81,3 +83,59 @@ var _ = Describe("Pod", func() {
8183
Expect(modified).To(Equal(expected))
8284
})
8385
})
86+
87+
func TestModePortForPod(t *testing.T) {
88+
testcases := []struct {
89+
message string
90+
pod *v1.Pod
91+
expectedPort int64
92+
}{
93+
{
94+
message: "read port from pod labels",
95+
pod: &v1.Pod{
96+
ObjectMeta: metav1.ObjectMeta{
97+
Name: "p1",
98+
Labels: map[string]string{
99+
"model.aibrix.ai/port": "9000",
100+
},
101+
},
102+
},
103+
expectedPort: 9000,
104+
},
105+
{
106+
message: "incorrect model port label value",
107+
pod: &v1.Pod{
108+
ObjectMeta: metav1.ObjectMeta{
109+
Name: "p1",
110+
Labels: map[string]string{
111+
"model.aibrix.ai/port": "port",
112+
},
113+
},
114+
},
115+
expectedPort: 8000,
116+
},
117+
{
118+
message: "return default port if not configured in pod labels",
119+
pod: &v1.Pod{
120+
ObjectMeta: metav1.ObjectMeta{
121+
Name: "p1",
122+
Labels: map[string]string{},
123+
},
124+
},
125+
expectedPort: 8000,
126+
},
127+
{
128+
message: "return default port if no label is present",
129+
pod: &v1.Pod{
130+
ObjectMeta: metav1.ObjectMeta{
131+
Name: "p1",
132+
},
133+
},
134+
expectedPort: 8000,
135+
},
136+
}
137+
138+
for _, tt := range testcases {
139+
assert.Equal(t, tt.expectedPort, GetModelPortForPod("1", tt.pod), tt.message)
140+
}
141+
}

0 commit comments

Comments
 (0)