Skip to content

Commit 1e3417a

Browse files
nirrozenbaumkfswain
authored andcommitted
normalize score to make sure it is always in the range of [0,1] (kubernetes-sigs#1236)
* normalize score to make sure score is always in the range of [0,1] Signed-off-by: Nir Rozenbaum <[email protected]> * code review commentsx Signed-off-by: Nir Rozenbaum <[email protected]> --------- Signed-off-by: Nir Rozenbaum <[email protected]>
1 parent 34b3e85 commit 1e3417a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pkg/epp/scheduling/framework/plugins.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type Filter interface {
5757

5858
// Scorer defines the interface for scoring a list of pods based on context.
5959
// Scorers must score pods with a value within the range of [0,1] where 1 is the highest score.
60+
// If a scorer returns value greater than 1, it will be treated as score 1.
61+
// If a scorer returns value lower than 0, it will be treated as score 0.
6062
type Scorer interface {
6163
plugins.Plugin
6264
Score(ctx context.Context, cycleState *types.CycleState, request *types.LLMRequest, pods []types.Pod) map[types.Pod]float64

pkg/epp/scheduling/framework/scheduler_profile.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (p *SchedulerProfile) runScorerPlugins(ctx context.Context, request *types.
180180
scores := scorer.Score(ctx, cycleState, request, pods)
181181
metrics.RecordSchedulerPluginProcessingLatency(ScorerPluginType, scorer.TypedName().Type, time.Since(before))
182182
for pod, score := range scores { // weight is relative to the sum of weights
183-
weightedScorePerPod[pod] += score * float64(scorer.Weight())
183+
weightedScorePerPod[pod] += enforceScoreRange(score) * float64(scorer.Weight())
184184
}
185185
loggerDebug.Info("After running scorer", "scorer", scorer.TypedName().Type)
186186
}
@@ -215,3 +215,13 @@ func (p *SchedulerProfile) runPostCyclePlugins(ctx context.Context, cycleState *
215215
metrics.RecordSchedulerPluginProcessingLatency(PostCyclePluginType, plugin.TypedName().Type, time.Since(before))
216216
}
217217
}
218+
219+
func enforceScoreRange(score float64) float64 {
220+
if score < 0 {
221+
return 0
222+
}
223+
if score > 1 {
224+
return 1
225+
}
226+
return score
227+
}

0 commit comments

Comments
 (0)