Skip to content

Commit 75c3897

Browse files
authored
add scorer category to scorer interface. (#2119)
Signed-off-by: Nir Rozenbaum <nirro@il.ibm.com>
1 parent d5ec68a commit 75c3897

File tree

9 files changed

+68
-13
lines changed

9 files changed

+68
-13
lines changed

pkg/epp/config/loader/configloader_test.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,35 +408,39 @@ func (m *mockPlugin) TypedName() plugins.TypedName { return m.t }
408408
// Mock Scorer
409409
type mockScorer struct{ mockPlugin }
410410

411+
// compile-time type assertion
412+
var _ framework.Scorer = &mockScorer{}
413+
414+
func (m *mockScorer) Category() framework.ScorerCategory {
415+
return framework.Distribution
416+
}
417+
411418
func (m *mockScorer) Score(context.Context, *types.CycleState, *types.LLMRequest, []types.Endpoint) map[types.Endpoint]float64 {
412419
return nil
413420
}
414421

415422
// Mock Picker
416423
type mockPicker struct{ mockPlugin }
417424

425+
// compile-time type assertion
426+
var _ framework.Picker = &mockPicker{}
427+
418428
func (m *mockPicker) Pick(context.Context, *types.CycleState, []*types.ScoredEndpoint) *types.ProfileRunResult {
419429
return nil
420430
}
421431

422432
// Mock Handler
423433
type mockHandler struct{ mockPlugin }
424434

425-
func (m *mockHandler) Pick(
426-
context.Context,
427-
*types.CycleState,
428-
*types.LLMRequest,
429-
map[string]*framework.SchedulerProfile,
430-
map[string]*types.ProfileRunResult,
431-
) map[string]*framework.SchedulerProfile {
435+
// compile-time type assertion
436+
var _ framework.ProfileHandler = &mockHandler{}
437+
438+
func (m *mockHandler) Pick(context.Context, *types.CycleState, *types.LLMRequest, map[string]*framework.SchedulerProfile,
439+
map[string]*types.ProfileRunResult) map[string]*framework.SchedulerProfile {
432440
return nil
433441
}
434-
func (m *mockHandler) ProcessResults(
435-
context.Context,
436-
*types.CycleState,
437-
*types.LLMRequest,
438-
map[string]*types.ProfileRunResult,
439-
) (*types.SchedulingResult, error) {
442+
func (m *mockHandler) ProcessResults(context.Context, *types.CycleState, *types.LLMRequest,
443+
map[string]*types.ProfileRunResult) (*types.SchedulingResult, error) {
440444
return nil, nil
441445
}
442446

pkg/epp/scheduling/framework/plugins.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ const (
3131
ProcessProfilesResultsExtensionPoint = "ProcessProfilesResults"
3232
)
3333

34+
// ScorerCategory marks the preference a scorer applies when scoring candidate endpoints.
35+
type ScorerCategory string
36+
37+
const (
38+
// Affinity indicates a scorer that prefers endpoints with existing locality, such as kv-cache or session-related state,
39+
// and therefore tends to give higher scores to the same endpoints.
40+
Affinity ScorerCategory = "Affinity"
41+
42+
// Distribution indicates a scorer that prefers spreading requests evenly across all candidate endpoints to avoid
43+
// hotspots and improve overall utilization.
44+
Distribution ScorerCategory = "Distribution"
45+
46+
// Balance indicates a scorer that its preference is balanced between Affinity and Distribution.
47+
Balance ScorerCategory = "Balance"
48+
)
49+
3450
// ProfileHandler defines the extension points for handling multi SchedulerProfile instances.
3551
// More specifically, this interface defines the 'Pick' and 'ProcessResults' extension points.
3652
type ProfileHandler interface {
@@ -60,6 +76,7 @@ type Filter interface {
6076
// If a scorer returns value lower than 0, it will be treated as score 0.
6177
type Scorer interface {
6278
plugins.Plugin
79+
Category() ScorerCategory
6380
Score(ctx context.Context, cycleState *types.CycleState, request *types.LLMRequest, pods []types.Endpoint) map[types.Endpoint]float64
6481
}
6582

pkg/epp/scheduling/framework/plugins/multi/prefix/plugin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ func (p *Plugin) TypedName() plugins.TypedName {
207207
return p.typedName
208208
}
209209

210+
// Category returns the preference the scorer applies when scoring candidate endpoints.
211+
func (p *Plugin) Category() framework.ScorerCategory {
212+
return framework.Affinity
213+
}
214+
210215
// WithName sets the name of the plugin.
211216
func (p *Plugin) WithName(name string) *Plugin {
212217
p.typedName.Name = name

pkg/epp/scheduling/framework/plugins/multi/slo_aware_router/scorer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ func (s *SLOAwareRouter) TypedName() plugins.TypedName {
186186
return s.typedName
187187
}
188188

189+
// Category returns the preference the scorer applies when scoring candidate endpoints.
190+
func (s *SLOAwareRouter) Category() framework.ScorerCategory {
191+
return framework.Balance
192+
}
193+
189194
func (s *SLOAwareRouter) WithName(name string) *SLOAwareRouter {
190195
s.typedName.Name = name
191196
return s

pkg/epp/scheduling/framework/plugins/scorer/kvcache_utilization.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func (s *KVCacheUtilizationScorer) TypedName() plugins.TypedName {
5555
return s.typedName
5656
}
5757

58+
// Category returns the preference the scorer applies when scoring candidate endpoints.
59+
func (s *KVCacheUtilizationScorer) Category() framework.ScorerCategory {
60+
return framework.Distribution
61+
}
62+
5863
// Consumes returns the list of data that is consumed by the plugin.
5964
func (s *KVCacheUtilizationScorer) Consumes() map[string]any {
6065
return map[string]any{

pkg/epp/scheduling/framework/plugins/scorer/lora_affinity.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func (s *LoraAffinityScorer) TypedName() plugins.TypedName {
5555
return s.typedName
5656
}
5757

58+
// Category returns the preference the scorer applies when scoring candidate endpoints.
59+
func (s *LoraAffinityScorer) Category() framework.ScorerCategory {
60+
return framework.Affinity
61+
}
62+
5863
// Consumes returns the list of data that is consumed by the plugin.
5964
func (s *LoraAffinityScorer) Consumes() map[string]any {
6065
return map[string]any{

pkg/epp/scheduling/framework/plugins/scorer/queue.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ func (s *QueueScorer) TypedName() plugins.TypedName {
5757
return s.typedName
5858
}
5959

60+
// Category returns the preference the scorer applies when scoring candidate endpoints.
61+
func (s *QueueScorer) Category() framework.ScorerCategory {
62+
return framework.Distribution
63+
}
64+
6065
// Consumes returns the list of data that is consumed by the plugin.
6166
func (s *QueueScorer) Consumes() map[string]any {
6267
return map[string]any{

pkg/epp/scheduling/framework/plugins/scorer/running.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ func (s *RunningRequestsSizeScorer) TypedName() plugins.TypedName {
5757
return s.typedName
5858
}
5959

60+
// Category returns the preference the scorer applies when scoring candidate endpoints.
61+
func (s *RunningRequestsSizeScorer) Category() framework.ScorerCategory {
62+
return framework.Distribution
63+
}
64+
6065
// Consumes returns the list of data that is consumed by the plugin.
6166
func (s *RunningRequestsSizeScorer) Consumes() map[string]any {
6267
return map[string]any{

pkg/epp/scheduling/framework/scheduler_profile_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ func (tp *testPlugin) TypedName() plugins.TypedName {
201201
return tp.typedName
202202
}
203203

204+
func (tp *testPlugin) Category() ScorerCategory {
205+
return Distribution
206+
}
207+
204208
func (tp *testPlugin) Filter(_ context.Context, _ *types.CycleState, _ *types.LLMRequest, endpoints []types.Endpoint) []types.Endpoint {
205209
tp.FilterCallCount++
206210
return findEndpoints(endpoints, tp.FilterRes...)

0 commit comments

Comments
 (0)