-
Notifications
You must be signed in to change notification settings - Fork 69
update algorithm parameters from env variables #580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hi @kaushikmitr. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
✅ Deploy Preview for gateway-api-inference-extension ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
pkg/epp/scheduling/scheduler.go
Outdated
) | ||
|
||
// getEnvFloat gets a float64 from an environment variable with a default value | ||
func getEnvFloat(key string, defaultVal float64, logger logr.Logger) float64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move these env var parsing helper functions to /util/env/env.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
It would likely blow up the size of this PR tho. Global vars are run before the main func. And our filter chain is a global var, which consumes these variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or do you just mean the parsing funcs themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it makes sense to have a separate env pkg within utils which has the env parsers. updated accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments, I would generally suggest restructuring this.
However, with kubecon so close, and we need this for v0.3.0, and if you are short on time... It may be acceptable to mark TODOs all over this, and add issues the refactor this
pkg/epp/scheduling/scheduler.go
Outdated
) | ||
|
||
// getEnvFloat gets a float64 from an environment variable with a default value | ||
func getEnvFloat(key string, defaultVal float64, logger logr.Logger) float64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or do you just mean the parsing funcs themselves.
} | ||
|
||
// LoadConfig loads configuration from environment variables | ||
func LoadConfig() Config { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically env variables are processed in the main func. It would be considered surprising to process an env var in a package like this and load it into a global var.
The unification of these config variables allows a reader to be able to reliably find the config, rather than having to hunt for its consumption.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree with this, will tackle it in a separate issue as suggested above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add a global struct to hold all env vars for discoverability. I am OK with a follow up.
pkg/epp/scheduling/scheduler.go
Outdated
@@ -108,6 +177,15 @@ var ( | |||
} | |||
) | |||
|
|||
// UpdateLoraAffinityThreshold updates the LoRA affinity threshold value | |||
// This is useful for testing or dynamic reconfiguration | |||
func UpdateLoraAffinityThreshold(newValue float64, logger logr.Logger) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it's only being consumed in tests, could we make this a test util func for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, moved it to test
pkg/epp/scheduling/scheduler.go
Outdated
|
||
// Log current configuration values for debugging purposes. | ||
logger.V(logutil.VERBOSE).Info("Scheduler configuration", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TRACE
is probably preferred since this would run on every request, and its unlikely to change frequently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes agreed.
pkg/epp/util/env/env.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls add unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added tests
pkg/epp/scheduling/scheduler.go
Outdated
LoraAffinityThreshold float64 | ||
} | ||
|
||
var ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: these can be const
pkg/epp/scheduling/scheduler.go
Outdated
|
||
// Log current configuration values for debugging purposes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the config is only loaded once, why do we log it in every request? it's already logged in LoadConfig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its logutil.TRACE, so should be logged in unless tracing is on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still, I would expect config parameters to be logged once on startup, you can move this log line to NewScheduler
for now, and later we should move it to main
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for this since this is already logged on startup. Also logging such environment configurable should be DEFAULT level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/epp/scheduling/scheduler.go
Outdated
LoraAffinityThreshold: envutil.GetEnvFloat("LORA_AFFINITY_THRESHOLD", defaultLoraAffinityThreshold, baseLogger), | ||
} | ||
|
||
baseLogger.V(logutil.DEFAULT).Info("Scheduler configuration loaded", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: You can simply log the config object itself, logger.Info("Scheduler configuration loaded", "config", config)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
// LoadConfig loads configuration from environment variables | ||
func LoadConfig() Config { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add a global struct to hold all env vars for discoverability. I am OK with a follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @kfswain that there are followups on this, but given the short kubecon timeline I am fine.
The change looks good to me except for a couple nits, and adding unit tests for the env parsing. Will let others approve.
pkg/epp/scheduling/filter_test.go
Outdated
// Set a specific test value for this test | ||
testThreshold := 0.75 // 75% | ||
// Inline update of threshold value | ||
func(newValue float64, logger logr.Logger) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry perhaps I wasn't super clear by inline the function
. Let's just do config.LoraAffinityThreshold = newValue
. I am fine without the logging since this is just in tests. If you want logging, simply add t.Logf()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/epp/scheduling/scheduler.go
Outdated
|
||
// Log current configuration values for debugging purposes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for this since this is already logged on startup. Also logging such environment configurable should be DEFAULT level.
/ok-to-test |
added unit test for env parser |
The PR has some lint errors, run |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahg-g, kaushikmitr The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This pull request introduces a significant refactor to make scheduler configuration values dynamically configurable through environment variables. The changes include creating a new
Config
struct to hold configuration values, updating various functions to use these new configuration values, and adding utility functions to load configuration from environment variables.Key changes include:
Configuration Management:
Config
struct to hold configuration values (KVCacheThreshold
,QueueThresholdCritical
,QueueingThresholdLoRA
,LoraAffinityThreshold
) and initialized it using environment variables (pkg/epp/scheduling/scheduler.go
).getEnvFloat
andgetEnvInt
to retrieve configuration values from environment variables with default fallbacks (pkg/epp/scheduling/scheduler.go
).Function Updates:
leastQueuingFilterFunc
andloRASoftAffinityFilter
to use the new configuration values (pkg/epp/scheduling/filter.go
). [1] [2]Testing Enhancements:
TestLoRASoftAffinityDistribution
to set and restore configuration values for testing purposes (pkg/epp/scheduling/filter_test.go
). [1] [2] [3]Scheduler Enhancements:
Schedule
method for better debugging (pkg/epp/scheduling/scheduler.go
).UpdateLoraAffinityThreshold
function to allow dynamic updates of the LoRA affinity threshold (pkg/epp/scheduling/scheduler.go
).[Copilot is generating a summary...]tested with:
- name: KV_CACHE_THRESHOLD
value: "0.9"
- name: QUEUE_THRESHOLD_CRITICAL
value: "10"
- name: QUEUING_THRESHOLD_LORA
value: "23"
- name: LORA_AFFINITY_THRESHOLD
value: "0.7"
logs printed:
2025-03-26T20:44:36Z LEVEL(-3) scheduling/scheduler.go:206 Scheduler configuration {"request": {"Model":"meta-llama/Llama-2-7b-hf","TargetModels":null,"ResolvedTargetModel":"meta-llama/Llama-2-7b-hf","Critical":true}, "KVCacheThreshold": 0.9, "QueueThresholdCritical": 10, "QueueingThresholdLoRA": 23, "LoraAffinityThreshold": 0.7}
2025-03-26T20:44:36Z LEVEL(-3) scheduling/scheduler.go:214 Scheduling a request.