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

@rlakhtakia rlakhtakia commented Jul 8, 2025

#967

Changes: Added new scorer for v2 scheduler.

Benchmark details:

Coefficient of Determination (R^2) between before and after runs:
avg_normalized_time_per_output_token_ms R^2 = 0.9887
p90_per_token_latency_ms R^2 = 0.9691
p90_latency_ms R^2 = 0.9633
num_prompts_attempted R^2 = 1.0000
num_prompts_succeeded R^2 = 0.9951

image

@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 e3f2eb7
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/687ff1fb4f95700008dad953
😎 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 3 times, most recently from f8f767d to a7214d7 Compare July 10, 2025 16:23
@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
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?

@rlakhtakia
Copy link
Contributor Author

Benchmark details:

Coefficient of Determination (R^2) between before and after runs:
avg_normalized_time_per_output_token_ms R^2 = 0.9887
p90_per_token_latency_ms R^2 = 0.9691
p90_latency_ms R^2 = 0.9633
num_prompts_attempted R^2 = 1.0000
num_prompts_succeeded R^2 = 0.9951

image

@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 22, 2025
@ahg-g
Copy link
Contributor

ahg-g commented Jul 23, 2025

Thanks @rlakhtakia; what exactly is the experiment setup? Can you please document that?

// Determine the model server's suitability score based on adapter load status and capacity.
switch {
// Ideal: The adapter is already active on this model server.
case active:
Copy link
Contributor

@liu-cong liu-cong Jul 23, 2025

Choose a reason for hiding this comment

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

The ideal case should be:

  1. The requested lora is active AND there are no waiting loras (otherwise the waiting ones will be served first given the request FIFO queue).

@liu-cong
Copy link
Contributor

@rlakhtakia

Thanks for the benchmark results, it looks very similar to the filter based lora affinity, great!

Can you provide more details on the benchmark?

  1. The exact benchmark setup (I believe you followed the regression test guide, if so, pls be explicit). Also clarify the baseline EPP version.
  2. Add a graph about throughput
  3. The graphs show the aggregated results for all LoRAs? If so, can you also provide the specific graphs for a high traffic LoRA and low traffic LoRA?

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. 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