Skip to content

feat(epp): add encoder cache features to the latency predictor#2125

Open
kaushikmitr wants to merge 2 commits into
mainfrom
kaushikmitra/latency-predictor-encoder-cache-feature
Open

feat(epp): add encoder cache features to the latency predictor#2125
kaushikmitr wants to merge 2 commits into
mainfrom
kaushikmitra/latency-predictor-encoder-cache-feature

Conversation

@kaushikmitr

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds two multimodal encoder-cache features to the latency predictor: encoder_input_size (total size of the request's unique multimodal items) and encoder_matched_size (portion likely present in the target pod's encoder cache, from the multimodal producer's per-pod match data).

For multimodal requests, encoder compute dominates TTFT when the target pod's encoder cache misses, and this cost differs per pod. The predictor cannot see this today, so TTFT predictions carry large unexplained variance on multimodal workloads, degrading SLO-aware routing and admission. input - matched approximates the encoder work a pod would actually perform.

The features are opt-in via a new useEncoderCacheFeatures plugin parameter (default false; no behavior change for existing deployments). When enabled, the plugin consumes EncoderCacheMatchInfo as a required dependency so the DAG orders the multimodal producer first, auto-creating it if absent. encoderCacheMatchInfoProducerName selects a specific producer instance. Sizes flow into bulk predictions per endpoint and into TTFT training entries for the serving pod (prefill pod in disaggregated mode); TPOT paths send zeros, following the prefix_cache_score convention. The Bayesian Ridge path applies matching TTFT coefficients when present; models trained without them are unaffected.

Note: the Python predictor server needs matching schema support (encoder_input_size, encoder_matched_size, both non-negative ints, matched <= input) before tree models learn from these fields; until then they are sent and ignored.

Which issue(s) this PR fixes:

Fixes #

Release note:

The latency predictor supports optional multimodal encoder-cache features (encoder_input_size, encoder_matched_size), enabled with the useEncoderCacheFeatures parameter, to improve TTFT predictions for multimodal requests.

Copilot AI review requested due to automatic review settings July 21, 2026 21:02
@kaushikmitr
kaushikmitr requested a review from a team as a code owner July 21, 2026 21:02
@kaushikmitr
kaushikmitr requested review from liu-cong and vMaroon July 21, 2026 21:02
@github-actions github-actions Bot added kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 21, 2026
@kaushikmitr
kaushikmitr force-pushed the kaushikmitra/latency-predictor-encoder-cache-feature branch from 0fa4e83 to 735d47e Compare July 21, 2026 21:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds optional multimodal encoder-cache size features into the PredictedLatency data producer so TTFT predictions and training can account for per-pod encoder cache locality (via EncoderCacheMatchInfo), improving routing quality on multimodal workloads without changing default behavior.

Changes:

  • Plumbs encoder_input_size and encoder_matched_size through prediction and training request payloads (including Bayesian Ridge coefficient support + validation).
  • Adds an opt-in plugin config (useEncoderCacheFeatures, encoderCacheMatchInfoProducerName) that consumes encoder-cache match data as a required DAG dependency and captures per-endpoint sizes.
  • Extends tests to cover propagation and validation of the new encoder-cache fields.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/training.go Extends bulk prediction/training request construction to include encoder-cache size features.
pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/training_test.go Adds/updates unit tests to verify encoder size propagation into outgoing prediction/training requests.
pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/requestcontrol_hooks.go Ensures TTFT training collection passes encoder-cache matched size for the serving/prefill endpoint.
pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/README.md Documents the new opt-in encoder-cache feature flags and data source.
pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/prediction.go Feeds per-endpoint encoder-cache sizes into bulk prediction requests.
pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/plugin.go Adds config knobs and request-scoped context fields for encoder-cache feature plumbing.
pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/latencypredictorclient/types.go Adds encoder-cache fields to JSON request/entry schemas.
pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/latencypredictorclient/training.go Validates encoder-cache fields for training entries.
pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/latencypredictorclient/prediction.go Validates encoder-cache fields for prediction requests and applies coefficients in Bayesian Ridge TTFT.
pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/latencypredictorclient/prediction_test.go Adds unit tests for encoder-cache validation and Bayesian Ridge coefficient application.
pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/dataproducer_hooks.go Captures encoder-cache input/matched sizes from endpoint attributes and adds required dependency when enabled.
pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/dataproducer_hooks_test.go Adds tests covering consumption gating and size capture behavior for enabled/disabled modes.

Comment on lines +137 to +141
inputSize := sumItemSizes(matchInfo.RequestItems())
matchedSize := sumItemSizes(matchInfo.MatchedItems())
predictedLatencyCtx.encoderInputSize = inputSize
predictedLatencyCtx.encoderMatchedSizeForEndpoints[endpoint.GetMetadata().NamespacedName.Name] = matchedSize
logger.V(logutil.DEBUG).Info("Encoder cache sizes for pod",
Comment on lines +226 to +231
if i < len(encoderInputSizes) {
bulkRequests[i].EncoderInputSize = encoderInputSizes[i]
}
if i < len(encoderMatchedSizes) {
bulkRequests[i].EncoderMatchedSize = encoderMatchedSizes[i]
}
@ahg-g

ahg-g commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Did we do any evaluation?

@kaushikmitr

Copy link
Copy Markdown
Contributor Author

Did we do any evaluation?

yes, https://github.com/llm-d/llm-d/pull/2078/changes

Multimodal requests incur encoder compute that dominates TTFT when the
target pod's encoder cache misses, and the predictor cannot see this
per-pod difference today. Feed the multimodal encoder-cache match data
as two features, encoder_input_size and encoder_matched_size, opt-in
via useEncoderCacheFeatures so existing deployments are unaffected.

Signed-off-by: Kaushik Mitra <kaushikmitra@google.com>
The predictor rejects matched > input, so inconsistent match data or
mismatched feature slices would fail validation and drop the whole
prediction or training entry instead of degrading gracefully.

Signed-off-by: Kaushik Mitra <kaushikmitra@google.com>
@kaushikmitr
kaushikmitr force-pushed the kaushikmitra/latency-predictor-encoder-cache-feature branch from 7dc0fa9 to 4d605c3 Compare July 23, 2026 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. 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.

3 participants