research28 min studyLesson 937 in Engineering

Train against a declared perturbation problem

Distinguish approximate robust optimization, explicit clean-adversarial mixtures, and distribution-consistency penalties.

On this page

What you’ll understand

  • Compute a clean-adversarial mixture objective and gradient.
  • Explain the inner-attack approximation in robust training.
  • Separate a TRADES-style consistency penalty from a simple loss mixture.

Adversarial training puts difficult feasible inputs inside the learning loop rather than relying only on a test-time filter. Its meaning depends on how those inputs are generated, which examples enter the batch, and what objective updates the model. A weak inner attack can teach the optimizer to exploit that attack’s limitations instead of learning useful local stability. Write the training threat and mixture explicitly, then evaluate the resulting artifact with stronger and different searches on held-out data. Training loss alone cannot show that a model solved the original worst-case problem.

Separate the inner search from the outer update

The robust objective asks the learner to minimize the expected largest loss over the permitted perturbations of each example. The inner search usually produces an approximate adversarial candidate rather than the exact maximum. The outer update then uses the chosen objective and model state. Record attack iterations, step sizes, restarts, initialization, precision, and model mode during generation. A change in batch-normalization or stochastic-layer behavior can change the inner target without changing the model architecture.

The candidate generator should not use test labels for model selection or mix final evaluation examples into training. Preserve train, validation, and final test roles across source data and any synthetic or additional data. A clean-adversarial mixture changes the effective training distribution; simply adding more attacked copies of frequent classes can alter class balance. State whether the coefficient applies per example, per batch, or through sampling frequency, because unequal batch sizes and denominators can make those implementations differ.

min⁡θ  E(x,y)[(1−λ)ℓ(Fθ(x),y)+λmax⁡z∈Sp(x,ε)ℓ(Fθ(z),y)]\min_\theta\;\mathbb E_{(x,y)}\left[(1-\lambda)\ell(F_\theta(x),y)+\lambda\max_{z\in\mathcal S_p(x,\varepsilon)}\ell(F_\theta(z),y)\right]
0≤λ≤1 is this lesson’s declared clean-adversarial mixing weight. The expectation is over a specified training distribution. Practical approximate inner searches generally under-estimate the exact maximum; λ=1 gives the pure robust-loss objective under the same threat.↔ Scroll wide equations horizontally.

Do not conflate different robustness objectives

A mixture of label losses is not the same as penalizing changes in the model’s predictive distribution. A TRADES-style objective combines clean classification loss with a worst-case divergence between clean and perturbed predictions. This encourages local distributional consistency while maintaining a separate term tied to labels. The weight convention varies across descriptions; declare whether a parameter multiplies or divides the penalty before comparing values across implementations.

Neither formulation removes the need to check semantic label validity within the training threat. If an allowed transformation genuinely changes the task label, forcing the old label everywhere can teach the wrong invariance. Also distinguish adversarial training from ordinary random data augmentation. Random transforms sample an augmentation distribution, while an adversarial inner loop searches for difficult candidates under its stated objective. Their compute costs and covered cases can differ even when they apply the same transformation family.

Lconsistency=CE⁡(pθ(x),y)+βmax⁡z∈Sp(x,ε)DKL ⁣(pθ(x) ∥ pθ(z)),β≥0\mathcal L_{\rm consistency}=\operatorname{CE}(p_\theta(x),y)+\beta\max_{z\in\mathcal S_p(x,\varepsilon)}D_{\rm KL}\!\left(p_\theta(x)\,\Vert\,p_\theta(z)\right),\quad\beta\geq0
pθ is a categorical prediction distribution and KL uses natural logarithms, so both terms are dimensionless losses. β is a penalty multiplier in this notation. This is a TRADES-style objective, not the simple λ mixture above or a universal certificate.↔ Scroll wide equations horizontally.

Evaluate the learned artifact independently

Measure clean accuracy, attack-survival accuracy, and relevant subgroup behavior on held-out examples. Use attack variants that differ from the training generator, including stronger iteration and restart budgets when feasible. Training-time candidate generation may be intentionally cheaper than final evaluation, so compare both. If robustness drops sharply under a different loss or derivative treatment, inspect whether the learned model exploited the training attack’s weaknesses instead of establishing broad resistance within the stated set.

Publish the complete training recipe and selected checkpoint policy. Early stopping on clean validation accuracy, robust validation accuracy, or a weighted decision metric can select different artifacts. Record auxiliary data provenance, normalization, randomness, and the final evaluator’s exact threat. Do not generalize a measured benefit under one norm or epsilon to spatial transformations, corruptions, or semantic edits that the experiment never tested. A stronger training recipe changes empirical evidence, while certification remains a separate kind of result.

Combine losses and parameter gradients consistently

For one example, clean loss is 0.2 and approximate adversarial loss is 1.4. Use λ=0.75 in the defined mixture. Their parameter gradients are g_clean=(1,0) and g_adv=(−1,2). Compute the mixed gradient and a gradient-descent update from θ=(1,1) with learning rate 0.1.

  1. The mixed loss is (1−0.75)×0.2+0.75×1.4=0.05+1.05=1.10. This is the chosen approximate training objective for the generated adversarial candidate.

  2. The mixed parameter gradient is 0.25×(1,0)+0.75×(−1,2)=(−0.5,1.5). Its components need not match either individual gradient’s direction.

  3. Apply θ_new=θ−0.1g to obtain (1−0.1×(−0.5),1−0.1×1.5)=(1.05,0.85). This outer parameter update is distinct from the inner input attack.

The result

The mixture coefficient must weight both loss and its corresponding gradient consistently. These toy calculations do not show that the approximate inner candidate attains the true maximum.

Explore the model

Interactive lab

Interactive lab · optimization

An outer learning step has its own update rule

Reset, set Step size η to 0.25 and Initial position x₀ to 2. Predict x₁=1.5 and x₂=1.125 after one and two Steps. Reset, explicitly set η=0.5 and x₀=2, then take two Steps: predict x₂=0.5. This exact descent model optimizes x²/2 and contains no adversarial inner maximization, data mixture, or learned classifier. Changing a control recomputes at retained time; use Reset for each fresh comparison.

An outer learning step has its own update ruleGradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Current readings: Position x0: 2; Objective x²/2: 2; Iteration behavior: Stable step. All parameters are adjustable with the labeled controls below.−4−202402.174.356.528.7Parameter xf(x) = x²/2n = 0
ObjectiveDiscrete iterate
Position x0
2
Objective x²/2
2
Iteration behavior
Stable step
n = 0 · t = 0 s

Gradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forDistinguish the parameter optimizer from the attack that generates its training examples.

Check your understanding

Which expression matches the declared λ=0.75 clean-adversarial mixture?

Try it yourself

A consistency objective has clean cross-entropy 0.3, worst-case estimated KL divergence 0.05, and penalty multiplier β=6 in the displayed convention. Compute its value. Does an estimated KL maximum from a finite attack establish an exact worst-case bound?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Multiply the divergence by β and distinguish an inner-search estimate from a verified upper bound.

Compare with the solution

The objective is 0.3+6×0.05=0.6. A finite attack supplies a candidate divergence and generally a lower bound on the exact maximum, not a certified upper bound. A small estimated penalty therefore does not prove that every feasible perturbed distribution stays close to the clean one.

Take it with you

  • Record the approximate inner attack separately from the outer optimizer.
  • Name mixing and consistency objectives with explicit coefficient conventions.
  • Evaluate the final model under independent, stronger held-out tests.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.