Safety & Alignment advanced 7 min read 10 flashcards

Model Extraction and Weight Stealing

A black-box API leaks more about the model behind it than intended, and with the right queries an attacker can recover architectural secrets or a functional clone for a tiny fraction of the training cost.

For under $20 in API calls, researchers recovered the entire final embedding projection matrix of OpenAI's Ada and Babbage models, along with their exact hidden dimensions of 1024 and 2048. For GPT-3.5-turbo they determined the hidden dimension exactly and estimated the full projection matrix would cost under $2,000 to recover (Carlini et al., 2024, Stealing Part of a Production Language Model, arXiv:2403.06634).

Nothing was breached. The attack used documented API features.

The mechanism, and why it is elegant

A transformer's final layer maps a hidden state of dimension \(h\) to a logit vector of dimension \(|V|\), where \(|V|\) is the vocabulary, typically 50k to 250k. Since \(h \ll |V|\), every logit vector the model can possibly produce lives in an \(h\)-dimensional subspace of \(\mathbb{R}^{|V|}\).

So collect logit vectors for many different prompts, stack them into a matrix, and take the singular value decomposition. The number of non-negligible singular values is \(h\). That one number is usually undisclosed. Push further and the left singular vectors give the projection matrix up to an unknown rotation, which is enough to reconstruct outputs.

The attack does not need raw logits. Any API exposing a logit bias parameter, or returning top-k log-probabilities, lets an attacker reconstruct full logit vectors by querying repeatedly with different biases. Affected providers changed their APIs after disclosure.

The deeper lesson generalises past this one attack: any API that returns real-valued scores rather than discrete choices leaks linear-algebraic structure, at a rate proportional to the precision returned.

Distillation as extraction

The blunter attack is behavioural cloning. Query the target, collect input-output pairs, train a smaller student on them. This is ordinary knowledge distillation with the teacher behind a paywall, and it works well enough that most frontier providers prohibit it explicitly; see distillation and terms-of-service constraints.

The economics make it a genuine business risk. Training the teacher cost eight or nine figures. Cloning a task-specific slice of its behaviour costs the price of the queries. Reasoning models make this worse, because a model that emits its chain of thought supplies not just labels but the intermediate supervision that makes distillation efficient.

Where the boundary sits

Not everything can be stolen. Carlini et al. recovered one layer, not a model. Full weight recovery from black-box access remains far out of reach at frontier scale; the parameter count alone makes the query complexity absurd. What is realistically extractable is:

  • architectural facts (hidden dimension, vocabulary structure, tokeniser behaviour),
  • the final projection up to symmetry,
  • task-specific behaviour, via distillation,
  • membership and memorisation signals, which are separate attacks with their own literature.

When it breaks

Rate limiting is a speed bump, not a defence. The SVD attack needs on the order of the hidden dimension in independent queries. That is thousands, not billions, and it spreads across accounts trivially.

Noise defences trade accuracy for protection. Adding noise to returned logprobs raises the query count an attacker needs, but it degrades the legitimate uses of logprobs (calibration, structured generation, evaluation), and a determined attacker averages the noise away.

Removing logprobs entirely has a real cost. Many providers took this route. It breaks perplexity-based evaluation, constrained decoding implementations that need per-token scores, and selective prediction pipelines that abstain on low confidence.

Watermarking outputs does not prevent distillation, it detects it afterwards, and only if the watermark survives the student's training; see watermarking and content provenance.

The honest summary: an API is an oracle, and every additional bit of information it returns per query is a bit of the model that can, with enough queries, be reconstructed.

Check yourself

10 flashcards for this concept

Click a card to reveal the answer.

Drill the whole track