Following this instruction :
1. Strictly adhere to PEP-8 standards, ensuring code is clean, well-structured, and follows Python's style guide for readability.
2. Use appropriate modules like `typing` for type hints, ensuring code clarity, maintainability, and leveraging Python's standard libraries effectively.
3. Focus on time, space, robustness, scalability; write optimized, efficient code that can handle large datasets and scale seamlessly.
4. Implement comprehensive error handling, catching exceptions gracefully, providing meaningful error messages, and ensuring code robustness under unexpected conditions.
5. Ensure the developer agent writes advanced, maintainable Python code, balancing performance and readability while adhering to best practices.

TASK : objective below all api we have develop from scratch using only torch module :

user_input :
1 Model (nn.module) 
2) loss fumnction
3) optimiser
3) adversarical_sample ( batch_size, channel, height, weight)
4) label(batch_size, true_value)

The defense trainers provided by ART offer various adversarial training techniques, each aimed at improving model robustness against adversarial attacks. Below are the mathematical formulations and concepts underlying each of these training methods:

---

### 1. **AdversarialTrainer**
   - **Purpose**: Trains a model with both original and adversarial examples to improve robustness.
   - **Objective**:
     \[
     \min_\theta \mathbb{E}_{(x, y) \sim \mathcal{D}} \left[ \max_{\delta \in \Delta} \mathcal{L}(f_\theta(x + \delta), y) \right]
     \]
     where \( f_\theta \) is the model with parameters \( \theta \), \( x \) and \( y \) are inputs and labels, \( \delta \) is the perturbation within the allowed set \( \Delta \), and \( \mathcal{L} \) is the loss function. This objective balances regular and adversarial examples during training.

### 2. **AdversarialTrainerCertifiedPytorch**
   - **Purpose**: Uses certified defenses to guarantee robustness within a certain perturbation radius, providing formal robustness guarantees.
   - **Objective**:
     \[
     \min_\theta \mathbb{E}_{(x, y) \sim \mathcal{D}} \left[ \mathcal{L}(f_\theta(x), y) + \gamma \cdot g(x, y) \right]
     \]
     where \( g(x, y) \) represents the certification term and \( \gamma \) controls its weight. This term assesses robustness guarantees for each input based on a certified defense.

### 3. **AdversarialTrainerCertifiedIBPPyTorch**
   - **Purpose**: Uses Interval Bound Propagation (IBP) to provide certified robustness through interval-based adversarial bounds.
   - **Objective**:
     \[
     \min_\theta \mathbb{E}_{(x, y) \sim \mathcal{D}} \left[ \mathcal{L}(f_\theta([l, u]), y) \right]
     \]
     where \([l, u]\) represents the lower and upper bounds on activations during forward propagation, ensuring each intermediate layer's output stays within bounds. This minimizes adversarial effects across the model.

### 4. **AdversarialTrainerMadryPGD**
   - **Purpose**: Employs Projected Gradient Descent (PGD) for generating adversarial examples, following Madry et al.'s approach.
   - **Objective**:
     \[
     \min_\theta \mathbb{E}_{(x, y) \sim \mathcal{D}} \left[ \max_{\|\delta\| \leq \epsilon} \mathcal{L}(f_\theta(x + \delta), y) \right]
     \]
     where PGD iteratively updates \( \delta \) with gradients to maximize loss, bounded by \( \epsilon \) in \( \ell_p \)-norm.

### 5. **AdversarialTrainerFBF (Fast Binary Feedback)**
   - **Purpose**: Uses fast binary feedback to guide adversarial training, a faster alternative to PGD-based training.
   - **Objective**: Similar to MadryPGD but optimized with binary feedback to improve efficiency, retaining robustness by reducing computational overhead of gradient-based attacks.

### 6. **AdversarialTrainerTRADES**
   - **Purpose**: Balances robustness with accuracy using TRADES (TRadeoff-inspired Adversarial DEfense via Surrogate-loss minimization).
   - **Objective**:
     \[
     \min_\theta \mathbb{E}_{(x, y) \sim \mathcal{D}} \left[ \mathcal{L}(f_\theta(x), y) + \lambda \cdot \max_{\|\delta\| \leq \epsilon} \mathcal{L}(f_\theta(x), f_\theta(x + \delta)) \right]
     \]
     where \( \lambda \) balances natural and adversarial losses, encouraging robustness without sacrificing accuracy.

### 7. **AdversarialTrainerAWP (Adversarial Weight Perturbation)**
   - **Purpose**: Adds adversarial perturbations to model weights, aiming to improve robustness by optimizing against perturbations.
   - **Objective**:
     \[
     \min_\theta \max_{\|\delta_w\| \leq \epsilon_w} \mathbb{E}_{(x, y) \sim \mathcal{D}} \left[ \mathcal{L}(f_{\theta + \delta_w}(x), y) \right]
     \]
     where \( \delta_w \) represents perturbations in weights, constrained by \( \epsilon_w \).

### 8. **AdversarialTrainerOAAT (One Attack At a Time)**
   - **Purpose**: Sequentially trains the model on different attack types in separate rounds, aiming for broad robustness across attack types.
   - **Objective**: An iterative approach that minimizes a separate adversarial loss for each attack, producing a final model that is robust across multiple attack vectors.

### 9. **DPInstaHideTrainer (Differential Privacy InstaHide)**
   - **Purpose**: Combines differential privacy with InstaHide to protect data privacy while training robust models.
   - **Objective**:
     \[
     \min_\theta \mathbb{E}_{(x, y) \sim \mathcal{D}} \left[ \mathcal{L}(f_\theta(x + \delta_{DP}), y) \right]
     \]
     where \( \delta_{DP} \) represents a privacy-preserving perturbation that aligns with differential privacy guarantees.