KatInterview

Hardware-Aware Routing for Multi-Phase LLM Inference

Machine LearningModel answer
MediumModel answerMachine Learningml-systemsinferencescheduling

Last updated

Build a system that dynamically assigns prefill and decode stages of large language model inference to heterogeneous hardware pools based on profiled capabilities.

You are building an inference service that processes batch jobs using large language models. The service has access to multiple hardware pools with varying characteristics: some have high memory and throughput, others are older units better suited for less compute-intensive work.

Your system should support phase-aware execution: the initial prefill stage (processing the input prompt and generating the KV cache) can run on different hardware than the decode stage (autoregressively generating output tokens). Jobs arrive with deadlines and belong to tenants with different priority levels.

Design the end-to-end system covering:

  1. Job lifecycle: How jobs are submitted, admitted, scheduled, and tracked through completion
  2. Hardware profiling and placement: How you measure and model each hardware pool's performance for different phases, models, and batch configurations
  3. Routing logic: How you decide which hardware executes prefill vs. decode for each job, considering queues, batching opportunities, transfer overhead, and deadline pressure
  4. Coordination and reliability: How prefill and decode phases communicate, how you handle failures and retries, and how you prevent stragglers from missing deadlines
  5. Resource fairness: How you prevent any single tenant from monopolizing capacity while respecting priorities
  6. Observability: What metrics and dashboards you expose, and how you validate that routing decisions improve utilization and meet deadlines

Assume you support multiple model families (7B to 70B parameters), quantization formats (FP16, INT8, INT4), and sequence lengths up to 8K tokens. Transferring KV cache state between hardware pools has measurable latency and bandwidth cost.

Walk through your architecture, key algorithms, and the trade-offs in your design. Discuss how your approach adapts to shifting workloads and hardware characteristics over time.

Hints

Hint 1

Consider how batch size affects throughput differently for prefill (compute-bound, benefits from larger batches) versus decode (memory-bound, constrained by KV cache size).

Hint 2

Profile each hardware pool offline with representative workloads, then use these profiles at runtime to estimate queue delay and execution time for placement decisions.

Hint 3

Think about when it makes sense to keep prefill and decode colocated on the same hardware versus splitting them—transfer cost and queueing dynamics both matter.