Inferensys

Glossary

TRADES Loss

A loss function that trades off natural accuracy against adversarial robustness by minimizing the Kullback-Leibler divergence between clean and adversarial output distributions.
AI evaluator reviewing output quality on laptop, comparison metrics visible, casual evaluation session.
ADVERSARIAL ROBUSTNESS

What is TRADES Loss?

A formal definition of the TRADES loss function, which optimizes the trade-off between standard accuracy and adversarial robustness in deep learning models.

TRADES Loss (TRadeoff-inspired Adversarial DEfense via Surrogate-loss minimization) is a loss function that balances natural accuracy against adversarial robustness by minimizing the Kullback-Leibler (KL) divergence between a model's output distribution on a clean input and its output distribution on an adversarially perturbed version of that same input. Unlike standard adversarial training, which directly minimizes the cross-entropy loss on adversarial examples, TRADES decomposes the objective into a natural error term and a boundary error term, providing a principled mechanism to control the trade-off between classifying clean data correctly and maintaining stable predictions near the decision boundary.

The formulation introduces a regularization hyperparameter, λ, that explicitly governs the trade-off: the natural error term optimizes for standard accuracy, while the boundary error term penalizes the model when its probabilistic output diverges under perturbation. This approach is theoretically grounded in a decomposition of a model's robust error, proving that the gap between natural and robust error is bounded by the expected KL divergence between clean and adversarial output distributions. TRADES has become a foundational baseline in the RobustBench leaderboard, often outperforming standard Projected Gradient Descent (PGD) adversarial training in achieving higher robust accuracy without sacrificing excessive clean accuracy.

ADVERSARIAL ROBUSTNESS

Key Characteristics of TRADES Loss

TRADES (TRadeoff-inspired Adversarial DEfense via Surrogate-loss minimization) is a loss function that formalizes the trade-off between natural accuracy and adversarial robustness by minimizing the Kullback-Leibler divergence between clean and adversarial output distributions.

01

The Accuracy-Robustness Trade-off

TRADES directly addresses the fundamental tension between natural accuracy (performance on clean data) and adversarial robustness (resistance to perturbations). The loss function is formulated as:

L_TRADES = L_CE(f(x), y) + β * KL(f(x) || f(x'))

  • The first term is standard cross-entropy loss for clean accuracy
  • The second term is the Kullback-Leibler divergence between the clean output distribution and the adversarial output distribution
  • The hyperparameter β controls the trade-off: higher β prioritizes robustness over accuracy
02

KL Divergence Regularization

Unlike adversarial training which uses the label of the adversarial example directly, TRADES uses the model's own prediction on the clean input as the soft target for the adversarial example. This encourages output stability:

  • The model learns to produce similar probability distributions for clean and perturbed inputs
  • This prevents the model from becoming overconfident on adversarial examples
  • The KL divergence term acts as a local smoothness regularizer around each data point
  • Results in smoother decision boundaries that are harder to exploit
03

Adversarial Example Generation

TRADES generates adversarial examples using Projected Gradient Descent (PGD) to maximize the KL divergence between clean and perturbed outputs:

  • The perturbation is constrained within an Lp-norm ball (typically L∞ with radius ε)
  • Uses multi-step PGD with random initialization for stronger attacks
  • The inner maximization finds the perturbation that causes the largest output distribution shift
  • This is more aligned with robustness goals than maximizing classification error alone
04

Theoretical Foundation

TRADES provides a principled upper bound on the robust error of a classifier. The theoretical decomposition shows:

  • Robust error ≤ Natural error + Boundary error
  • Natural error is the error on clean samples
  • Boundary error measures how often the model's prediction changes within the perturbation neighborhood
  • TRADES minimizes both terms simultaneously
  • This formalization explains why robustness and accuracy can conflict and provides a framework for managing the trade-off
05

Comparison to Standard Adversarial Training

Standard adversarial training (Madry et al.) uses one-hot labels for adversarial examples, while TRADES uses the model's own soft predictions on clean data:

  • Standard AT: L_CE(f(x'), y) — forces correct classification of perturbed inputs
  • TRADES: L_CE(f(x), y) + β * KL(f(x) || f(x')) — forces output consistency
  • TRADES often achieves higher clean accuracy at equivalent robustness levels
  • Particularly effective when β is tuned appropriately for the dataset and threat model
  • Widely adopted as a strong baseline in adversarial robustness research
06

Practical Implementation Considerations

Key implementation details for effective TRADES training:

  • β selection: Typically ranges from 1.0 to 6.0; higher values for stronger robustness requirements
  • PGD steps: 10-step PGD is standard during training; more steps increase computational cost
  • Step size: Usually set to ε/4 for L∞ perturbations with radius ε = 8/255
  • Training time: Approximately 2-3x slower than standard training due to adversarial example generation
  • Evaluation: Use AutoAttack for reliable robustness assessment rather than PGD alone
  • Available in libraries like Adversarial Robustness Toolbox (ART) and RobustBench
ROBUSTNESS METHODOLOGY COMPARISON

TRADES Loss vs. Standard Adversarial Training

A feature-level comparison between the TRADES loss function and standard adversarial training for optimizing the trade-off between natural accuracy and adversarial robustness.

FeatureTRADES LossStandard Adversarial Training

Core objective

Minimize natural error + boundary error

Minimize adversarial error directly

Loss function composition

Cross-entropy on clean data + KL divergence regularization

Cross-entropy on adversarial examples only

Clean data utilization

Theoretical grounding

Decomposes robust error into natural and boundary components

Empirical risk minimization on adversarial distribution

Natural accuracy preservation

High (explicitly optimized)

Moderate to Low (often degrades)

Hyperparameter controlling trade-off

1/λ (regularization coefficient)

ε (perturbation radius)

Gradient computation

Requires second backward pass for KL divergence term

Single backward pass on adversarial examples

Sensitivity to perturbation step size

Lower (smoother optimization landscape)

Higher (can overfit to specific ε)

TRADES LOSS CLARIFIED

Frequently Asked Questions

Clear, technical answers to the most common questions about the TRADES loss function and its role in building adversarially robust financial fraud detection models.

The TRADES loss (TRadeoff-inspired Adversarial DEfense via Surrogate-loss) is a training objective that balances a model's accuracy on clean, natural data against its robustness to adversarial perturbations. It works by minimizing a composite loss: the standard cross-entropy loss for natural accuracy plus a regularization term that minimizes the Kullback-Leibler (KL) divergence between the model's output probability distribution on a clean sample and its distribution on an adversarially perturbed version of that same sample. This forces the decision boundary to be smooth, pushing it away from the data manifold and making it difficult for an attacker to find a nearby misclassified input. The trade-off is controlled by a hyperparameter, typically denoted as 1/λ, which weights the importance of robustness relative to natural accuracy.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.