Defensive distillation

On this page 7

Defensive distillation is a training technique that aims to make a neural network classifier resistant to adversarial examples by retraining it on the soft probability outputs of an earlier copy of itself, produced at a high softmax temperature. In AI security, it is one of the best-known early defenses against evasion attacks and, equally, one of the clearest lessons in why gradient masking is not real robustness.

The method was proposed by Nicolas Papernot and colleagues in 2016 and initially reported dramatic reductions in attack success. Within a year, the Carlini–Wagner attack showed that a slightly modified attacker defeats it almost completely, so today it is studied mainly as a historical baseline and a cautionary example.

How defensive distillation trains a model

Defensive distillation trains two networks of the same architecture in sequence, using the softmax temperature to transfer smoothed knowledge from the first to the second. It borrows the mechanics of knowledge distillation but uses them for robustness rather than compression.

  1. Train an initial network on the hard labels with the softmax temperature T set high, often between 20 and 100.
  2. Run the training data through this network at the same temperature to obtain soft labels, probability vectors that encode similarities between classes.
  3. Train a distilled network of identical architecture on those soft labels, again at temperature T.
  4. Deploy the distilled network with the temperature reset to 1 for inference.

The temperature divides the logits before the softmax. Training at a high T and testing at T = 1 forces the network to produce very large logits, which drives the softmax into saturation. The table summarizes the key quantities involved.

ParameterTypical valueRole in the defense
Training temperature T20 to 100Smooths labels and scales logits
Inference temperature1Produces saturated, near one-hot outputs
Soft labelsClass probability vectorsCarry inter-class similarity
ArchitectureSame for both networksKeeps capacity unchanged
Accuracy costUsually smallClean accuracy stays close to baseline
Main parameters of defensive distillation

Why it appeared to work: gradient masking

Defensive distillation appeared to work because it makes the gradients of the softmax output vanishingly small near the training data, not because it moves decision boundaries away from inputs. Gradient-based attacks such as the fast gradient sign method rely on those gradients to find a perturbation direction.

When the softmax saturates, the derivative of the output probability with respect to the input becomes so small that it underflows in 32-bit floating point arithmetic. The attacker receives a zero or useless gradient and concludes that no small perturbation changes the label. This effect is called gradient masking or obfuscated gradients: the model is just as vulnerable, but the attacker’s tool is blinded.

Early evaluations reported that distillation cut the success rate of some attacks on image classifiers from above 90 percent to a few percent. Those figures measured the weakness of the attacks, not the strength of the model.

How attacks defeat defensive distillation

Attacks defeat defensive distillation by working on the logits instead of the softmax probabilities, or by approximating gradients in ways that ignore saturation. Each of the following approaches restores a usable attack signal.

Attack strategyHow it bypasses the defenseResult
Carlini–Wagner attackOptimizes a loss on logitsNear 100% success on distilled models
Logit rescalingDivides logits by T before the softmaxRestores non-zero gradients
Transfer attackCrafts examples on an undefended surrogateHigh success through transferability
Black-box attackUses queries or score estimatesIgnores internal gradients
Projected gradient descent attackIterative steps on a stable lossBreaks the defense when adapted
Attack strategies that bypass defensive distillation

The success of adversarial transferability is especially telling: examples crafted against an ordinary network fool the distilled one at similar rates, which shows that its decision boundaries barely changed.

Defensive distillation compared with robust defenses

Defensive distillation differs from robust defenses because it changes the attacker’s view of the model rather than the model’s actual behavior near each input. Modern evaluations require defenses to hold against adaptive attacks designed with full knowledge of the defense.

DefenseMechanismRobustness status
Defensive distillationSaturated softmax via temperatureBroken by adaptive attacks
Adversarial trainingTrains on worst-case perturbed inputsEmpirically strong, costly to train
Randomized smoothingAverages predictions under noiseProvable radius for L2 norm
Certified robustness methodsBounds outputs mathematicallyGuaranteed within stated bounds
Input preprocessingDenoising or compressionOften broken, similar masking risk
Distillation and neighboring defenses

Knowledge distillation itself remains useful in compressing models and is sometimes combined with adversarial training, for example to transfer robustness from a large robust teacher to a smaller student. In that setting, the robustness comes from adversarial training, not from the temperature trick.

Lessons for evaluating AI defenses

The main legacy of defensive distillation is a methodological standard for security evaluation of machine learning models. Several rules widely accepted in adversarial machine learning trace back to its failure.

  • Test every defense with adaptive attacks built for that specific defense.
  • Treat vanishing or noisy gradients as a warning sign of masking, not as evidence of robustness.
  • Confirm that transfer and black-box attacks succeed less often than white-box attacks; the reverse indicates masking.
  • Report robustness for a clearly stated threat model, including norm and perturbation budget.
  • Prefer defenses with certified guarantees where the application requires assurance.

Threat catalogs such as MITRE ATLAS and guidance such as NIST AI 100-2 describe evasion attacks and stress that defenses must be evaluated against capable adversaries. A security review that accepts defensive distillation as a control would overstate the protection of the system.

In plain words

Defensive distillation tried to protect image recognition models from tiny, sneaky changes to pictures. It retrained the model so its answers became extremely confident. Attack tools that look for weak spots then saw nothing to grab.

It is like painting over the cracks in a wall. The wall looks smooth, but the cracks are still there. Attackers soon found other ways to see them. The key lesson is simple: hiding a weakness is not the same as fixing it.

A real-world example

A company building a traffic sign recognition model for driver assistance evaluates defenses against adversarial stickers. An engineer applies defensive distillation at a temperature of 50, and the team’s fast gradient sign tests drop from 87 percent attack success to 4 percent.

Before approval, an internal red team runs an adaptive evaluation. It crafts adversarial examples on an undefended copy of the model and transfers them, then runs a Carlini–Wagner attack on the distilled model’s logits. The transfer attack succeeds on about 80 percent of test signs, and the logit-based attack on nearly all of them.

The team records the result as gradient masking and replaces the defense with adversarial training under a stated perturbation budget, combined with sensor fusion checks. Robust accuracy is lower than the misleading distillation figure, but it is measured against realistic attackers, which is what the safety case requires.