TensorTonic
Study Plans
Study Plan
Route Cache-Aware Prefill Requests
Language ModelsInference
Hard

Implement cache-aware request routing. Track full assigned tokens and uncached prefill load independently for every worker. A worker is feasible when adding the full request length remains within capacity. Rank feasible workers by longest cached prefix, lowest projected uncached load, greatest remaining capacity after assignment, then lowest worker ID. Assign -1 when no worker is feasible. Return a dictionary with assignments and worker_uncached_loads in worker input order.

Loading visualization...

Examples

Input: request_token_counts = [10,8], cached_prefix_lengths = [[8,0],[0,6]], worker_ids = [2,1], worker_capacities = [20,20]

Output: {"assignments":[2,1],"worker_uncached_loads":[2,2]}

Explanation: Each request selects the worker holding its longest reusable prefix.

Input: request_token_counts = [4], cached_prefix_lengths = [[0,0]], worker_ids = [5,2], worker_capacities = [10,10]

Output: {"assignments":[2],"worker_uncached_loads":[0,4]}

Input: request_token_counts = [6], cached_prefix_lengths = [[3,4]], worker_ids = [0,1], worker_capacities = [5,5]

Output: {"assignments":[-1],"worker_uncached_loads":[0,0]}

Hint 1

Track assigned_tokens and uncached_loads separately.

Hint 2

Build one lexicographic key for the four routing priorities.

Requirements

  • Process requests in arrival-list order.
  • Test feasibility with full assigned request tokens, independently of cache reuse.
  • Apply every routing tie-breaker in the documented order.
  • Add only the selected request's uncached suffix to prefill load.
  • Leave worker state unchanged for infeasible requests and do not modify inputs.

Constraints

  • Request counts, cached prefixes, worker IDs, and capacities are nonnegative Python integers.
  • Worker IDs are unique and cached_prefix_lengths has one row per request and one column per worker.
  • Every cached prefix is at most its request token count.
  • Empty request lists are valid.
Try Similar Problems
Simulate Continuous Decode BatchingHardFind Reusable Prefixes in a KV TrieMediumDecode Attention with a KV CacheHardPerform Exact Speculative SamplingHardPlan KV-Cache CapacityMediumMeasure Kernel Timeline UtilizationMediumRecover an IsoFLOP Compute-Optimal FrontierHardFit a Data Power Law with a Noise FloorHardImplement Speculative Decoding and Token VerificationHardBeam Search DecodingHardImplement Prefix Cache Matching and ReuseMediumText Generation SamplingMedium

Accepts: array

Accepts: array

Accepts: array

Accepts: array

You must run your code first.

Route Cache-Aware Prefill Requests

Language ModelsInference
Hard

Implement cache-aware request routing. Track full assigned tokens and uncached prefill load independently for every worker. A worker is feasible when adding the full request length remains within capacity. Rank feasible workers by longest cached prefix, lowest projected uncached load, greatest remaining capacity after assignment, then lowest worker ID. Assign -1 when no worker is feasible. Return a dictionary with assignments and worker_uncached_loads in worker input order.

Loading visualization...

Examples

Input: request_token_counts = [10,8], cached_prefix_lengths = [[8,0],[0,6]], worker_ids = [2,1], worker_capacities = [20,20]

Output: {"assignments":[2,1],"worker_uncached_loads":[2,2]}

Explanation: Each request selects the worker holding its longest reusable prefix.

Input: request_token_counts = [4], cached_prefix_lengths = [[0,0]], worker_ids = [5,2], worker_capacities = [10,10]

Output: {"assignments":[2],"worker_uncached_loads":[0,4]}

Input: request_token_counts = [6], cached_prefix_lengths = [[3,4]], worker_ids = [0,1], worker_capacities = [5,5]

Output: {"assignments":[-1],"worker_uncached_loads":[0,0]}

Hint 1

Track assigned_tokens and uncached_loads separately.

Hint 2

Build one lexicographic key for the four routing priorities.

Requirements

  • Process requests in arrival-list order.
  • Test feasibility with full assigned request tokens, independently of cache reuse.
  • Apply every routing tie-breaker in the documented order.
  • Add only the selected request's uncached suffix to prefill load.
  • Leave worker state unchanged for infeasible requests and do not modify inputs.

Constraints

  • Request counts, cached prefixes, worker IDs, and capacities are nonnegative Python integers.
  • Worker IDs are unique and cached_prefix_lengths has one row per request and one column per worker.
  • Every cached prefix is at most its request token count.
  • Empty request lists are valid.
Try Similar Problems
Simulate Continuous Decode BatchingHardFind Reusable Prefixes in a KV TrieMediumDecode Attention with a KV CacheHardPerform Exact Speculative SamplingHardPlan KV-Cache CapacityMediumMeasure Kernel Timeline UtilizationMediumRecover an IsoFLOP Compute-Optimal FrontierHardFit a Data Power Law with a Noise FloorHardImplement Speculative Decoding and Token VerificationHardBeam Search DecodingHardImplement Prefix Cache Matching and ReuseMediumText Generation SamplingMedium

Accepts: array

Accepts: array

Accepts: array

Accepts: array

You must run your code first.