Proxy-KD: Knowledge Distillation of Black-Box Large Language Models
Train an open model to imitate GPT-4, then distill a small model from the open model's token probabilities.
GPT-4 returns the words it chose and none of the probabilities behind them. Proxy-KD fine-tunes Llama-2-70B on GPT-4's replies, aligns it further with iterative preference optimization, and uses its next-token distributions as soft labels for a Llama-2-7B student, weighted per example by how well the 70B model predicts GPT-4's reply.
Explaining the paperKnowledge Distillation of Black-Box Large Language ModelsWith the same 7B student and the same GPT-4 data, the method averages 56.78 on six benchmarks against 53.66 for plain fine-tuning on the GPT-4 text. Inserting the 70B model without first aligning it to GPT-4 scores 52.82, below having no middle model at all.
Suppose you want a 7B open model, one you can run on your own hardware, to answer reasoning questions the way GPT-4 does. The standard tool is knowledge distillation: a large teacher model produces outputs and a small student is trained to reproduce them. Its most informative form has the student match the teacher's full probability distribution over the next token at every position of an answer. The paper treats GPT-4 as a black box, reachable only through API calls that return generated text, so the distribution is unavailable and the student can only be trained on the words GPT-4 emitted.
Proxy-KD (Chen et al., Sun Yat-sen University and Alibaba, January 2024) adds a third model between the two. An open Llama-2-70B, the proxy, is first trained to imitate GPT-4: fine-tuned on GPT-4's replies, then aligned further with 16 rounds of preference optimization in which GPT-4's reply is always ranked above the proxy's own. The proxy's weights are open, so its next-token distribution can be computed at every position of any text, and the 7B student is then trained on GPT-4's text and the proxy's distributions together.
The page follows the method in order: what a soft label carries that a hard label does not; why a black-box teacher yields only hard labels; how the proxy is aligned to GPT-4 with fine-tuning and DPO, including a sign error in the paper's printed DPO loss; how the student learns from both sources; and the per-example weight that discounts the proxy where it predicts GPT-4 poorly. The last three sections cover the results, the ablations (an unaligned proxy is worse than none) and the training cost.
What a soft label carries that a hard label does not
Hinton, Vinyals and Dean framed distillation around soft targets in 2015. A trained model's output distribution puts small probabilities on wrong answers, and the relative sizes of those small probabilities say which wrong answers are close to right. A student trained to match the distribution gets that ranking from every example; their paper says soft targets "provide much more information per training case than hard targets."1
Take one next-token step for the prompt "The capital of France is". Suppose the teacher puts 0.80 on Paris, 0.05 on Lyon, 0.035 on Lille, 0.025 on Nice, 0.018 on London and 0.012 on Berlin, with the remaining 0.06 on filler tokens such as the and in (illustrative numbers, the same ones Figure 1 uses). The hard label is the one token the teacher emitted, Paris. The soft label is the whole vector, and it ranks the near-misses: other French cities above other capitals.
Now compare two students that both put 0.80 on Paris. Student A copies the teacher's probabilities for the other tokens. Student B swaps two of them, giving Berlin 0.05 and Lyon 0.012. Trained on the hard label, both have the same loss, nats, because that loss depends only on the probability of Paris. The soft-label loss below is 0 for A and 0.054 nats for B, and its gradient moves B's probability from Berlin back to Lyon.
Figure 1 puts that distribution under a softmax temperature , which divides the logits before the softmax. Proxy-KD itself uses no temperature; the slider shows how much of the distribution a single sampled token leaves out. At the low end the curve collapses onto Paris and the entropy readout drops toward zero, which is all a hard label holds.
For a whole answer to a prompt , the soft-label objective is a Kullback-Leibler (KL) divergence between the teacher's distribution and the student's , compared position by position along the answer and averaged over the dataset :
At a single position, with ranging over the vocabulary, the divergence is
with the teacher's distribution as and the student's as . Putting the teacher in the first slot is the forward direction. Every token the teacher gives probability contributes a term, and the term grows as the student's probability for that token shrinks, so a student trained on forward KL spreads its probability over all the tokens the teacher considers plausible. That "mode-covering" description is standard machine-learning usage; the paper does not use the term. The reverse direction, with the student in the first slot, is what two of the baselines in the results (MiniLLM and GKD) use.
Why a black-box teacher gives only hard labels
Equation (2) needs at every position, and the API returns a string. What remains is to treat the teacher's text as the target and maximize its likelihood under the student, the negative log-likelihood (NLL) objective of ordinary supervised fine-tuning:
Equation (1) is equation (2) with the teacher's distribution replaced by a one-hot vector on the token it emitted. If puts probability 1 on token , the sum in the KL has one nonzero term, , which is . Black-box distillation is therefore soft-label distillation with all of the teacher's uncertainty set to zero. Alpaca, Vicuna and Orca, which the paper cites as distilling proprietary models into small open ones, are trained this way.
The paper also cites a second problem. Cho and Hariharan (2019) found that a more accurate teacher does not always produce a better student: when the teacher is much larger than the student, distillation can get worse, and GPT-4 to a 7B model is a large gap. TAKD (Mirzadeh et al., 2020) addressed the gap by inserting an intermediate "teacher assistant", in white-box image classification, with no step that makes the assistant match the teacher. The results section shows what that omission costs when the assistant is a raw Llama-2-70B.
How Proxy-KD works: an open proxy between teacher and student
Proxy-KD inserts an open model, the proxy , which addresses both problems. Its distribution can be computed, so equation (2) can be evaluated with the proxy in place of the teacher, and it lies between teacher and student in capability, which the paper says also narrows the capacity gap.
The proxy is larger than the student. In the main runs the teacher is GPT-4, the proxy is Llama-2-70B and the student is Llama-2-7B; a second set of runs uses a Llama-1-7B student. The proxy has to imitate GPT-4 closely enough that its distributions are worth copying, and capacity limits how closely it can: in the paper a 70B proxy aligns better with GPT-4 than a 13B proxy and gives a better student.
Training uses 1M GPT-4 replies: the GPT-4 responses in OpenOrca and Nectar, plus synthetic GPT-4 data built on existing benchmark training sets (the paper gives no breakdown by source). The set is cut into three slices: 10% (100K examples) to warm up the proxy, 45% (450K) to align the proxy, and 45% (450K) to distill into the student. Every model is trained with LoRA adapters (frozen weights in bf16, adapter weights in fp32) for one epoch, with Adam at a constant learning rate of 1e-5, sequences up to 1,024 tokens, on 8 A100 80GB GPUs. Click through the three stages in Figure 2: the first two change only the proxy, and the student trains only in the third.
Pull the proxy onto the teacher: copy its text (NLL) and prefer the teacher’s replies over the proxy’s own (DPO).
Aligning the proxy: fine-tuning, then iterative DPO
The proxy is first fine-tuned on the 100K warm-up slice . On the 450K alignment slice it keeps fine-tuning on GPT-4's replies, the NLL of equation (1) applied to the proxy:
NLL raises the probability of GPT-4's tokens but places no direct penalty on the replies the proxy itself tends to produce. The paper adds a preference term on the stated hypothesis that GPT-4's replies are better than the unaligned proxy's. For each prompt , GPT-4's reply from the dataset is the chosen reply and a fresh sample from the current proxy is the rejected one. Direct Preference Optimization (DPO) turns " is preferred to " into a single differentiable loss, with no reward model and no reinforcement-learning loop. For alignment round :
Each log ratio compares the current proxy with a frozen reference: how many nats more (or less) likely the current proxy makes a reply than the reference did. Call them and . The bracket is the margin , and , the logistic sigmoid, is the probability DPO's preference model assigns to beating . The loss is large when is negative and falls toward zero as grows, so minimizing it raises the probability of GPT-4's reply and lowers that of the proxy's own, both relative to the reference. scales the log ratios; the paper does not report the value it used.
A worked step: suppose that partway through a round the current proxy assigns GPT-4's reply 2.0 nats more log-probability than the reference does, and its own sample 1.0 nat less. With (the DPO paper's default, used here only for illustration), , , and the loss is . Its derivative with respect to is , negative, so a gradient step increases .
The paper prints equation (4) without the leading minus, as . Its derivative with respect to is , positive everywhere, so gradient descent on it lowers the margin, and keeps falling as : the printed loss is minimized by making the proxy prefer its own reply over GPT-4's by an ever larger margin. The paper's own text states the opposite aim, "to train the proxy model to prefer over ", and standard DPO has the minus, so this page writes it with the minus. In Figure 3, switch between the two losses and press run descent: from , the standard loss moves the margin right and slows as shrinks, while the printed one runs it to the left edge.
Two details make this iterative DPO rather than the one-shot version in the DPO paper, which keeps one fixed reference model and trains on a fixed dataset of pairs. Here the reference is the proxy as the previous round left it, re-anchored each round, and is sampled from the current proxy during training:
That online sampling is the largest training cost in the method (the last section has the hours). Each round minimizes the sum of the copying loss and the preference loss, for rounds:
The paper checks alignment by top-1 token agreement: at each position of a GPT-4 reply, does the proxy's most probable next token equal the token GPT-4 wrote? Agreement rises after alignment and stays below a perfect match. The paper reports it only as a chart, so Figure 4 is a schematic of that behavior on one position. Drag the round slider: the proxy's probability moves from its own preferred token (rejected) to GPT-4's (chosen), and the overlap stops short of 100%.
One round of alignment, as code:
# proxy alignment on D_p: one of k = 16 rounds
# lp(m, y, x) = sum of log-probs of tokens y under model m, given prompt x
ref = frozen_copy(proxy) # pi_p^(i-1): the proxy after the last round
for x, y in D_p: # y = GPT-4's reply, the "chosen" one
y_hat = proxy.sample(x) # the proxy's own reply, the "rejected" one
nll = -lp(proxy, y, x) # Eq 3: raise the likelihood of GPT-4's text
r_y = lp(proxy, y, x) - lp(ref, y, x) # log-ratio on y
r_hat = lp(proxy, y_hat, x) - lp(ref, y_hat, x) # log-ratio on y_hat
pref = -log_sigmoid(beta * (r_y - r_hat)) # Eq 4, with the minus
(nll + pref).backward(); opt.step() # Eq 6
# beta is not reported in the paperAfter the 16 rounds the aligned 70B proxy scores 49.12 on AGIEval, 87.67 on ARC, 66.04 on BBH, 82.18 on CSQA, 78.24 on GSM8K and 68.62 on MMLU. GPT-4's scores in the same table are 56.40, 93.26, 88.0, not reported, 92.0 and 86.4. On BBH the proxy sits between GPT-4 (88.0) and the best 7B student (53.40), and unlike GPT-4 its distributions can be read.
Distilling the aligned proxy into the student
The student trains on the 450K distillation slice with two terms. The first is the hard label: NLL on GPT-4's reply, unchanged from black-box distillation.
The second is equation (2) with the frozen proxy in the teacher's slot. Prompt and GPT-4 reply are fed to both models, and at each position of the reply the proxy's next-token distribution is compared with the student's:
It uses the same forward direction, with the proxy first. The proxy's distributions are computed once, offline, and only the top 10 token indices and logits are kept at each position, because most of the probability mass is on a few tokens. To give the saving a size (with an assumed 300-token average reply, Llama-2's 32,000-token vocabulary and 2 bytes per value): full distributions for 450K replies would take 450,000 × 300 × 32,000 × 2 bytes, about 8.6 TB, while ten (index, logit) pairs per position at 6 bytes each take about 8.1 GB. The paper does not say how the probability outside the top 10 is handled when the KL is computed.
Weighting each example by how well the proxy predicts GPT-4
Alignment leaves a gap between proxy and teacher, and the gap varies by example: on some prompts the proxy would readily have written GPT-4's reply, on others it would not. Copying the proxy's distribution equally on every example teaches the student the proxy's errors where they are largest. The paper measures reliability per example with a number already available: , the proxy's log-likelihood of GPT-4's reply . High values mean the proxy agrees with GPT-4 on this example. The value is standardized over the distillation set (subtract the mean , divide by the standard deviation , which gives a z-score ) and passed through a sigmoid:
The division is by , the standard deviation; appears only to define it. A worked batch, with illustrative statistics and nats (the ones Figure 5 uses): a reply the proxy scores at has and weight ; a reply at has and weight exactly 0.5; a reply at has and weight . The third reply's KL term counts about one sixth as much as the first's. No weight reaches 0 or 1. The 0.5 belongs to the average-likelihood example; the mean weight over the dataset need not be 0.5.
Drag the marker in Figure 5 to read the weight at any z-score; the faint hump shows where most examples fall if the log-likelihoods are roughly normal.
is a sum of per-token log-probabilities over the whole reply, so a longer reply tends to score lower. The paper does not say whether it normalizes by length; if it does not, long replies get smaller weights partly for their length. The weight multiplies only the KL term:
The NLL on GPT-4's text stays unweighted, since GPT-4's reply is the target whether or not the proxy agrees with it. The full student objective adds the two with a coefficient :
The paper sets and gives no reason for the value. The weighting scheme is a heuristic: the paper motivates it by the proxy-teacher discrepancies that remain after alignment and derives it from no bound. The ablations show it raises the average and lowers one benchmark. One student step, as code:
# student distillation on D_s (proxy frozen; top-10 logits cached offline)
# mu, gamma: mean and std of lp(proxy, y, x) over all of D_s, computed once
x, y = next(D_s) # y = GPT-4's reply, used as the hard label
nll = -lp(student, y, x) # Eq 7: fine-tune on GPT-4's text
p = proxy_topk_probs(x, y) # [len(y), 10]: proxy's dists along y
q = student_probs(x, y) # [len(y), vocab]: student's, same positions
kl = sum_over_positions(KL(p || q)) # Eq 8: forward KL, proxy in the first slot
z = (lp(proxy, y, x) - mu) / gamma # how well the proxy predicts GPT-4's reply
w = sigmoid(z) # Eq 9: weight in (0, 1), no gradient
loss = nll + 100 * w * kl # Eqs 10-11, alpha = 100
loss.backward(); opt.step() # only the student's LoRA weights updateResults: Proxy-KD against white-box and black-box distillation
The baselines come from the two families Proxy-KD combines. White-box KD has full distributions, but from an open teacher, here Llama-2-70B-Chat. Black-box KD has GPT-4, but only its text. The authors re-implemented both, starting from the same student checkpoint with the same prompts, and evaluated on six benchmarks: AGIEval, ARC, BBH (BIG-Bench Hard), CSQA (CommonsenseQA), GSM8K (grade-school math) and MMLU.
With the Llama-2-7B student, Proxy-KD averages 56.78. The best baseline is MiniLLM at 53.87, then forward KL from the aligned proxy at 53.84, vanilla black-box KD (fine-tuning on GPT-4 text) at 53.66, GKD at 52.95, TAKD at 52.82 and forward KL from Llama-2-70B-Chat at 51.27. The largest single-benchmark lead is on GSM8K, 53.07 against 49.51 for black-box KD; on BBH, 53.40 is only 0.29 above MiniLLM's 53.11. Figure 6 has every cell of that part of Table 1. The zoomed axis starts at 20 so that 1 to 3 point gaps are visible; switch to the full axis to see them at true scale.
Proxy-KD · Proxy-KD (aligned 70B proxy + weighted KL): 56.78
Three comparisons in that figure isolate parts of the method. Forward KL from the aligned proxy (53.84) uses the proxy's distributions on the proxy's own generated text with no GPT-4 text; Proxy-KD beats it by 2.94, so GPT-4's hard labels add something the aligned proxy alone does not. Proxy-KD beats black-box KD by 3.12 on the same data, and the only input it adds is the proxy's distributions. And with the Llama-1-7B student the average goes from 49.11 (black-box KD) to 52.09, though MMLU drops from 45.21 to 41.88.
Proxy-KD does not lead everywhere. On MMLU (Llama-2-7B student) it scores 51.35, 0.07 behind forward KL from Llama-2-70B-Chat; on CSQA TAKD's 76.04 beats its 75.18. GPT-4 scores 88.0 on BBH against the student's 53.40, so the student remains far from the teacher. Among methods using the same student and the same GPT-4 data, routing the data through an aligned proxy scores highest on average; the table does not make it the best 7B model. Orca-2's Llama-2-7B, trained on its own GPT-4 data and reported from its paper, is higher on AGIEval (45.10), ARC (78.41) and MMLU (53.70).
Which parts matter: the ablations
Table 2 removes one component at a time from the Llama-2-7B student with the 70B proxy. Removing the proxy leaves NLL on GPT-4's text alone, which is vanilla black-box KD (the six scores are identical): BBH falls 6.72, ARC 4.24 and GSM8K 3.56.
Keeping the proxy but skipping its alignment, so the student copies the distributions of a raw Llama-2-70B, does worse. BBH falls 10.40, more than the 6.72 from removing the proxy entirely, GSM8K falls 5.53 and MMLU 3.26, while CSQA rises 0.86. The student is fit to GPT-4's text and, in the same loss, to a model's distributions that were never trained to agree with that text. These six scores are also the TAKD row of Table 1, so TAKD's 52.82 and this ablation are one result reported twice. Select a benchmark in Figure 7 to see each component's effect.
−align · The 70B proxy is used raw, never aligned to the teacher. On BBH it scores below using no proxy. These are the same six numbers as the TAKD row in Table 1.
Dropping the DPO term, so the proxy is aligned by NLL alone, lowers the student on five of six benchmarks (ARC −4.98, MMLU −2.56, AGIEval −1.21, BBH −0.89, GSM8K −0.58) and raises CSQA by 0.33. It also leaves the proxy itself less aligned: BBH −3.88, MMLU −2.24, CSQA −1.23, AGIEval −0.81, ARC −0.74, with GSM8K up 0.91. Replacing the weighted KL with the plain KL of equation (8) lowers AGIEval by 2.60, BBH by 1.90 and MMLU by 1.88, raises ARC by 0.72, and brings the six-benchmark mean from 56.78 to 55.80.
Training cost and limitations
The paper reports training time per round of 40K samples (Table 3). Preference optimization on the 70B proxy takes 28.0 hours on 8 GPUs, against 5.5 hours for plain fine-tuning of the same model on 8 GPUs and 2.0 hours on 4 GPUs for a round of student distillation. In GPU-hours that is 224 for a preference round against 8 for a distillation round, a factor of 28; the 13B proxy's preference rounds take 9.0 hours. The overhead comes from sampling from the proxy online. For comparison, the on-policy GKD baseline takes 10.0 hours per round on 8 GPUs for the 7B student. The paper gives no end-to-end total.
All experiments use Llama-family models. The paper lists the omission of other backbones such as Qwen and Mistral as a limitation, "due to resource constraints". No code was released.
Questions you might still have
Why not fine-tune the student on GPT-4 text and skip the proxy?
That is vanilla black-box KD, and it is the "w/o proxy" ablation. With the same Llama-2-7B student and the same GPT-4 data it averages 53.66 against Proxy-KD's 56.78, and it is 6.72 points lower on BBH and 3.56 lower on GSM8K. Proxy-KD adds the proxy's token distributions on that same text, which a black-box teacher does not return.
If GPT-4 is the teacher, why is the proxy bigger than the student?
The proxy has to imitate GPT-4 closely enough that its distributions are worth copying. In the paper a Llama-2-70B proxy aligns better than a Llama-2-13B one and gives a better student. The aligned 70B proxy scores 66.04 on BBH, between the 7B student (53.40) and GPT-4 (88.0).
How is this different from TAKD?
TAKD also puts a model between teacher and student, but in white-box image classification and with no step that aligns that model to the teacher. Used that way, a raw Llama-2-70B in the middle gives a 52.82 average, below the 53.66 of using no middle model at all. Proxy-KD adds the fine-tuning and DPO alignment, which brings the average to 56.78.
Why forward KL, when MiniLLM and GKD use reverse KL?
The paper does not argue for the direction; it writes the standard forward KL with the proxy in the first slot. Forward KL charges the student for any token the proxy finds plausible and the student does not, so the student spreads probability over all of them. MiniLLM and GKD, which use reverse KL with a Llama-2-70B-Chat teacher, average 53.87 and 52.95 in the same table.
Does the per-example weight penalize long replies?
Possibly. The weight is a sigmoid of the proxy's log-likelihood of the whole teacher reply, and a sum of per-token log-probabilities gets more negative as the reply gets longer. The paper does not say whether it normalizes by length, so this cannot be settled from the text.
Are the gaps larger than run-to-run noise?
The paper reports one score per cell, with no seeds, repeated runs or error bars. Gaps of a few tenths, such as BBH 53.40 against MiniLLM's 53.11 or MMLU 51.35 against 51.42, cannot be told apart from noise on that basis. The larger ones, 3.12 points on the average over black-box KD and 3.56 on GSM8K, are less likely to be noise but are also single runs.
How expensive is Proxy-KD to train?
The preference rounds on the 70B proxy dominate: 28.0 hours per 40K samples on 8 A100s, against 5.5 hours for plain fine-tuning of the same proxy and 2.0 hours on 4 GPUs for a round of student distillation. The paper reports per-round times only, not a total.
Can I reproduce it?
No code was released. The paper gives the main settings: GPT-4 replies from OpenOrca and Nectar plus synthetic data, a 100K/450K/450K split, k = 16 DPO rounds, alpha = 100, constant learning rate 1e-5 with Adam, sequence length 1024, one epoch, LoRA on every model, and top-10 proxy logits cached offline. It does not give the DPO beta or how the ten logits are turned into a distribution.
Footnotes & further reading
- The phrase "dark knowledge" for this transferable structure comes from Hinton's later talks, not the 2015 paper, which says only that soft targets carry "much more information per training case than hard targets." The paper: Hinton, Vinyals, Dean, Distilling the Knowledge in a Neural Network; this site's explainer of it. ↩
- The paper: Chen, Chen, Yi, Quan, Li, Yan, Zhang, Knowledge Distillation of Black-Box Large Language Models (Sun Yat-sen University & Alibaba; arXiv v1 January 2024, v2 November 2024).
- The alignment loss is Direct Preference Optimization (Rafailov et al., arXiv:2305.18290), here run iteratively with the reference re-anchored to the previous round's proxy.
- The capacity-gap effect is from Cho & Hariharan, On the Efficacy of Knowledge Distillation (ICCV 2019), and the teacher-assistant idea from Mirzadeh et al., Improved Knowledge Distillation via Teacher Assistant (TAKD, AAAI 2020).
- Reverse-KL distillation baselines: MiniLLM (Gu et al., arXiv:2306.08543) and GKD (Agarwal et al., arXiv:2306.13649). Every model in the paper's experiments is trained with LoRA.
How could this explainer be improved? Found an error, or something unclear? I read every message.