Keep the Function, Rotate the Geometry: Teacher-Anchored Defense Against Extract-then-Transfer Attacks

A model served through a public API can be attacked in two cheap steps. First, the attacker queries it and trains a local copy on its answers, which is called model extraction. Then the attacker computes adversarial examples, tiny input changes that flip predictions, on that local copy and sends them back to the API, where they usually still work. This second property is called adversarial transferability. Model Extraction and Adversarial Transferability, Your BERT is Vulnerable! showed that BERT classification APIs can be copied for as little as $7.10, reaching 90–99% of the victim's accuracy, and that the copy then serves as a working attack tool against the victim. The standard fix is adversarial training: retrain the model on its own worst-case perturbed inputs. That requires an inner optimization loop at every training step and is too expensive for large served models.

This note proposes a defense that does not try to stop the copying. It tries to make the copy useless as an attack tool. We briefly fine-tune the served model with a small low-rank adapter so that its outputs stay anchored to the original frozen model, the "teacher," while the directions in which its loss is most sensitive to input changes are rotated away from the directions a distilled copy would inherit. An honest user sees the same predictions and confidences. An attacker who distills those predictions gets a surrogate whose gradients point the wrong way, so attacks crafted on it no longer transfer. The procedure uses no inner attack loop. Its cost is one extra backward pass through the input, not ten or more attack steps.

Core Claim

A distilled surrogate learns the teacher's function from its outputs. Uncovering the Connections Between Adversarial Transferability and Knowledge Transferability proves that matching functions and matching input gradients go together with adversarial transferability, at least for small perturbations. The surrogate therefore inherits something close to the teacher's gradient field, meaning the direction, at each input, in which the loss rises fastest. Outputs and gradients are not the same object, though. A model can reproduce the teacher's outputs at natural inputs while having different input gradients there.

A first-order expansion makes the target precise. Let $g_D(x)$ be the deployed model's input gradient of its loss at $x$, let $g_S(x)$ be the surrogate's, and let the attacker step $\delta = \epsilon\, g_S/\|g_S\|$. The deployed model's loss then rises by about $\epsilon\,\|g_D(x)\|\cos(g_D, g_S)$. Transfer is suppressed by driving the cosine toward zero without letting the gradient norm grow.

The norm condition is not optional. Reducing Adversarial Example Transferability Using Gradient Regularization found that attacks transfer more easily from low-gradient models to high-gradient ones ($R^2 = 0.93$ for the quadratic fit). That result rules out a design that rotates gradients by inflating them.

The claim we will test is this: on CIFAR-10 and BERT text APIs, a parameter-efficient, teacher-anchored rotation of this kind cuts the success rate of extract-then-transfer attacks substantially. It should keep the deployed model's outputs within a small divergence of the teacher's and cost a small fraction of adversarial training.

Research Program

The method is a teacher-anchored fine-tuning problem in the sense used in machine unlearning. That literature tethers an edited model to a frozen reference so that removing one thing does not destroy everything else. Don't Shift the Trigger: Robust Gradient Ascent for Backdoor Unlearning combines a KL anchor with an $L_2$ weight anchor to stop unlearning from collapsing the model or merely moving a backdoor to another class. Go Beyond Your Means: Unlearning with Per-Sample Gradient Orthogonalization confines updates to a low-rank adapter (LoRA, a small trainable add-on to frozen weights) and to directions orthogonal to what must be preserved. We reuse both ideas, but the thing we "unlearn" is the teacher's local geometry rather than any data. With adapter parameters $\phi$, the objective is

$$ \min_\phi\; \mathbb{E}_{x\sim Q}\,\mathrm{KL}\big(f_T(x)\,\|\,f_\phi(x)\big) \;+\; \lambda\,\mathbb{E}_{x\sim D}\,\cos^2\!\big(g_\phi(x),\, \hat g(x)\big) \;+\; \mu\,\mathbb{E}_{x\sim D}\Big[\big(\tfrac{\|g_\phi(x)\|}{\|g_T(x)\|}-1\big)_+\Big]^2 . $$

The symbols are as follows. $f_T$ is the frozen teacher's output distribution and $f_\phi$ is the deployed model's. $Q$ mixes in-domain inputs with the kind of generic public data an attacker would query, following Knockoff Nets: Stealing Functionality of Black-Box Models. $D$ is the defender's training data. $g_\phi$ and $g_T$ are the input gradients of the deployed and teacher models. $\hat g$ is the defender's estimate of the gradient a future surrogate would inherit. The weights $\lambda$ and $\mu$ trade off rotation against norm control.

The KL anchor is applied only at clean points, never at perturbed neighbors. That is what leaves room for the gradients to differ.

The central open design question is how to estimate $\hat g$. The cheapest choice is the teacher's own gradient, $\hat g = g_T$. This is justified if distillation copies the teacher's geometry faithfully, which the equivalence result suggests. The more expensive choice is the gradient of a small panel of proxy students that the defender distills from the teacher once, on attacker-like queries, across several architectures. This captures what is actually learnable from outputs, including each architecture's own biases. We treat the teacher-gradient variant as the default. We adopt proxies only if they clearly beat it on surrogates whose architecture was held out from the panel.

Cost accounting is part of the contribution. Each step needs one forward pass, one backward pass to the input, and one double backward pass for the cosine term, all through a frozen backbone with a small adapter. We will report training passes and wall-clock time against PGD adversarial training, which typically runs about ten attack steps per update.

Baselines

The naive reference is the undefended API, attacked by the full pipeline of He et al.: extraction from posterior outputs, then white-box attacks on the surrogate transferred back to the victim. For this pipeline, no reported transfer-success number was found on Lacuna. The file reports only 90–99% extraction fidelity for this pipeline, so we will re-measure the undefended success rate on Yelp and AG News, and on CIFAR-10 with a ResNet victim. All defenses are measured against that figure.

The strongest existing competitor on the extraction side is QUEEN: Query Unlearning against Model Extraction. QUEEN detects sensitive query streams and returns outputs that make the attacker's student unlearn the task. On CIFAR-10 it reports extracted-student accuracy falling from 87.42% to 10.00%, with victim accuracy falling from 92.74% to 90.01%. It is the strongest competitor because a surrogate at chance accuracy should also be a poor attack tool. We will run it with its released thresholds and the same query budget and data, then measure both student accuracy and transfer success. QUEEN perturbs outputs, so we also measure its divergence from the teacher. We beat it if we reach comparable transfer suppression at lower output divergence and without shadow models. We would also count it as a win if QUEEN's surrogates, after the attacker applies temperature rescaling, recover transfer power that ours do not.

How to Steer Your Adversary: Targeted and Efficient Model Stealing Defenses with Gradient Redirection (GRAD²) is the second active output-perturbation baseline. It reports a 3.75–6.33× speedup over the earlier MAD defense but no transfer numbers in the file. We run it on CIFAR-10 under the same protocol.

On the robustness side, the strongest cheap baseline is Robustness Tokens: Towards Adversarial Robustness of Transformers. It trains about ten tokens appended to the input of a frozen Vision Transformer, uses a teacher-anchored invariance loss, and converges in 200 steps. It reports recovering DINOv2-G white-box accuracy on ImageNet-1k from 0.3% to 63.1%, with clean accuracy at 85.2% against 85.6%. We will also run single-step and PGD adversarial training at a matched adapter size. Every method gets the same adapter capacity, data, and tuning trials. We compare them at matched GPU-hours and also at their own converged settings.

Two ablations isolate the key ingredient. The first drops the norm term ($\mu = 0$), which tests whether the asymmetry result bites. The second replaces the targeted cosine term with a random-direction gradient penalty of equal strength. This tests whether targeting the inherited direction matters, or whether any gradient perturbation does.

Why not just…?

Why not just add noise to, round, or soften the outputs? He et al. report that these defenses stopped extraction only when the noise was strong enough to ruin the API for honest users. Towards Undistillable Models by Minimizing Conditional Mutual Information reports that noise-based defenses are bypassed when the attacker retunes the distillation temperature. More fundamentally, output noise leaves the victim's own gradient field untouched. A surrogate that recovers the clean function through averaging regains its transfer power. We include output noise tuned to our divergence level as a baseline to show this directly.

Why not just return hard labels? Knockoff Nets shows that decision boundaries can be reconstructed from degraded outputs. Hard labels also deny calibrated confidences to legitimate users, as the GRAD² paper notes. Our method is orthogonal to label format, so we also evaluate a hard-label attacker. If transfer collapses under hard labels alone, the defense's marginal value shrinks to the soft-output setting, and we will say so.

Why not just make the model undistillable, or stop extraction outright? CMIM (Towards Undistillable Models) requires full retraining, and its guarantee is relative to a label-smoothing student. A student that merely ties a label-smoothed one is still a decent surrogate for attacks. QUEEN's protection depends on detecting the query stream. Both are real competitors. Our proposal differs in accepting that functionality may be stolen, which could be handled separately by watermarking, and denying the attack-tool payoff instead. The experiments settle the comparison by measuring transfer success, not student accuracy.

Why not just run cheap adversarial training, such as single-step attacks or robustness tokens? This is the most serious threat, because a genuinely robust model resists transferred attacks too. The comparison is at matched compute and matched clean accuracy. Our method costs fewer passes per step, while adversarial training has the familiar clean-accuracy cost. If cheap adversarial training matches our transfer suppression at equal cost, the gradient-rotation idea adds nothing and the honest conclusion is to use it. Our method buys only transfer resistance, not white-box robustness.

Why not just use the joint gradient regularizer of Reducing Transferability? That method co-trains both models from scratch and was shown on MNIST and FashionMNIST, reducing iterative-attack transfer by about 56%. A defender never controls the attacker's surrogate. Our teacher-gradient and proxy-student variants are precisely the attempt to make that idea work from the victim's side alone.

Proposed Experiments

The test settings are a ResNet victim on CIFAR-10 and BERT victims on Yelp and AG News, following He et al. Attackers extract with in-domain and generic out-of-domain queries across three surrogate architectures, at least one of them excluded from any proxy panel. They then run iterative-gradient and Carlini–Wagner attacks on the surrogates, and word-substitution attacks for text.

The metrics are transfer attack success rate and the directional transfer measure $\alpha_2$ from the transferability-equivalence paper. Utility is measured by clean accuracy and KL divergence from the teacher on held-out data. Cost is measured in training passes and GPU-hours. We also track the surrogate's accuracy, which we do not expect to fall.

The decisive checks are as follows. First, transfer success must fall substantially while teacher KL stays near the level of seed-to-seed variation. Second, suppression must hold for held-out surrogate architectures, which tests whether a teacher-gradient estimate generalizes. Third, the suppression must survive a sweep of perturbation size $\epsilon$. The first-order argument predicts degradation at large $\epsilon$, and we will report where it fails.

Fourth, the defense must withstand adaptive attackers. These include an attacker who queries noisy neighbors of natural inputs to learn the rotated local geometry directly, ensemble surrogates, and attacks averaged over random input transformations. We also report query-based refinement attacks as an explicit boundary of the threat model.

The neighbor-querying attack is the one most likely to break the method, because it lets the attacker measure local geometry rather than infer it. Its query cost is therefore a headline result.