Skip to content

Commit 38a4472

Browse files
authored
Merge branch 'main' into refactor/fc-outcome-from-error
2 parents b0fc046 + d9f5962 commit 38a4472

6 files changed

Lines changed: 24 additions & 28 deletions

File tree

pkg/kvevents/engineadapter/common.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ const (
3333
eventTagAllBlocksCleared = "AllBlocksCleared"
3434
)
3535

36+
type msgpackEventBatch struct {
37+
_ struct{} `msgpack:",array"`
38+
TS float64
39+
Events []msgpack.RawMessage
40+
DataParallelRank *int `msgpack:",omitempty"`
41+
}
42+
3643
// parseTopic extracts pod ID and model name from the topic format "kv@<pod-id>@<model-name>".
3744
//
3845
//nolint:gocritic // unnamedResult: named returns conflict with nonamedreturns linter

pkg/kvevents/engineadapter/sglang_adapter.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (s *SGLangAdapter) ShardingKey(msg *kvevents.RawMessage) string {
7171
func (s *SGLangAdapter) ParseMessage(msg *kvevents.RawMessage) (string, string, kvevents.EventBatch, error) {
7272
podID, modelName := parseTopic(msg.Topic)
7373

74-
var batch msgpackSGLangEventBatch
74+
var batch msgpackEventBatch
7575
if err := msgpack.Unmarshal(msg.Payload, &batch); err != nil {
7676
return "", "", kvevents.EventBatch{}, fmt.Errorf("failed to decode SGLang event batch: %w", err)
7777
}
@@ -86,22 +86,14 @@ func (s *SGLangAdapter) ParseMessage(msg *kvevents.RawMessage) (string, string,
8686
}
8787

8888
eventBatch := kvevents.EventBatch{
89-
Timestamp: batch.TS,
90-
Events: genericEvents,
89+
Timestamp: batch.TS,
90+
Events: genericEvents,
91+
DataParallelRank: batch.DataParallelRank,
9192
}
9293

9394
return podID, modelName, eventBatch, nil
9495
}
9596

96-
// SGLang msgpack event structures.
97-
// These match the vLLM wire format (SGLang uses the same positional encoding).
98-
type msgpackSGLangEventBatch struct {
99-
_ struct{} `msgpack:",array"`
100-
TS float64
101-
Events []msgpack.RawMessage
102-
DataParallelRank *int `msgpack:",omitempty"`
103-
}
104-
10597
type msgpackSGLangBlockStoredEvent struct {
10698
_ struct{} `msgpack:",array"`
10799
Tag string

pkg/kvevents/engineadapter/sglang_adapter_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestSGLangParseMessage_Valid(t *testing.T) {
5050
batch := []any{
5151
1234567890.0,
5252
[]any{blockStoredEvent},
53-
nil,
53+
3,
5454
}
5555
payload, err := msgpack.Marshal(batch)
5656
require.NoError(t, err)
@@ -65,6 +65,8 @@ func TestSGLangParseMessage_Valid(t *testing.T) {
6565
require.NoError(t, err)
6666
assert.Equal(t, "pod-1", podID)
6767
assert.Equal(t, "llama-2-7b", modelName)
68+
require.NotNil(t, eventBatch.DataParallelRank)
69+
assert.Equal(t, 3, *eventBatch.DataParallelRank)
6870
assert.Len(t, eventBatch.Events, 1)
6971

7072
blockStored, ok := eventBatch.Events[0].(*kvevents.BlockStoredEvent)

pkg/kvevents/engineadapter/vllm_adapter.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (v *VLLMAdapter) ShardingKey(msg *kvevents.RawMessage) string {
6464
func (v *VLLMAdapter) ParseMessage(msg *kvevents.RawMessage) (string, string, kvevents.EventBatch, error) {
6565
podID, modelName := parseTopic(msg.Topic)
6666

67-
var vllmBatch msgpackVLLMEventBatch
67+
var vllmBatch msgpackEventBatch
6868
if err := msgpack.Unmarshal(msg.Payload, &vllmBatch); err != nil {
6969
return "", "", kvevents.EventBatch{}, fmt.Errorf("failed to decode vLLM event batch: %w", err)
7070
}
@@ -79,22 +79,14 @@ func (v *VLLMAdapter) ParseMessage(msg *kvevents.RawMessage) (string, string, kv
7979
}
8080

8181
batch := kvevents.EventBatch{
82-
Timestamp: vllmBatch.TS,
83-
Events: genericEvents,
82+
Timestamp: vllmBatch.TS,
83+
Events: genericEvents,
84+
DataParallelRank: vllmBatch.DataParallelRank,
8485
}
8586

8687
return podID, modelName, batch, nil
8788
}
8889

89-
// vLLM msgpack event batch structure.
90-
// This struct uses array encoding to match vLLM's msgspec array_like=True format.
91-
type msgpackVLLMEventBatch struct {
92-
_ struct{} `msgpack:",array"`
93-
TS float64
94-
Events []msgpack.RawMessage
95-
DataParallelRank *int `msgpack:",omitempty"`
96-
}
97-
9890
// decodeVLLMEvent decodes a single vLLM event from msgpack bytes and dispatches
9991
// it to the matching converter. Map-encoded events are first normalized to the
10092
// positional []any layout the converters consume.

pkg/kvevents/engineadapter/vllm_adapter_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestVLLMParseMessage_Valid(t *testing.T) {
5151
batch := []any{
5252
1234567890.0,
5353
[]any{blockStoredEvent},
54-
nil,
54+
3,
5555
}
5656
payload, err := msgpack.Marshal(batch)
5757
require.NoError(t, err)
@@ -66,6 +66,8 @@ func TestVLLMParseMessage_Valid(t *testing.T) {
6666
require.NoError(t, err)
6767
assert.Equal(t, "pod-1", podID)
6868
assert.Equal(t, "llama-2-7b", modelName)
69+
require.NotNil(t, eventBatch.DataParallelRank)
70+
assert.Equal(t, 3, *eventBatch.DataParallelRank)
6971
assert.Len(t, eventBatch.Events, 1)
7072

7173
blockStored, ok := eventBatch.Events[0].(*kvevents.BlockStoredEvent)

pkg/kvevents/events.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ type GenericEvent interface {
5050

5151
// EventBatch represents a batch of generic events from an inference engine.
5252
type EventBatch struct {
53-
Timestamp float64
54-
Events []GenericEvent
53+
Timestamp float64
54+
Events []GenericEvent
55+
DataParallelRank *int
5556
}
5657

5758
// RawMessage holds the raw transport-level data from a received pub/sub message.

0 commit comments

Comments
 (0)