Skip to content

Update lora affinity to be a scorer. #1121

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rlakhtakia
Copy link
Contributor

#967

Changes: Added new scorer for v2 scheduler.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 8, 2025
Copy link

netlify bot commented Jul 8, 2025

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit a7214d7
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/686fe8e8753b1300081c7cce
😎 Deploy Preview https://deploy-preview-1121--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot k8s-ci-robot requested review from liu-cong and robscott July 8, 2025 17:19
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rlakhtakia
Once this PR has been reviewed and has the lgtm label, please assign jeffwan for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 8, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @rlakhtakia. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 8, 2025

// LoraAffinityScorer scores list of candidate pods based on KV cache utilization.
type LoraAffinityScorer struct {
name plugins.TypedName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typedNamed

if active {
scores[pod] = 1
} else if len(pod.GetMetrics().ActiveModels)+len(pod.GetMetrics().WaitingModels) < pod.GetMetrics().MaxActiveModels {
scores[pod] = 0.8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did you select these numbers? is it based on some tests? performance comparison? intuition?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1; how does this compare to the approach we have in the decision tree plugin.

@kaushikmitr pls take a look as well

name string
request *types.LLMRequest
pods []types.Pod
expectedScoresPod map[int]float64 // Map of pod index to expected score
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use a map[NamespacedName]float64 (map from pod identifier to expected score)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good suggestion. I wonder if map[string]float64 might be better. We can easily get the pod's name from the target pod directly, which would avoid needing to declare NamespacedName repeatedly in the test cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Score function we get back map[Pod]float64, where the Pod representation includes NamespacedName, Address and Labels.
I assume we can either use NamespacedName.String() or Address. both will do the work.

@ahg-g
Copy link
Contributor

ahg-g commented Jul 8, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 8, 2025
@nirrozenbaum
Copy link
Contributor

cc @mayabar

@ahg-g
Copy link
Contributor

ahg-g commented Jul 9, 2025

This is great, this will help us move off of the decision tree plugin

@kaushikmitr
Copy link
Contributor

In the current Lora affinity algorithm we have loraaffinitythreshold = 0.99. We use this to prefer a pod that already has the Lora loaded over a pod that does not have the Lora loaded but has room with 99% probability. This ensures that we maintain Lora affinity while spreading it out at high Lora traffic. I am guessing scoring can conceptually achieve that but it seems we are always picking the highest score.

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 10, 2025
@rlakhtakia rlakhtakia force-pushed the scorer branch 2 times, most recently from 7a8ba08 to f8f767d Compare July 10, 2025 05:03
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 15, 2025
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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.

var _ framework.Scorer = &LoraAffinityScorer{}

// LoraAffinityScorerFactory defines the factory function for LoraAffinityScorer.
func LoraAffinityScorerFactory(name string, _ json.RawMessage, _ plugins.Handle) (plugins.Plugin, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: perhaps allow setting DefaultLoraAffinityScorerWeight via configuration parameters in the config file?
We're trying to avoid using environment variables (e.g., added in runner.go).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are planning to have GIE default weight for scorers. if no weight specified in the config the weight will default to 1 automatically by the config api code.
this will be pushed in a separate, not in scope of this PR of course.

@liu-cong
Copy link
Contributor

Do you have some benchmark numbers to share?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants