Skip to content

Commit c277812

Browse files
committed
simplify config
Signed-off-by: Nir Rozenbaum <nirro@il.ibm.com>
1 parent f6c57c5 commit c277812

File tree

4 files changed

+45
-55
lines changed

4 files changed

+45
-55
lines changed

cmd/epp/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,10 @@ func run() error {
178178
// Setup runner.
179179
ctx := ctrl.SetupSignalHandler()
180180

181-
schedCfg := config.NewConfig(setupLog)
182-
schedCfg.LoadConfig()
181+
schedulerConfig := config.LoadConfig(setupLog)
183182

184183
datastore := datastore.NewDatastore(ctx, pmf)
185-
scheduler, err := pd.NewScheduler(ctx, schedCfg, datastore)
184+
scheduler, err := pd.NewScheduler(ctx, schedulerConfig, datastore)
186185
if err != nil {
187186
setupLog.Error(err, "Failed to create PD scheduler")
188187
return err

pkg/config/config.go

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
package config
44

55
import (
6-
"math"
7-
86
"github.com/go-logr/logr"
97
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/env"
108
)
@@ -16,6 +14,10 @@ const (
1614
// - "PREFILL_ENABLE_" + pluginName Enables the named plugin for prefill processing
1715
// - "PREFILL_" + pluginName + "_WEIGHT" The weight for a scorer in prefill processing
1816

17+
prefillPrefix = "PREFILL_"
18+
enablePrefix = "ENABLE_"
19+
weightSuffix = "_WEIGHT"
20+
1921
// KVCacheScorerName name of the kv-cache scorer in configuration
2022
KVCacheScorerName = "KVCACHE_AWARE_SCORER"
2123
// LoadAwareScorerName name of the load aware scorer in configuration
@@ -25,10 +27,6 @@ const (
2527
// SessionAwareScorerName name of the session aware scorer in configuration
2628
SessionAwareScorerName = "SESSION_AWARE_SCORER"
2729

28-
prefillPrefix = "PREFILL_"
29-
enablePrefix = "ENABLE_"
30-
weightSuffix = "_WEIGHT"
31-
3230
// Plugins from Upstream
3331

3432
// GIELeastKVCacheFilterName name of the GIE least kv-cache filter in configuration
@@ -58,47 +56,34 @@ const (
5856

5957
// Config contains scheduler configuration, currently configuration is loaded from environment variables
6058
type Config struct {
61-
logger logr.Logger
6259
DecodeSchedulerPlugins map[string]int
6360
PrefillSchedulerPlugins map[string]int
64-
65-
PDEnabled bool
66-
PDThreshold int
67-
PrefixBlockSize int
61+
PDEnabled bool
62+
PDThreshold int
63+
PrefixBlockSize int
6864
}
6965

70-
// NewConfig creates a new instance if Config
71-
func NewConfig(logger logr.Logger) *Config {
72-
return &Config{
73-
logger: logger,
74-
DecodeSchedulerPlugins: map[string]int{},
75-
PrefillSchedulerPlugins: map[string]int{},
76-
PDEnabled: false,
77-
PDThreshold: math.MaxInt,
78-
PrefixBlockSize: prefixScorerBlockSizeDefault,
79-
}
80-
}
81-
82-
// LoadConfig loads configuration from environment variables
83-
func (c *Config) LoadConfig() {
84-
c.loadPluginInfo(c.DecodeSchedulerPlugins, false,
85-
KVCacheScorerName, LoadAwareScorerName, PrefixScorerName, SessionAwareScorerName,
86-
GIELeastKVCacheFilterName, GIELeastQueueFilterName, GIELoraAffinityFilterName,
87-
GIELowQueueFilterName, GIESheddableCapacityFilterName,
88-
GIEKVCacheUtilizationScorerName, GIEQueueScorerName, GIEPrefixScorerName)
89-
90-
c.loadPluginInfo(c.PrefillSchedulerPlugins, true,
66+
// LoadConfig loads configuration from environment variables and returns a new instance of Config
67+
func LoadConfig(logger logr.Logger) *Config {
68+
pluginNames := []string{
9169
KVCacheScorerName, LoadAwareScorerName, PrefixScorerName, SessionAwareScorerName,
9270
GIELeastKVCacheFilterName, GIELeastQueueFilterName, GIELoraAffinityFilterName,
9371
GIELowQueueFilterName, GIESheddableCapacityFilterName,
94-
GIEKVCacheUtilizationScorerName, GIEQueueScorerName, GIEPrefixScorerName)
72+
GIEKVCacheUtilizationScorerName, GIEQueueScorerName, GIEPrefixScorerName,
73+
}
9574

96-
c.PDEnabled = env.GetEnvString(pdEnabledEnvKey, "false", c.logger) == "true"
97-
c.PDThreshold = env.GetEnvInt(pdPromptLenThresholdEnvKey, pdPromptLenThresholdDefault, c.logger)
98-
c.PrefixBlockSize = env.GetEnvInt(prefixScorerBlockSizeEnvKey, prefixScorerBlockSizeDefault, c.logger)
75+
return &Config{
76+
DecodeSchedulerPlugins: loadPluginInfo(logger, false, pluginNames...),
77+
PrefillSchedulerPlugins: loadPluginInfo(logger, true, pluginNames...),
78+
PDEnabled: env.GetEnvString(pdEnabledEnvKey, "false", logger) == "true",
79+
PDThreshold: env.GetEnvInt(pdPromptLenThresholdEnvKey, pdPromptLenThresholdDefault, logger),
80+
PrefixBlockSize: env.GetEnvInt(prefixScorerBlockSizeEnvKey, prefixScorerBlockSizeDefault, logger),
81+
}
9982
}
10083

101-
func (c *Config) loadPluginInfo(plugins map[string]int, prefill bool, pluginNames ...string) {
84+
func loadPluginInfo(logger logr.Logger, prefill bool, pluginNames ...string) map[string]int {
85+
result := map[string]int{}
86+
10287
for _, pluginName := range pluginNames {
10388
var enablementKey string
10489
var weightKey string
@@ -110,13 +95,15 @@ func (c *Config) loadPluginInfo(plugins map[string]int, prefill bool, pluginName
11095
weightKey = pluginName + weightSuffix
11196
}
11297

113-
if env.GetEnvString(enablementKey, "false", c.logger) != "true" {
114-
c.logger.Info("Skipping plugin creation as it is not enabled", "name", pluginName)
98+
if env.GetEnvString(enablementKey, "false", logger) != "true" {
99+
logger.Info("Skipping plugin creation as it is not enabled", "name", pluginName)
115100
} else {
116-
weight := env.GetEnvInt(weightKey, 1, c.logger)
101+
weight := env.GetEnvInt(weightKey, 1, logger)
117102

118-
plugins[pluginName] = weight
119-
c.logger.Info("Initialized plugin", "plugin", pluginName, "weight", weight)
103+
result[pluginName] = weight
104+
logger.Info("Initialized plugin", "plugin", pluginName, "weight", weight)
120105
}
121106
}
107+
108+
return result
122109
}

pkg/scheduling/pd/scheduler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,26 @@ type Datastore interface {
5757

5858
// NewScheduler returns a new disaggregated Prefill/Decode filter, using the
5959
// provided configuration.
60-
func NewScheduler(ctx context.Context, schedCfg *config.Config, ds Datastore) (*Scheduler, error) {
60+
func NewScheduler(ctx context.Context, schedulerConfig *config.Config, ds Datastore) (*Scheduler, error) {
6161
prefixConfig := scorer.DefaultPrefixStoreConfig()
62-
prefixConfig.BlockSize = schedCfg.PrefixBlockSize
62+
prefixConfig.BlockSize = schedulerConfig.PrefixBlockSize
6363

6464
scheduler := &Scheduler{
65-
threshold: schedCfg.PDThreshold,
66-
pdEnabled: schedCfg.PDEnabled,
65+
threshold: schedulerConfig.PDThreshold,
66+
pdEnabled: schedulerConfig.PDEnabled,
6767
store: ds,
6868
prefixScorer: scorer.NewPrefixAwareScorer(ctx, prefixConfig),
6969
}
7070

7171
scheduler.prefill = scheduling.NewSchedulerWithConfig(
7272
ds,
73-
scheduler.generateSchedulerConfig(ctx, schedCfg.PrefillSchedulerPlugins,
73+
scheduler.generateSchedulerConfig(ctx, schedulerConfig.PrefillSchedulerPlugins,
7474
&filter.PrefillFilter{}),
7575
)
7676

7777
scheduler.decode = scheduling.NewSchedulerWithConfig(
7878
ds,
79-
scheduler.generateSchedulerConfig(ctx, schedCfg.DecodeSchedulerPlugins,
79+
scheduler.generateSchedulerConfig(ctx, schedulerConfig.DecodeSchedulerPlugins,
8080
&filter.DecodeFilter{}),
8181
)
8282

pkg/scheduling/pd/scheduler_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,17 @@ func TestPDSchedule(t *testing.T) {
136136
logger := testr.New(t)
137137
ctx = log.IntoContext(ctx, logger)
138138

139-
schedCfg := config.NewConfig(logger)
140-
schedCfg.PDEnabled = true
141-
schedCfg.PDThreshold = 5
139+
schedulderConfig := &config.Config{
140+
DecodeSchedulerPlugins: map[string]int{},
141+
PrefillSchedulerPlugins: map[string]int{},
142+
PDEnabled: true,
143+
PDThreshold: 5,
144+
PrefixBlockSize: 256,
145+
}
142146

143147
for _, test := range tests {
144148
t.Run(test.name, func(t *testing.T) {
145-
scheduler, _ := pd.NewScheduler(ctx, schedCfg, &fakeDataStore{pods: test.input})
149+
scheduler, _ := pd.NewScheduler(ctx, schedulderConfig, &fakeDataStore{pods: test.input})
146150
got, err := scheduler.Schedule(ctx, test.req)
147151

148152
if test.err != (err != nil) {

0 commit comments

Comments
 (0)