Skip to content
Inference Academy

Lab: modify vLLM's scheduler and benchmark the change

Change real vLLM code and measure it. Install vLLM v0.34.0 from source in editable mode, add a switch that changes which request the scheduler preempts (the default most recently admitted, the one with the fewest computed tokens, or the one with the most), write a unit test that runs without a GPU, then benchmark all three under KV cache pressure with vllm bench serve and explain the results from the code.

By

Key takeaways

  • An editable install with precompiled kernels lets you change vLLM's Python code and rerun in seconds.
  • Test scheduler changes without a GPU: tests/v1/core builds a scheduler with a fake KV cache and fake model outputs.
  • Create pressure on purpose (a small KV cache, long prompts, a high request rate) or a scheduler change has nothing to act on.
  • Predict before measuring: which policy should preempt least, recompute least, or hurt the tail most? Then explain each result from the code.
120 min · verified 2026-11Hands-on labPro
Share

Goal: make a real change to vLLM's scheduler, prove it is correct with a unit test, measure it under load, and explain what you see from the code you read in this track.

You need:

  • For the code change and the unit test: a Linux machine with Python 3.11 to 3.14 (what v0.34.0 supports), Git and uv. No GPU. On macOS, vLLM's setup switches to a CPU build, which compiles from source and takes longer; the unit test still works there.
  • For the benchmark: one NVIDIA GPU with at least 16 GB (rented is fine) and a small model you have access to, for example a 1B to 3B instruct model.
  • About two hours, plus GPU time. Background: the scheduler and the KV cache manager.

Honest limits. We wrote this lab against the v0.34.0 source and checked every file, line and flag it names there. We have not run the benchmark on a GPU for this page, so it shows no results: the numbers are yours to measure. The -e . install with VLLM_USE_PRECOMPILED=1 downloads prebuilt kernels that match the commit; if that fails on your platform, follow docs/contributing/README.md for a full build. The scheduler is internal code, not a public API: the change is for learning, not for production.

#The change

When allocate_slots() fails, the FCFS scheduler preempts self.running[-1], the most recently admitted request. You will add a switch, read from an environment variable, with three choices:

LAB_PREEMPT_VICTIM Victim Hypothesis to test
last (default) The most recently admitted request Baseline: protects old requests, but the newest may be preempted again and again
fewest_computed The running request with the fewest computed tokens Least work to redo, but may free too few blocks, so more preemptions per step
most_computed The running request with the most computed tokens Frees the most blocks per preemption, but the most work to redo, and long requests suffer

Write your prediction for each before you build anything: preemption count, throughput, p50 and p99 TTFT, p99 end-to-end latency.

The rest is Pro

Keep reading this full lab

Pro unlocks this full lab, every advanced lesson, the hands-on labs and completion certificates.

One year

$25

365 days, no auto-renewal

Lifetime Best value

$75

pay once, keep it forever

7-day refund, no questions asked. One payment, no auto-renewal.Compare plansHave a licence key?

Sandip MaityBuilt by Sandip Maity, who runs self-hosted LLM inference in production.

Not ready? Keep learning free

Free lessons from vLLM Internals, no sign-up. Or follow the free roadmap →

Not ready? Take the free 5-day email course

One short email a day for five days, each built on a free lesson, then the occasional new lesson or offer. Unsubscribe in one click.

Still to come in this lab

  1. Step 1: install from source
  2. Step 2: make the change
  3. Step 3: a unit test without a GPU
  4. Step 4: benchmark under pressure
  5. Step 5: report
  6. Stretch goals
  7. Checklist
  8. Where to go next

You will be able to answer

  • Why does the lab cap the KV cache with --kv-cache-memory-bytes before benchmarking?
  • Preempting the request with the most computed tokens frees the most blocks. What is its likely cost?
  • Your new policy lowers the preemption count by 30% but p99 TTFT gets worse. What should the report say?