forked from llm-d/llm-d-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnector_nixlv2_test.go
More file actions
1246 lines (992 loc) · 48.4 KB
/
Copy pathconnector_nixlv2_test.go
File metadata and controls
1246 lines (992 loc) · 48.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2025 The llm-d Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package proxy
import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"net/url"
"strconv"
"strings"
"time"
"github.com/llm-d/llm-d-router/test/sidecar/mock"
. "github.com/onsi/ginkgo/v2" // nolint:revive
. "github.com/onsi/gomega" // nolint:revive
"github.com/llm-d/llm-d-router/pkg/common/routing"
)
const eventStreamContentType = "text/event-stream"
var _ = Describe("NIXL Connector (v2)", func() {
var testInfo *sidecarTestInfo
BeforeEach(func() {
testInfo = sidecarConnectionTestSetup(KVConnectorNIXLV2)
})
startProxy := func() string {
go func() {
defer GinkgoRecover()
testInfo.proxy.allowlistValidator = &AllowlistValidator{enabled: false}
err := testInfo.proxy.Start(testInfo.ctx)
Expect(err).ToNot(HaveOccurred())
testInfo.stoppedCh <- struct{}{}
}()
<-testInfo.proxy.readyCh
DeferCleanup(func() {
testInfo.cancelFn()
<-testInfo.stoppedCh
})
return "http://" + testInfo.proxy.addr.String()
}
sendChatCompletionsRequest := func(proxyBaseAddr string) map[string]any {
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ChatCompletionsPath, bytes.NewReader([]byte(chatCompletionsRequestBody)))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
defer rp.Body.Close()
responseBody, err := io.ReadAll(rp.Body)
Expect(err).ToNot(HaveOccurred())
Expect(rp.StatusCode).To(Equal(http.StatusOK), string(responseBody))
var response map[string]any
Expect(json.Unmarshal(responseBody, &response)).To(Succeed())
return response
}
sendStreamingChatCompletionsRequest := func(proxyBaseAddr string) string {
body := `{
"model": "Qwen/Qwen2-0.5B",
"messages": [
{"role": "user", "content": "Hello"}
],
"max_tokens": 50,
"stream": true,
"stream_options": {"include_usage": true}
}`
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ChatCompletionsPath, bytes.NewReader([]byte(body)))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
defer rp.Body.Close()
responseBody, err := io.ReadAll(rp.Body)
Expect(err).ToNot(HaveOccurred())
Expect(rp.StatusCode).To(Equal(http.StatusOK), string(responseBody))
Expect(rp.Header.Get("Content-Type")).To(ContainSubstring(eventStreamContentType))
return string(responseBody)
}
cachedTokensFromResponse := func(response map[string]any) float64 {
usage, ok := response["usage"].(map[string]any)
Expect(ok).To(BeTrue())
details, ok := usage["prompt_tokens_details"].(map[string]any)
Expect(ok).To(BeTrue())
cachedTokens, ok := details["cached_tokens"].(float64)
Expect(ok).To(BeTrue())
return cachedTokens
}
It("should successfully send request to 1. prefill 2. decode with the correct fields", func() {
proxyBaseAddr := startProxy()
By("sending a /v1/chat/completions request with prefill header")
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ChatCompletionsPath, bytes.NewReader([]byte(chatCompletionsRequestBody)))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
if rp.StatusCode != 200 {
bp, _ := io.ReadAll(rp.Body) //nolint:errcheck
Fail(string(bp))
}
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.prefillHandler.CompletionRequests).To(HaveLen(1))
prq1 := testInfo.prefillHandler.CompletionRequests[0]
Expect(prq1).To(HaveKey(requestFieldKVTransferParams))
kvTransferParams, ok := prq1[requestFieldKVTransferParams].(map[string]any)
Expect(ok).To(BeTrue())
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldDoRemoteDecode, true))
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldDoRemotePrefill, false))
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldRemoteBlockIDs, BeNil()))
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldRemoteEngineID, BeNil()))
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldRemoteHost, BeNil()))
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldRemotePort, BeNil()))
Expect(prq1).To(HaveKeyWithValue("max_tokens", BeNumerically("==", 1)))
Expect(prq1).To(HaveKeyWithValue("stream", false))
Expect(prq1).ToNot(HaveKey("stream_options"))
Expect(testInfo.prefillHandler.CompletionResponses).To(HaveLen(1))
prp1 := testInfo.prefillHandler.CompletionResponses[0]
Expect(prp1).To(HaveKey(requestFieldKVTransferParams))
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.decodeHandler.CompletionRequests).To(HaveLen(1))
responseBody, err := io.ReadAll(rp.Body)
Expect(err).ToNot(HaveOccurred())
var response map[string]any
Expect(json.Unmarshal(responseBody, &response)).To(Succeed())
usage := response["usage"].(map[string]any)
details := usage["prompt_tokens_details"].(map[string]any)
Expect(details["cached_tokens"]).To(BeNumerically("==", 7))
})
It("should add prefiller cached tokens when decoder usage details omit cached_tokens", func() {
testInfo.decodeHandler.RawResponse = `{"id":"chatcmpl-test","object":"chat.completion","choices":[],"usage":{"prompt_tokens":64,"completion_tokens":1,"total_tokens":65,"prompt_tokens_details":{}}}`
proxyBaseAddr := startProxy()
response := sendChatCompletionsRequest(proxyBaseAddr)
Expect(cachedTokensFromResponse(response)).To(BeNumerically("==", 7))
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
})
It("should create prompt token details when decoder usage omits them", func() {
testInfo.decodeHandler.RawResponse = `{"id":"chatcmpl-test","object":"chat.completion","choices":[],"usage":{"prompt_tokens":64,"completion_tokens":1,"total_tokens":65}}`
proxyBaseAddr := startProxy()
response := sendChatCompletionsRequest(proxyBaseAddr)
Expect(cachedTokensFromResponse(response)).To(BeNumerically("==", 7))
})
It("should return zero cached tokens when prefiller does not report cached tokens", func() {
testInfo.prefillHandler.RawResponse = `{"kv_transfer_params":{"remote_block_ids":[1,2,3],"remote_engine_id":"5b5fb28f-3f30-4bdd-9a36-958d52459200","remote_host":"ahost","remote_port":4032},"usage":{"prompt_tokens":64,"completion_tokens":1,"total_tokens":65,"prompt_tokens_details":{}}}`
testInfo.decodeHandler.RawResponse = `{"id":"chatcmpl-test","object":"chat.completion","choices":[],"usage":{"prompt_tokens":64,"completion_tokens":1,"total_tokens":65,"prompt_tokens_details":{"cached_tokens":49}}}`
proxyBaseAddr := startProxy()
response := sendChatCompletionsRequest(proxyBaseAddr)
Expect(cachedTokensFromResponse(response)).To(BeNumerically("==", 0))
})
It("should overwrite decoder cached tokens when prefiller reports zero cached tokens", func() {
testInfo.prefillHandler.RawResponse = `{"kv_transfer_params":{"remote_block_ids":[1,2,3],"remote_engine_id":"5b5fb28f-3f30-4bdd-9a36-958d52459200","remote_host":"ahost","remote_port":4032},"usage":{"prompt_tokens":64,"completion_tokens":1,"total_tokens":65,"prompt_tokens_details":{"cached_tokens":0}}}`
testInfo.decodeHandler.RawResponse = `{"id":"chatcmpl-test","object":"chat.completion","choices":[],"usage":{"prompt_tokens":64,"completion_tokens":1,"total_tokens":65,"prompt_tokens_details":{"cached_tokens":49}}}`
proxyBaseAddr := startProxy()
response := sendChatCompletionsRequest(proxyBaseAddr)
Expect(cachedTokensFromResponse(response)).To(BeNumerically("==", 0))
})
It("should replace cached tokens in streamed usage chunks", func() {
testInfo.decodeHandler.RawResponseType = eventStreamContentType
testInfo.decodeHandler.RawResponse = "data: {\"choices\":[{\"delta\":{\"content\":\"hello\"}}]}\n\ndata: {\"choices\":[],\"usage\":{\"prompt_tokens\":64,\"completion_tokens\":1,\"total_tokens\":65,\"prompt_tokens_details\":{\"cached_tokens\":49}}}\n\ndata: [DONE]\n"
proxyBaseAddr := startProxy()
responseBody := sendStreamingChatCompletionsRequest(proxyBaseAddr)
Expect(responseBody).To(ContainSubstring(`"content":"hello"`))
Expect(responseBody).To(ContainSubstring(`"cached_tokens":7`))
Expect(responseBody).ToNot(ContainSubstring(`"cached_tokens":49`))
Expect(responseBody).To(ContainSubstring("data: [DONE]"))
})
It("should create cached token details in streamed usage chunks that omit them", func() {
testInfo.decodeHandler.RawResponseType = eventStreamContentType
testInfo.decodeHandler.RawResponse = "data: {\"choices\":[],\"usage\":{\"prompt_tokens\":64,\"completion_tokens\":1,\"total_tokens\":65}}\n\ndata: [DONE]\n"
proxyBaseAddr := startProxy()
responseBody := sendStreamingChatCompletionsRequest(proxyBaseAddr)
Expect(responseBody).To(ContainSubstring(`"prompt_tokens_details":{"cached_tokens":7}`))
Expect(responseBody).To(ContainSubstring("data: [DONE]"))
})
It("should return zero cached tokens in streamed usage when prefiller does not report cached tokens", func() {
testInfo.prefillHandler.RawResponse = `{"kv_transfer_params":{"remote_block_ids":[1,2,3],"remote_engine_id":"5b5fb28f-3f30-4bdd-9a36-958d52459200","remote_host":"ahost","remote_port":4032},"usage":{"prompt_tokens":64,"completion_tokens":1,"total_tokens":65,"prompt_tokens_details":{}}}`
testInfo.decodeHandler.RawResponseType = eventStreamContentType
testInfo.decodeHandler.RawResponse = "data: {\"choices\":[],\"usage\":{\"prompt_tokens\":64,\"completion_tokens\":1,\"total_tokens\":65,\"prompt_tokens_details\":{\"cached_tokens\":49}}}\n\ndata: [DONE]\n"
proxyBaseAddr := startProxy()
responseBody := sendStreamingChatCompletionsRequest(proxyBaseAddr)
Expect(responseBody).To(ContainSubstring(`"cached_tokens":0`))
Expect(responseBody).ToNot(ContainSubstring(`"cached_tokens":49`))
Expect(responseBody).To(ContainSubstring("data: [DONE]"))
})
// Messages API tests — verify /v1/messages routes through the disaggregation
// handler with the same token-limit fields as chat completions.
It("should successfully send messages API request to 1. prefill 2. decode with the correct fields", func() {
proxyBaseAddr := startProxy()
By("sending a /v1/messages request with prefill header")
body := `{
"model": "claude-3-5-sonnet-20241022",
"messages": [
{"role": "user", "content": "Hello"}
],
"max_tokens": 50
}`
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+MessagesPath, bytes.NewReader([]byte(body)))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
defer rp.Body.Close()
responseBody, err := io.ReadAll(rp.Body)
Expect(err).ToNot(HaveOccurred())
Expect(rp.StatusCode).To(Equal(http.StatusOK), string(responseBody))
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.prefillHandler.CompletionRequests).To(HaveLen(1))
prq1 := testInfo.prefillHandler.CompletionRequests[0]
Expect(prq1).To(HaveKey(requestFieldKVTransferParams))
kvTransferParams, ok := prq1[requestFieldKVTransferParams].(map[string]any)
Expect(ok).To(BeTrue())
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldDoRemoteDecode, true))
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldDoRemotePrefill, false))
Expect(prq1).To(HaveKeyWithValue("max_tokens", BeNumerically("==", 1)))
Expect(prq1).To(HaveKeyWithValue("stream", false))
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.decodeHandler.CompletionRequests).To(HaveLen(1))
})
It("should pass through messages API request when no prefill header is set", func() {
proxyBaseAddr := startProxy()
By("sending a /v1/messages request without prefill header")
body := `{
"model": "claude-3-5-sonnet-20241022",
"messages": [
{"role": "user", "content": "Hello"}
],
"max_tokens": 50
}`
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+MessagesPath, bytes.NewReader([]byte(body)))
Expect(err).ToNot(HaveOccurred())
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
defer rp.Body.Close()
responseBody, err := io.ReadAll(rp.Body)
Expect(err).ToNot(HaveOccurred())
Expect(rp.StatusCode).To(Equal(http.StatusOK), string(responseBody))
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 0))
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
})
// Responses API tests — exercise the same NIXL v2 connector with
// /v1/responses and the max_output_tokens field instead of max_tokens.
It("should successfully send responses API request to 1. prefill 2. decode with the correct fields", func() {
By("starting the proxy")
go func() {
defer GinkgoRecover()
testInfo.proxy.allowlistValidator = &AllowlistValidator{enabled: false}
err := testInfo.proxy.Start(testInfo.ctx)
Expect(err).ToNot(HaveOccurred())
testInfo.stoppedCh <- struct{}{}
}()
<-testInfo.proxy.readyCh
proxyBaseAddr := "http://" + testInfo.proxy.addr.String()
By("sending a /v1/responses request with prefill header")
body := `{
"model": "gpt-4o",
"input": "Hello, how are you?",
"max_output_tokens": 50
}`
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ResponsesPath, strings.NewReader(body))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
if rp.StatusCode != 200 {
bp, _ := io.ReadAll(rp.Body) //nolint:all
Fail(string(bp))
}
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.prefillHandler.CompletionRequests).To(HaveLen(1))
prq1 := testInfo.prefillHandler.CompletionRequests[0]
Expect(prq1).To(HaveKey(requestFieldKVTransferParams))
kvTransferParams, ok := prq1[requestFieldKVTransferParams].(map[string]any)
Expect(ok).To(BeTrue())
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldDoRemoteDecode, true))
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldDoRemotePrefill, false))
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldRemoteBlockIDs, BeNil()))
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldRemoteEngineID, BeNil()))
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldRemoteHost, BeNil()))
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldRemotePort, BeNil()))
Expect(prq1).To(HaveKeyWithValue("max_output_tokens", BeNumerically("==", 1)))
Expect(prq1).To(HaveKeyWithValue("stream", false))
Expect(prq1).ToNot(HaveKey("stream_options"))
Expect(testInfo.prefillHandler.CompletionResponses).To(HaveLen(1))
prp1 := testInfo.prefillHandler.CompletionResponses[0]
Expect(prp1).To(HaveKey(requestFieldKVTransferParams))
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.decodeHandler.CompletionRequests).To(HaveLen(1))
testInfo.cancelFn()
<-testInfo.stoppedCh
})
It("should set max_output_tokens=1 in prefill and restore original value in decode", func() {
By("starting the proxy")
go func() {
defer GinkgoRecover()
testInfo.proxy.allowlistValidator = &AllowlistValidator{enabled: false}
err := testInfo.proxy.Start(testInfo.ctx)
Expect(err).ToNot(HaveOccurred())
testInfo.stoppedCh <- struct{}{}
}()
<-testInfo.proxy.readyCh
proxyBaseAddr := "http://" + testInfo.proxy.addr.String()
By("sending a /v1/responses request with max_output_tokens set")
body := `{
"model": "gpt-4o",
"input": "Tell me a story",
"max_output_tokens": 100
}`
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ResponsesPath, strings.NewReader(body))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
if rp.StatusCode != 200 {
bp, _ := io.ReadAll(rp.Body) //nolint:all
Fail(string(bp))
}
By("verifying prefill request has max_output_tokens=1")
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.prefillHandler.CompletionRequests).To(HaveLen(1))
prefillReq := testInfo.prefillHandler.CompletionRequests[0]
Expect(prefillReq).To(HaveKeyWithValue("max_output_tokens", BeNumerically("==", 1)))
By("verifying decode request has original max_output_tokens=100")
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.decodeHandler.CompletionRequests).To(HaveLen(1))
decodeReq := testInfo.decodeHandler.CompletionRequests[0]
Expect(decodeReq).To(HaveKeyWithValue("max_output_tokens", BeNumerically("==", 100)))
testInfo.cancelFn()
<-testInfo.stoppedCh
})
It("should handle responses API request without max_output_tokens", func() {
By("starting the proxy")
go func() {
defer GinkgoRecover()
testInfo.proxy.allowlistValidator = &AllowlistValidator{enabled: false}
err := testInfo.proxy.Start(testInfo.ctx)
Expect(err).ToNot(HaveOccurred())
testInfo.stoppedCh <- struct{}{}
}()
<-testInfo.proxy.readyCh
proxyBaseAddr := "http://" + testInfo.proxy.addr.String()
By("sending a /v1/responses request without max_output_tokens")
body := `{
"model": "gpt-4o",
"input": "Hello!"
}`
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ResponsesPath, strings.NewReader(body))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
if rp.StatusCode != 200 {
bp, _ := io.ReadAll(rp.Body) //nolint:all
Fail(string(bp))
}
By("verifying prefill request has max_output_tokens=1")
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.prefillHandler.CompletionRequests).To(HaveLen(1))
prefillReq := testInfo.prefillHandler.CompletionRequests[0]
Expect(prefillReq).To(HaveKeyWithValue("max_output_tokens", BeNumerically("==", 1)))
By("verifying decode request does not have max_output_tokens since it wasn't in original request")
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.decodeHandler.CompletionRequests).To(HaveLen(1))
decodeReq := testInfo.decodeHandler.CompletionRequests[0]
Expect(decodeReq).ToNot(HaveKey("max_output_tokens"))
testInfo.cancelFn()
<-testInfo.stoppedCh
})
It("should pass through responses API request when no prefill header is set", func() {
By("starting the proxy")
go func() {
defer GinkgoRecover()
testInfo.proxy.allowlistValidator = &AllowlistValidator{enabled: false}
err := testInfo.proxy.Start(testInfo.ctx)
Expect(err).ToNot(HaveOccurred())
testInfo.stoppedCh <- struct{}{}
}()
<-testInfo.proxy.readyCh
proxyBaseAddr := "http://" + testInfo.proxy.addr.String()
By("sending a /v1/responses request without prefill header")
body := `{
"model": "gpt-4o",
"input": "Hello, how are you?",
"max_output_tokens": 50
}`
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ResponsesPath, strings.NewReader(body))
Expect(err).ToNot(HaveOccurred())
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
if rp.StatusCode != 200 {
bp, _ := io.ReadAll(rp.Body) //nolint:all
Fail(string(bp))
}
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 0))
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
testInfo.cancelFn()
<-testInfo.stoppedCh
})
DescribeTable("should retry prefill on retryable status and succeed",
func(statusCode int) {
testInfo.prefillHandler.FailForFirstN = 1
testInfo.prefillHandler.FailStatusCode = statusCode
testInfo.proxy.config.PrefillMaxRetries = 2
testInfo.proxy.config.PrefillRetryBackoff = time.Millisecond
proxyBaseAddr := startProxy()
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ChatCompletionsPath, bytes.NewReader([]byte(chatCompletionsRequestBody)))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
defer rp.Body.Close()
Expect(rp.StatusCode).To(Equal(http.StatusOK))
By("verifying prefill was called twice (1 fail + 1 success)")
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 2))
By("verifying decode received kv_transfer_params from the successful prefill")
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
decodeReq := testInfo.decodeHandler.CompletionRequests[0]
Expect(decodeReq).To(HaveKey(requestFieldKVTransferParams))
},
Entry("502 Bad Gateway", http.StatusBadGateway),
Entry("503 Service Unavailable", http.StatusServiceUnavailable),
Entry("504 Gateway Timeout", http.StatusGatewayTimeout),
)
It("should return error to client when retries are disabled and prefill fails", func() {
testInfo.prefillHandler.FailForFirstN = 1
testInfo.prefillHandler.FailStatusCode = http.StatusBadGateway
testInfo.proxy.config.PrefillMaxRetries = 0
proxyBaseAddr := startProxy()
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ChatCompletionsPath, bytes.NewReader([]byte(chatCompletionsRequestBody)))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
defer rp.Body.Close()
By("verifying the error is returned to the client")
Expect(rp.StatusCode).To(Equal(http.StatusBadGateway))
By("verifying prefill was called only once (no retry)")
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
By("verifying decode was NOT called")
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 0))
})
It("should return error to client after exhausting all retries", func() {
testInfo.prefillHandler.FailForFirstN = 100
testInfo.prefillHandler.FailStatusCode = http.StatusBadGateway
testInfo.proxy.config.PrefillMaxRetries = 2
testInfo.proxy.config.PrefillRetryBackoff = time.Millisecond
proxyBaseAddr := startProxy()
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ChatCompletionsPath, bytes.NewReader([]byte(chatCompletionsRequestBody)))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
defer rp.Body.Close()
By("verifying the error is returned to the client")
Expect(rp.StatusCode).To(Equal(http.StatusBadGateway))
By("verifying prefill was called 3 times (1 initial + 2 retries)")
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 3))
By("verifying decode was NOT called")
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 0))
})
It("should not retry on non-retryable 500 and return error to client", func() {
testInfo.prefillHandler.FailForFirstN = 1
testInfo.prefillHandler.FailStatusCode = http.StatusInternalServerError
testInfo.proxy.config.PrefillMaxRetries = 2
testInfo.proxy.config.PrefillRetryBackoff = time.Millisecond
proxyBaseAddr := startProxy()
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ChatCompletionsPath, bytes.NewReader([]byte(chatCompletionsRequestBody)))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
defer rp.Body.Close()
By("verifying the error is returned to the client")
Expect(rp.StatusCode).To(Equal(http.StatusInternalServerError))
By("verifying prefill was called only once (no retry despite PrefillMaxRetries=2)")
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
By("verifying decode was NOT called")
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 0))
})
It("should preserve stream settings in responses API request", func() {
By("starting the proxy")
go func() {
defer GinkgoRecover()
testInfo.proxy.allowlistValidator = &AllowlistValidator{enabled: false}
err := testInfo.proxy.Start(testInfo.ctx)
Expect(err).ToNot(HaveOccurred())
testInfo.stoppedCh <- struct{}{}
}()
<-testInfo.proxy.readyCh
proxyBaseAddr := "http://" + testInfo.proxy.addr.String()
By("sending a /v1/responses request with streaming enabled")
body := `{
"model": "gpt-4o",
"input": "Hello!",
"max_output_tokens": 50,
"stream": true
}`
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ResponsesPath, strings.NewReader(body))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
if rp.StatusCode != 200 {
bp, _ := io.ReadAll(rp.Body) //nolint:all
Fail(string(bp))
}
By("verifying prefill request has stream=false")
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
prefillReq := testInfo.prefillHandler.CompletionRequests[0]
Expect(prefillReq).To(HaveKeyWithValue("stream", false))
By("verifying decode request has stream=true restored")
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
decodeReq := testInfo.decodeHandler.CompletionRequests[0]
Expect(decodeReq).To(HaveKeyWithValue("stream", true))
testInfo.cancelFn()
<-testInfo.stoppedCh
})
// Generate API tests — exercise the same NIXL v2 connector with
// /inference/v1/generate, whose token limits live under sampling_params.
startProxyAndSendGenerate := func(body string, withPrefillHeader bool) {
go func() {
defer GinkgoRecover()
testInfo.proxy.allowlistValidator = &AllowlistValidator{enabled: false}
err := testInfo.proxy.Start(testInfo.ctx)
Expect(err).ToNot(HaveOccurred())
testInfo.stoppedCh <- struct{}{}
}()
<-testInfo.proxy.readyCh
DeferCleanup(func() {
testInfo.cancelFn()
<-testInfo.stoppedCh
})
proxyBaseAddr := "http://" + testInfo.proxy.addr.String()
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+GeneratePath, strings.NewReader(body))
Expect(err).ToNot(HaveOccurred())
if withPrefillHeader {
req.Header.Add(routing.PrefillEndpointHeader, testInfo.prefillBackend.URL[len("http://"):])
}
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
defer rp.Body.Close()
if rp.StatusCode != 200 {
bp, readErr := io.ReadAll(rp.Body)
Expect(readErr).ToNot(HaveOccurred())
Fail(string(bp))
}
}
samplingParamsOf := func(req map[string]any) map[string]any {
sp, ok := req[requestFieldSamplingParams].(map[string]any)
Expect(ok).To(BeTrue())
return sp
}
It("should successfully send generate API request to 1. prefill 2. decode with the correct fields", func() {
startProxyAndSendGenerate(`{
"model": "Qwen/Qwen2-0.5B",
"token_ids": [1, 2, 3, 4],
"sampling_params": {"max_tokens": 50}
}`, true)
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.prefillHandler.CompletionRequests).To(HaveLen(1))
prq1 := testInfo.prefillHandler.CompletionRequests[0]
kvTransferParams, ok := prq1[requestFieldKVTransferParams].(map[string]any)
Expect(ok).To(BeTrue())
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldDoRemoteDecode, true))
Expect(kvTransferParams).To(HaveKeyWithValue(requestFieldDoRemotePrefill, false))
Expect(samplingParamsOf(prq1)).To(HaveKeyWithValue(requestFieldMaxTokens, BeNumerically("==", 1)))
Expect(samplingParamsOf(prq1)).To(HaveKeyWithValue(requestFieldMinTokens, BeNumerically("==", 1)))
Expect(prq1).To(HaveKeyWithValue("stream", false))
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(testInfo.decodeHandler.CompletionRequests).To(HaveLen(1))
})
It("should cap sampling_params token limits in prefill and restore originals in decode", func() {
startProxyAndSendGenerate(`{
"model": "Qwen/Qwen2-0.5B",
"token_ids": [1, 2, 3, 4],
"sampling_params": {"max_tokens": 100, "min_tokens": 5}
}`, true)
prefillSP := samplingParamsOf(testInfo.prefillHandler.CompletionRequests[0])
Expect(prefillSP).To(HaveKeyWithValue(requestFieldMaxTokens, BeNumerically("==", 1)))
Expect(prefillSP).To(HaveKeyWithValue(requestFieldMinTokens, BeNumerically("==", 1)))
decodeSP := samplingParamsOf(testInfo.decodeHandler.CompletionRequests[0])
Expect(decodeSP).To(HaveKeyWithValue(requestFieldMaxTokens, BeNumerically("==", 100)))
Expect(decodeSP).To(HaveKeyWithValue(requestFieldMinTokens, BeNumerically("==", 5)))
})
It("should cap prefill and drop the caps in decode when sampling_params omits them", func() {
startProxyAndSendGenerate(`{
"model": "Qwen/Qwen2-0.5B",
"token_ids": [1, 2, 3, 4],
"sampling_params": {"temperature": 0.7}
}`, true)
prefillSP := samplingParamsOf(testInfo.prefillHandler.CompletionRequests[0])
Expect(prefillSP).To(HaveKeyWithValue(requestFieldMaxTokens, BeNumerically("==", 1)))
Expect(prefillSP).To(HaveKeyWithValue(requestFieldMinTokens, BeNumerically("==", 1)))
decodeSP := samplingParamsOf(testInfo.decodeHandler.CompletionRequests[0])
Expect(decodeSP).ToNot(HaveKey(requestFieldMaxTokens))
Expect(decodeSP).ToNot(HaveKey(requestFieldMinTokens))
Expect(decodeSP).To(HaveKeyWithValue("temperature", BeNumerically("==", 0.7)))
})
It("should cap prefill and drop synthesized sampling_params in decode when the request omits it", func() {
startProxyAndSendGenerate(`{
"model": "Qwen/Qwen2-0.5B",
"token_ids": [1, 2, 3, 4]
}`, true)
prefillSP := samplingParamsOf(testInfo.prefillHandler.CompletionRequests[0])
Expect(prefillSP).To(HaveKeyWithValue(requestFieldMaxTokens, BeNumerically("==", 1)))
Expect(prefillSP).To(HaveKeyWithValue(requestFieldMinTokens, BeNumerically("==", 1)))
decodeReq := testInfo.decodeHandler.CompletionRequests[0]
Expect(decodeReq).ToNot(HaveKey(requestFieldSamplingParams))
})
It("should pass through generate API request when no prefill header is set", func() {
startProxyAndSendGenerate(`{
"model": "Qwen/Qwen2-0.5B",
"token_ids": [1, 2, 3, 4],
"sampling_params": {"max_tokens": 50}
}`, false)
Expect(testInfo.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 0))
Expect(testInfo.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
})
// MoRI-IO WRITE-mode regression test.
// When --moriio-write-mode is enabled, the sidecar must populate
// remote_host / remote_notify_port / transfer_id on the prefill leg
// (rather than leaving them nil as the standard NIXLv2 contract does) so
// the prefill engine's MoRIIOConnector can issue RDMA Write to decode.
// The same transfer_id must also be carried forward into the decode request
// so the consumer side can bind notifications to the right transfer.
It("populates MoRI-IO WRITE-mode kv_transfer_params when MoRIIOWriteMode is enabled", func() {
// Manual setup because sidecarConnectionTestSetup does not accept
// MoRI-IO config knobs. Mirrors the helper exactly otherwise.
ctx := newTestContext()
ctx, cancelFn := context.WithCancel(ctx)
stoppedCh := make(chan struct{})
decodeHandler := &mock.ChatCompletionHandler{
Connector: KVConnectorNIXLV2,
Role: mock.RoleDecode,
MoRIIOWriteMode: true,
}
decodeBackend := httptest.NewServer(decodeHandler)
DeferCleanup(decodeBackend.Close)
prefillHandler := &mock.ChatCompletionHandler{
Connector: KVConnectorNIXLV2,
Role: mock.RolePrefill,
MoRIIOWriteMode: true,
}
prefillBackend := httptest.NewServer(prefillHandler)
DeferCleanup(prefillBackend.Close)
decodeURL, err := url.Parse(decodeBackend.URL)
Expect(err).ToNot(HaveOccurred())
cfg := Config{
Port: "0",
DecoderURL: decodeURL,
KVConnector: KVConnectorNIXLV2,
MoRIIOWriteMode: true,
MoRIIODecodeNotifyPort: 61005,
// r6: kv_transfer_params["remote_host"] is sourced from this
// field (the decode pod's routable IP) instead of
// DecoderURL.Hostname(). Set it so the assertion at
// line 195 (remote_host == decodeURL.Hostname()) holds.
MoRIIODecodePodIP: decodeURL.Hostname(),
}
proxy := NewProxy(cfg)
By("starting the proxy")
go func() {
defer GinkgoRecover()
proxy.allowlistValidator = &AllowlistValidator{enabled: false}
err := proxy.Start(ctx)
Expect(err).ToNot(HaveOccurred())
stoppedCh <- struct{}{}
}()
<-proxy.readyCh
proxyBaseAddr := "http://" + proxy.addr.String()
By("sending a /v1/chat/completions request")
body := `{
"model": "Qwen/Qwen2-0.5B",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 50
}`
req, err := http.NewRequest(http.MethodPost, proxyBaseAddr+ChatCompletionsPath, strings.NewReader(body))
Expect(err).ToNot(HaveOccurred())
req.Header.Add(routing.PrefillEndpointHeader, prefillBackend.URL[len("http://"):])
rp, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())
if rp.StatusCode != 200 {
bp, _ := io.ReadAll(rp.Body) //nolint:all
Fail(string(bp))
}
By("verifying prefill request has WRITE-mode kv_transfer_params populated")
Expect(prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(prefillHandler.CompletionRequests).To(HaveLen(1))
prq := prefillHandler.CompletionRequests[0]
Expect(prq).To(HaveKey(requestFieldKVTransferParams))
kv, ok := prq[requestFieldKVTransferParams].(map[string]any)
Expect(ok).To(BeTrue())
// New WRITE-mode fields must be non-nil and match config / request UUID.
Expect(kv).To(HaveKeyWithValue(requestFieldRemoteHost, decodeURL.Hostname()))
Expect(kv).To(HaveKeyWithValue(requestFieldRemoteNotifyPort, BeNumerically("==", 61005)))
Expect(kv).To(HaveKeyWithValue(requestFieldRemoteDPRank, BeNumerically("==", 0)))
Expect(kv).To(HaveKey(requestFieldTransferID))
Expect(kv[requestFieldTransferID]).ToNot(BeEmpty())
// Pre-existing nil fields are still nil because they are populated by
// the prefill engine's request_finished, not the sidecar.
Expect(kv).To(HaveKeyWithValue(requestFieldDoRemoteDecode, true))
Expect(kv).To(HaveKeyWithValue(requestFieldDoRemotePrefill, false))
Expect(kv).To(HaveKeyWithValue(requestFieldRemoteEngineID, BeNil()))
Expect(kv).To(HaveKeyWithValue(requestFieldRemoteBlockIDs, BeNil()))
Expect(kv).To(HaveKeyWithValue(requestFieldRemotePort, BeNil()))
transferID := kv[requestFieldTransferID]
By("verifying decode request carries the same transfer_id")
Expect(decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(decodeHandler.CompletionRequests).To(HaveLen(1))
drq := decodeHandler.CompletionRequests[0]
Expect(drq).To(HaveKey(requestFieldKVTransferParams))
dkv, ok := drq[requestFieldKVTransferParams].(map[string]any)
Expect(ok).To(BeTrue())
Expect(dkv).To(HaveKey(requestFieldTransferID))
Expect(dkv[requestFieldTransferID]).To(Equal(transferID))
cancelFn()
<-stoppedCh
})
// MoRI-IO Wide-EP DP-rank pinning and multi-pod fan-out coverage for the
// 1P1D DP=8 and 2P2D DP=16 topologies, plus the flags-off legacy path.
//
// These tests use mocks and build Config directly - they don't need the
// MoRIIOFeatureEnabled gate since they bypass Options.Complete().
// 1P1D DP=8, concurrent dispatch: both legs pinned to one DP rank, decode
// flips do_remote_prefill, remote_dp_size carries the DP world size.
It("parallel-dispatch 1P1D DP=8 pins both legs to one DP rank and emits remote_dp_size", func() {
env := startMoRIProxy(func(c *Config) {
c.MoRIIOParallelDispatch = true
c.MoRIIODPSize = 8
})
env.send()
Expect(env.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(env.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))
By("prefill leg carries WRITE-mode + Wide-EP fields")
pkv := kvParams(env.prefillHandler, 0)
Expect(pkv).To(HaveKeyWithValue(requestFieldDoRemoteDecode, true))
Expect(pkv).To(HaveKeyWithValue(requestFieldDoRemotePrefill, false))
Expect(pkv).To(HaveKeyWithValue(requestFieldRemoteHost, env.decodePodIP))
Expect(pkv).To(HaveKeyWithValue("remote_dp_size", BeNumerically("==", 8)))
Expect(pkv).To(HaveKeyWithValue(requestFieldRemoteDPRankOverride, true))
// Single-pod: the multi-pod fan-out keys must be omitted entirely.
Expect(pkv).ToNot(HaveKey("remote_hosts"))
Expect(pkv).ToNot(HaveKey("remote_dp_size_local"))
pRank, ok := pkv[requestFieldRemoteDPRank].(float64)
Expect(ok).To(BeTrue())
Expect(pRank).To(And(BeNumerically(">=", 0), BeNumerically("<", 8)))
By("decode leg flips do_remote_prefill and reuses the same rank + transfer_id")
dkv := kvParams(env.decodeHandler, 0)
Expect(dkv).To(HaveKeyWithValue(requestFieldDoRemotePrefill, true))
Expect(dkv).To(HaveKeyWithValue(requestFieldDoRemoteDecode, false))
Expect(dkv).To(HaveKeyWithValue("remote_dp_size", BeNumerically("==", 8)))
Expect(dkv[requestFieldRemoteDPRank]).To(Equal(pRank))
Expect(dkv[requestFieldTransferID]).To(Equal(pkv[requestFieldTransferID]))
Expect(dkv[requestFieldTransferID]).ToNot(BeEmpty())
By("both HTTP legs share the same X-Data-Parallel-Rank header")
ph := dpRankHeader(env.prefillHandler, 0)
Expect(ph).To(Equal(strconv.Itoa(int(pRank))))
Expect(dpRankHeader(env.decodeHandler, 0)).To(Equal(ph))
})
// 2P2D DP=16 multi-pod fan-out: each leg's remote_hosts is the opposite
// side's pod IPs (prefill leg -> decode IPs, decode leg -> prefill IPs).
It("parallel-dispatch 2P2D DP=EP=16 fans out remote_hosts with opposite host lists per leg", func() {
prefillHosts := []string{"10.0.0.1", "10.0.0.2"}
decodeHosts := []string{"10.0.1.1", "10.0.1.2"}
env := startMoRIProxy(func(c *Config) {
c.MoRIIOParallelDispatch = true
c.MoRIIODPSize = 16
c.MoRIIODPSizeLocal = 8
c.MoRIIORemoteHosts = prefillHosts
c.MoRIIODecodeHosts = decodeHosts
})
env.send()
Expect(env.prefillHandler.RequestCount.Load()).To(BeNumerically("==", 1))
Expect(env.decodeHandler.RequestCount.Load()).To(BeNumerically("==", 1))