Projects / llm-inference · 2026 · Coursework (ECE326, Computer Systems)

LLM Inference & Performance Optimization

An LLM inference pipeline engineered for throughput: NumPy vectorization, then concurrency restructures profiled against the clock. Course benchmark: 3.2x agent throughput with bit-identical transcripts.

What it is: A systems coursework project (University of Toronto ECE326): implement and optimize an LLM inference pipeline in Python. What it does: handles request workloads through a token-generation path that I measured, profiled, and restructured for speed.

What I did

  • Engineered the pipeline around NumPy array programming, pushing per-token Python loops into vectorized operations so the math runs where it's fast.
  • Vectorized the attention kernels (rotary position encoding, grouped-query reduction) against the course's C numerical oracle, so the restructured math stays within single-precision noise of the reference and end-to-end completions come out token-for-token identical.
  • Rebuilt the agent benchmark on a cooperative-coroutine scheduler. Generator-based tasks over a hand-rolled deadline queue: no threads, no asyncio, no scheduler library, plain Python lists, so four concurrent agent trajectories share one server without any of the machinery doing parallelism behind my back.
  • Profiled end-to-end latency to find where time actually went, rather than where it felt like it went, vectorization strategy by vectorization strategy.

What the benchmark measured

All figures are coursework figures from the assignment's own harness, a local single-threaded model server on a lab machine running small Llama-family story checkpoints (260K and 15M parameters, public weight format). They live here, not on the homelab page, on purpose.

  • The workload: 4 agent trajectories, 12 model calls, 48 generated tokens per profile, run twice: sequential baseline vs coroutine scheduler.
  • Sequential took 17.0 s wall; the coroutine run finished the same fixture in 5.3 s, a 3.2x throughput ratio, with the harness verifying both runs produced identical transcripts. Correctness first, speed second, in that order in the report.
  • The ceiling is honest and physical: coroutines overlap waiting, not computing, so the ratio is bounded by the slowest agent's critical path (~3-3.5x expected on this fixture, not 4x), and the rubric explicitly failed anyone claiming the model calculation itself got faster. A suspiciously perfect 4.0x was listed as a red flag before we could trip over it.

The schedule, drawn from the trace

The whole 3.2x in one picture: every rectangle below is a measured interval, not a sketch.

model call (blocking) tool wait queued: thread busy on another call idle-wait to earliest deadline Sequential baseline - wall 17.03 s: 2.6 s of calls + 14.4 s of waits, paid one at a time A B C D Coroutine scheduler - wall 5.33 s: same 12 calls, 15.0 s of observed waits stacked A B C D srv idle idle model server: 12 requests, never two in flight - a blocking call freezes the one scheduler thread (D starts queued behind three calls) 5.33 s 17.03 s 11.7 s of wall reclaimed by overlapping waits, not compute: 3.2x 0 2 4 6 8 10 12 14 16 seconds - one shared clock, both panels identical scale Coursework benchmark: one measured run per profile, plotted from its own per-turn timestamps; trajectories relabeled A-D. Compute is never parallel here - the 12 calls stay ~2.6 s either way. The wall floors at the slowest trajectory's critical path (lane C: 4.5 s of serial waits + its 3 calls), so 3.2x is the physics of this fixture, not a shy 4x.
Parallel agent trajectories, one measured run, plotted from the harness's own per-turn timestamps. Sequential (top) pays every tool wait in full; the coroutine scheduler (bottom) stacks the waits under each other while the 12 model calls stay strictly one at a time - 17.03 s to 5.33 s, 3.2x, transcript-identical.

Why it's on a portfolio

Inference optimization is the same fight I work on at MDA: bounded resources, a hard latency budget, and only profiling as an oracle. The difference is the scale of the stakes; here it was a coursemark.

The habit that transferred from this lab to my home server: wall times don't transfer between machines; invariants do: identical transcripts, 12/12 completions, token counts. Reports cite ratios and correctness gates; machine-specific numbers always name the machine that produced them (anonymized here, as the benchmark rules demanded).

Coursework project; implementation details stay inside course rules. Happy to discuss the optimization methodology and what each experiment cost or saved.

← all projectsQuestions? Email me