Shopify engineer Cody Mazza-Anthony presents the 'flywheel,' a continual learning loop built on PyTorch and vLLM that lets task-specific models beat frontier models at lower cost and latency.
Key Takeaways
- A high-quality, expert-validated ground-truth dataset and a judge calibrated to it are the foundation of the whole loop.
- Continuous production failure detection, repair, and retraining lets a specialized model outperform frontier models over time while reducing cost.
- Prompt compression via learned special tokens and tuned vLLM parameters can significantly reduce latency and increase throughput without changing model weights.
What the video covers
- The flywheel is Shopify's continual learning loop built on PyTorch and vLLM, designed to outperform frontier models on specific tasks at a fraction of the cost while improving latency and throughput.
- The loop begins with building a reliable, trustworthy ground-truth dataset aligned with what 'good' means for the product, described as the most important and most often done wrong step.
- Teams should launch with a frontier model to start collecting data, then use the flywheel after shipping to production.
- An LLM judge is built from a rubric of criteria with integer scores (0, 1, 2) and detailed explanations; the more detailed the explanations, the better the judge calibrates.
- Two senior product experts blind-label about 50 conversations each, and agreement is measured with Cohen's kappa; disagreements prompt revisiting product understanding before continuing.
- The judge is calibrated to human labels using prompt optimizers such as GEPA and ACE, with human agreement treated as the ceiling rather than perfection.
- Production failures are detected with the trusted judge, repaired by a council of high-thinking models that replay conversations or regenerate outputs with injected hints, then rescored.
- High-scoring repaired examples are added back into the training data, and a new candidate checkpoint is trained.
- Using the buyer profile model as a case study, the training set grew from about 29,000 examples and the model quickly outperformed a frontier model on that task.
- Inference is optimized with prompt compression (distillation of a long system prompt into learned special tokens via KL divergence against a teacher), which shrinks prefill and improves latency and throughput while keeping model weights frozen.
Chapters
- 00:00Introduction to Shopify's Flywheel
- 00:26The Continual Learning Loop Overview
- 00:53Building Ground Truth and Starting with a Frontier Model
- 01:44Building an LLM Judge: Rubrics and Human Labeling
- 02:51Calibrating the Judge to Human Agreement
- 03:13Production Failures and Repair with the Buyer Profile Example
- 03:56Results: Outperforming Frontier Models
- 04:16Inference Optimization with Prompt Compression and vLLM Tuning
- 05:01Recap and Closing
Full Transcript — Download SRT & Markdown
Speaker A
Hey everyone. So, [sighs] my name's Cody, and today I'm going to be talking to you about the flywheel, which is Shopify's continual learning loop that's built on top of PyTorch and VLLM. So, excited to talk to you about
Speaker A
it today. So, continual learning allows us to outperform frontier models on a on a task that is specific at a fraction of the cost while improving latency and throughput.
Speaker A
And the way it works is this image right here. And the first thing we start with is building out a reliable, trustworthy ground truth data set that is aligned with what good looks like for our product. It's the most important piece,
Speaker A
and it's the piece that most teams get wrong. Now, once you have this this high-quality data set, what you do is you want to calibrate an LLM judge to that data set so that you can actually, you know, score large amounts of
Speaker A
samples, whether they be conversations or buyer profiles or anything like that. Now, when you're building out your harness, so your tools, your prompt, it's good to go to market with a frontier model just to start so you start collecting data.
Speaker A
Now, this is where the flywheel really kicks in after. What you do is, once it's shipped to production, you want to identify production failures using your judge.
Speaker A
And then you want to repair them. And after that, you want to add them to your training data, and then you want to train a new candidate, a new checkpoint.
Speaker A
And then the final step is making sure you're actually doing proper inference optimization, and I'm going to talk a little bit about just compression, which can cut your system prompt down uh significantly to cut prefill and thus improve latency and throughput.
Speaker A
So, let's talk a little bit about how a judge is built. We like to start with something called a rubric. Now, a rubric is very simple. Uh it has a list of criteria. An example criteria would be like safety
Speaker A
or goal fulfillment or something like that. And then you want to assign a integer score. We like 0 1 2.
Speaker A
And then you also want to provide a detailed explanation. The more detailed the explanation, the better your judge is going to calibrate. So, it's really important to get that part right.
Speaker A
Now, I like to take the two most senior experts at that product, and I want them to do a blind labeling. So, So, let's say they do 50 conversations each, and then I want to measure their uh agreement with something called the
Speaker A
Cohen's kappa. Now, usually the first time around, they're not really going to agree. So, you have to go back to one, make sure you understand the product, understand what good looks like, and then continue.
Speaker A
Now, once you have pretty good uh Cohen's kappa, then you can actually calibrate your judge. So, we like to use prompt optimizers like Jeppa, Ace, until it until the judge is similar to the human.
Speaker A
Now, it's important to keep in mind that human agreement is the ceiling. We're not looking for a perfect here. We're looking for as good as humans.
Speaker A
Okay, so now we have a judge. Let's look at an example from something from production called the buyer profile. The buyer profile takes shopping activity and converts into a structured profile that has the taste and interest of the
Speaker A
buyer. So, first thing we do is we use our judge that we trust to detect low-scoring production failures.
Speaker A
Then we want to repair. The way we we repair those failures is we actually use a council of high-thinking models to actually replay the the conversation or regenerate the buyer profile with a hint that's uh injected.
Speaker A
Then we rescore, and we take the ones that are uh that are high-scoring and add it to our training data.
Speaker A
So, this graph here is a is a real graph that's that is focuses on the buyer profile model. So, on July 23rd, we started with around 29,000 uh examples, and then as we sample from production, correct the failures, add it
Speaker A
back to our training data, you can see that you can quickly outperform a frontier model on that task.
Speaker A
So, the last thing is that the flywheel optimizes inference. So I mentioned justing earlier. The way justing works is you have a teacher and a student. The teacher has the full system prompt, so you are a helpful assistant {dot} {dot} {dot}
Speaker A
and the student has has the justed prompt sorry, justed tokens, which is a series of special tokens. So like G1, G2, G3, and so on.
Speaker A
And we minimize the difference between the teacher and the student using KL divergence, and we're actually learning the embedding representation of those special tokens.
Speaker A
Once you've done that, you end up with a model that has a much smaller much smaller prompt, which cuts your prefill, which improves your latency and throughput.
Speaker A
It's important to note here that the model weights stay frozen. We're not actually changing any model weights here. We're just learning the embedding, and it's really straightforward to deploy afterwards.
Speaker A
On the right, we use auto research to find the optimal set of VLM parameters to make sure we're getting the most throughput we can.
Speaker A
So just to recap, the the flywheel is collecting ground truth, creating a reliable judge, going to production, and collecting uh production failures, repairing them, adding them to your training data, and arriving at a new model. And over time,
Speaker A
you end up performing very uh you end up outperforming frontier models while reducing cost.
Speaker A
Thank you. [applause]
Topics:continual learningPyTorchvLLMLLM as judgeflywheelprompt compressiondistillationCohen's kappainference optimizationShopify











