Evaluate machine learning models against adversarial attacks. Test your models for robustness and get detailed metrics on what perturbations break them.
Input: A trained ML model + dataset
Process: Run adversarial attacks (FGSM, PGD, Bayesian optimization, etc.)
Output: JSON metrics + interactive HTML report showing robustness under attack
Supports classification, regression, and multi-output models across sklearn, XGBoost, LightGBM, PyTorch, and MLflow.
pip install -e .Copy and edit examples/configs/mlflow/blackbox_pytorch_classification.yaml:
name: "my_robustness_eval"
description: "Testing model robustness"
dataset:
path: "data/my_data.csv" # CSV with features + target column
format: "csv"
target_column: "target"
model:
backend: "sklearn" # or pytorch, xgboost, lightgbm, mlflow
path: "models/my_model.joblib" # Saved model path
task_type: "classification" # or regression
robustness:
attacks:
- type: "fgsm"
epsilon: 0.1
- type: "pgd"
epsilon: 0.1
max_iter: 20
sample_size: 50 # How many samples to attackpython -m runner run --config my_config.yaml# Interactive HTML report
open outputs/report.html
# Raw JSON metrics
cat outputs/metrics.json | python -m json.tool| Framework | Format | Status | Notes |
|---|---|---|---|
| scikit-learn | .joblib, .pkl |
✅ Full | RandomForest, SVM, LogisticRegression, etc. |
| XGBoost | .joblib, .pkl |
✅ Full | Classification & regression |
| LightGBM | .joblib, .pkl |
✅ Full | Classification & regression |
| PyTorch | .pt, .pth |
✅ Full | Gradient-based white-box attacks |
| PyTorch Lightning | Checkpoint | ✅ Full | Trained model state |
| MLflow | Model Registry | ✅ Full | Any MLflow-registered model |
Task types: Classification, Regression, Multi-output regression
| Attack | Best For | Example Params |
|---|---|---|
| FGSM | Fast gradient | epsilon: 0.1 |
| PGD | Stronger gradient-based | epsilon: 0.1, max_iter: 20, eps_step: 0.01 |
| BIM | Iterative version of FGSM | epsilon: 0.1, max_iter: 5 |
When to use: PyTorch models, classification tasks, you need strong attacks.
| Attack | Query Efficiency | Use Case |
|---|---|---|
| HopSkipJump | Medium | Decision boundaries, sklearn models |
| Bayesian | High | Regression, small query budgets |
| Random Search | Low | Baseline, sanity check |
When to use: sklearn/tree models, regression, production APIs where gradients unavailable.
name: "string" # Unique run name (appears in reports)
description: "string" # What you're testingdataset:
path: "string" # CSV file path
format: "csv" # Only CSV supported
target_column: "string" # Column name for labels/targets
# Optional:
target_columns: # For multi-output regression
- "output_1"
- "output_2"For sklearn/XGBoost/LightGBM:
model:
backend: "sklearn" # Type
path: "path/to/model.joblib" # File
task_type: "classification" # or regression
clip_values: [0.0, 1.0] # Input boundsFor PyTorch:
model:
backend: "pytorch"
path: "path/to/model.pt"
task_type: "classification"
input_shape: [n_features] # e.g., [28, 28] for images
clip_values: [0.0, 1.0]
# If using custom scaling:
scaler_path: "path/to/scaler.pkl"For MLflow:
model:
backend: "mlflow"
mlflow_tracking_uri: "http://localhost:5000" # or local path
mlflow_run_id: "abc123def456" # From MLflow UI
mlflow_model_uri: "models:/my-model/production"
task_type: "classification"
mlflow_validate_signature: truerobustness:
attacks:
- type: "fgsm"
epsilon: 0.1
norm: "inf" # or "2" for L2
targeted: false
- type: "pgd"
epsilon: 0.1
eps_step: 0.01 # Step size per iteration
max_iter: 20 # PGD iterations
norm: "inf"
targeted: false
# How many samples to evaluate
sample_size: 50 # For white-box attacks
eval_subset_size: 100 # For pure black-box attacks
# Query budget for Bayesian optimization
query_budget_auto: true # Auto-calibrate from data
query_budget_pilot_samples: 5
query_budget_pilot_percentile: 0.90Structure:
{
"report_meta": {
"family": "white_box",
"task_type": "classification",
"attack_name": "Pgd",
"model_backend": "pytorch",
"dataset": "path/to/data.csv"
},
"attack_setup": {
"epsilon": 0.1,
"norm": "inf",
"steps": 20,
"samples_evaluated": 50
},
"performance_summary": {
"primary_metrics": [
{
"key": "clean_accuracy",
"label": "Clean Accuracy",
"value": 0.95,
"format": "percent"
},
{
"key": "adversarial_accuracy",
"label": "Adversarial Accuracy",
"value": 0.78,
"format": "percent"
},
{
"key": "attack_success_rate",
"label": "Attack Success Rate",
"value": 0.22,
"format": "percent"
}
]
},
"charts": {
"robustness_curve": {
"type": "line",
"x_label": "epsilon",
"y_label": "robust_accuracy",
"points": [
[0.05, 0.92],
[0.1, 0.78],
[0.2, 0.55]
]
},
"attack_efficiency": {
"type": "line",
"x_label": "queries",
"y_label": "success_rate",
"points": [[50, 0.22]]
},
"attack_profile": {
"type": "bar",
"x_label": "feature",
"y_label": "mean_perturbation",
"points": [
["feature_5", 0.095],
["feature_12", 0.089]
]
}
},
"warnings": [
"Small sample size may not represent full dataset"
]
}Shows at a glance:
- Clean accuracy vs. adversarial accuracy
- Attack success rate
- Per-feature vulnerability (which features attacked?)
- Robustness curve (how does performance degrade with epsilon?)
- Attack efficiency (queries vs. success for black-box)
- Prediction shifts (how much did outputs change?)
Metrics displayed:
- Clean metrics: Baseline performance on unperturbed data
- Adversarial metrics: Performance under attack
- Robustness metrics: Robust accuracy, attack success rate, accuracy drop
- Perturbation analysis: Feature-level vulnerability, mean perturbation size
Exact configuration used (with defaults filled in). Use this to reproduce runs exactly.
Access via browser: http://localhost:9005
Three main views:
- Upload a YAML config file
- View preprocessing steps
- See model loading status
- Shows evaluation progress
- Real-time status updates
- Estimated time remaining
Shows interactive visualizations:
- Performance Summary: Cards showing clean accuracy, adversarial accuracy, drop
- Robustness Curve: How accuracy falls as attack strength increases
- Attack Efficiency: For black-box attacks, how many queries needed for success
- Feature Vulnerability: Which features are most attacked
- Per-Sample Perturbations: Magnitude of change per sample
- Warnings: Any issues or limitations
Download button: Export full metrics.json for analysis
- Adversarial accuracy ≥ 80% of clean accuracy
- Attack requires large epsilon values
- Few features are vulnerable
- Adversarial accuracy 50-80% of clean accuracy
- Attacks succeed with moderate epsilon
- Specific features are highly vulnerable
- Adversarial accuracy < 50% of clean accuracy
- Small perturbations (epsilon < 0.05) break the model
- Many features are vulnerable
Next steps:
- Try different attack types — black-box vs white-box may show different weaknesses
- Check
attack_profile— retrain focusing on vulnerable features - Increase
sample_size— small samples may not represent full dataset - Try ensemble methods or adversarial training
Q: Which attack should I use?
A: Start with random_search (fast baseline), then try pgd (stronger) if you have PyTorch. For sklearn, use hopskipjump.
Q: My config failed with "timeout"?
A: Reduce sample_size, max_iter, or max_evaluations. Evaluations taking >5 min need optimization.
Q: What does epsilon mean?
A: Maximum allowed perturbation size (in input units). Lower = harder for attacker. For normalized [0,1] inputs, try 0.05-0.2.
Q: Can I test on my production model?
A: Yes! Use MLflow backend and point to your model registry. For API models, treat as black-box attacks.
Q: How many samples do I need?
A: At least 10 for quick tests, 50-100 for reliable results. Larger datasets need more samples for confidence.
Q: Does this work on images?
A: Not directly (this tool is for tabular data). For images, use ART or Foolbox directly.
- Full architecture details: See
docs/ARCHITECTURE.md - Advanced configurations: See
docs/USER_INSTRUCTIONS.md - Metrics explained: See
docs/ADVERSARIAL_ROBUSTNESS_METRICS.md - MLflow integration: See
docs/MLFLOW_GUIDE.md - Example configs: Browse
examples/configs/
- Check file path is correct and readable
- Verify model format matches backend (e.g.,
.joblibfor sklearn) - For MLflow: verify run_id and model_uri in your tracking server
- White-box attacks (FGSM, PGD) require PyTorch models
- sklearn/tree models automatically use black-box fallbacks
- Check supported attacks table above
- Reduce
sample_size - Reduce
max_iterfor PGD/BIM - Use fewer attack types in one config
- Check that
clip_valuesmatch your input bounds - Verify
task_typeis correct (classification vs regression) - Look at
config_resolved.yamlto see what actually ran
- Browse example configs:
examples/configs/ - Run smoke test:
pytest tests/test_smoke.py - Check logs in
outputs/directory - File an issue on GitHub with config + error message
Enjoy testing! 🛡️