class_docstr: Arguments for ``Trainer`` class that is used for adversarial training.
  
  Args:
      num_epochs (:obj:`int`, `optional`, defaults to :obj:`3`):
          Total number of epochs for training.
      num_clean_epochs (:obj:`int`, `optional`, defaults to :obj:`1`):
          Number of epochs to train on just the original training dataset before adversarial training.
      attack_epoch_interval (:obj:`int`, `optional`, defaults to :obj:`1`):
          Generate a new adversarial training set every `N` epochs.
      early_stopping_epochs (:obj:`int`, `optional`, defaults to :obj:`None`):
          Number of epochs validation must increase before stopping early (:obj:`None` for no early stopping).
      learning_rate (:obj:`float`, `optional`, defaults to :obj:`5e-5`):
          Learning rate for optimizer.
      num_warmup_steps (:obj:`int` or :obj:`float`, `optional`, defaults to :obj:`500`):
          The number of steps for the warmup phase of linear scheduler.
          If :obj:`num_warmup_steps` is a :obj:`float` between 0 and 1, the number of warmup steps will be :obj:`math.ceil(num_training_steps * num_warmup_steps)`.
      weight_decay (:obj:`float`, `optional`, defaults to :obj:`0.01`):
          Weight decay (L2 penalty).
      per_device_train_batch_size (:obj:`int`, `optional`, defaults to :obj:`8`):
          The batch size per GPU/CPU for training.
      per_device_eval_batch_size (:obj:`int`, `optional`, defaults to :obj:`32`):
          The batch size per GPU/CPU for evaluation.
      gradient_accumulation_steps (:obj:`int`, `optional`, defaults to :obj:`1`):
          Number of updates steps to accumulate the gradients before performing a backward/update pass.
      random_seed (:obj:`int`, `optional`, defaults to :obj:`786`):
          Random seed for reproducibility.
      parallel (:obj:`bool`, `optional`, defaults to :obj:`False`):
          If :obj:`True`, train using multiple GPUs using :obj:`torch.DataParallel`.
      load_best_model_at_end (:obj:`bool`, `optional`, defaults to :obj:`False`):
          If :obj:`True`, keep track of the best model across training and load it at the end.
      alpha (:obj:`float`, `optional`, defaults to :obj:`1.0`):
          The weight for adversarial loss.
      num_train_adv_examples (:obj:`int` or :obj:`float`, `optional`, defaults to :obj:`-1`):
          The number of samples to successfully attack when generating adversarial training set before start of every epoch.
          If :obj:`num_train_adv_examples` is a :obj:`float` between 0 and 1, the number of adversarial examples generated is
          fraction of the original training set.
      query_budget_train (:obj:`int`, `optional`, defaults to :obj:`None`):
          The max query budget to use when generating adversarial training set. :obj:`None` means infinite query budget.
      attack_num_workers_per_device (:obj:`int`, defaults to `optional`, :obj:`1`):
          Number of worker processes to run per device for attack. Same as :obj:`num_workers_per_device` argument for :class:`~textattack.AttackArgs`.
      output_dir (:obj:`str`, `optional`):
          Directory to output training logs and checkpoints. Defaults to :obj:`./outputs/%Y-%m-%d-%H-%M-%S-%f` format.
      checkpoint_interval_steps (:obj:`int`, `optional`, defaults to :obj:`None`):
          If set, save model checkpoint after every `N` updates to the model.
      checkpoint_interval_epochs (:obj:`int`, `optional`, defaults to :obj:`None`):
          If set, save model checkpoint after every `N` epochs.
      save_last (:obj:`bool`, `optional`, defaults to :obj:`True`):
          If :obj:`True`, save the model at end of training. Can be used with :obj:`load_best_model_at_end` to save the best model at the end.
      log_to_tb (:obj:`bool`, `optional`, defaults to :obj:`False`):
          If :obj:`True`, log to Tensorboard.
      tb_log_dir (:obj:`str`, `optional`, defaults to :obj:`"./runs"`):
          Path of Tensorboard log directory.
      log_to_wandb (:obj:`bool`, `optional`, defaults to :obj:`False`):
          If :obj:`True`, log to Wandb.
      wandb_project (:obj:`str`, `optional`, defaults to :obj:`"textattack"`):
          Name of Wandb project for logging.
      logging_interval_step (:obj:`int`, `optional`, defaults to :obj:`1`):
          Log to Tensorboard/Wandb every `N` training steps.
class_docstr_tok: ["Arguments","for","``","Trainer","``","class","that","is","used","for","adversarial","training",".","Args",":","num_epochs","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","3","`",")",":","Total","number","of","epochs","for","training",".","num_clean_epochs","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","1","`",")",":","Number","of","epochs","to","train","on","just","the","original","training","dataset","before","adversarial","training",".","attack_epoch_interval","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","1","`",")",":","Generate","a","new","adversarial","training","set","every","`","N","`","epochs",".","early_stopping_epochs","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","None","`",")",":","Number","of","epochs","validation","must","increase","before","stopping","early","(",":","obj",":","`","None","`","for","no","early","stopping",")",".","learning_rate","(",":","obj",":","`","float","`",",","`","optional","`",",","defaults","to",":","obj",":","`","5e-5","`",")",":","Learning","rate","for","optimizer",".","num_warmup_steps","(",":","obj",":","`","int","`","or",":","obj",":","`","float","`",",","`","optional","`",",","defaults","to",":","obj",":","`","500","`",")",":","The","number","of","steps","for","the","warmup","phase","of","linear","scheduler",".","If",":","obj",":","`","num_warmup_steps","`","is","a",":","obj",":","`","float","`","between","0","and","1",",","the","number","of","warmup","steps","will","be",":","obj",":","`","math.ceil","(","num_training_steps","*","num_warmup_steps",")","`",".","weight_decay","(",":","obj",":","`","float","`",",","`","optional","`",",","defaults","to",":","obj",":","`","0.01","`",")",":","Weight","decay","(","L2","penalty",")",".","per_device_train_batch_size","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","8","`",")",":","The","batch","size","per","GPU\/CPU","for","training",".","per_device_eval_batch_size","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","32","`",")",":","The","batch","size","per","GPU\/CPU","for","evaluation",".","gradient_accumulation_steps","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","1","`",")",":","Number","of","updates","steps","to","accumulate","the","gradients","before","performing","a","backward\/update","pass",".","random_seed","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","786","`",")",":","Random","seed","for","reproducibility",".","parallel","(",":","obj",":","`","bool","`",",","`","optional","`",",","defaults","to",":","obj",":","`","False","`",")",":","If",":","obj",":","`","True","`",",","train","using","multiple","GPUs","using",":","obj",":","`","torch.DataParallel","`",".","load_best_model_at_end","(",":","obj",":","`","bool","`",",","`","optional","`",",","defaults","to",":","obj",":","`","False","`",")",":","If",":","obj",":","`","True","`",",","keep","track","of","the","best","model","across","training","and","load","it","at","the","end",".","alpha","(",":","obj",":","`","float","`",",","`","optional","`",",","defaults","to",":","obj",":","`","1.0","`",")",":","The","weight","for","adversarial","loss",".","num_train_adv_examples","(",":","obj",":","`","int","`","or",":","obj",":","`","float","`",",","`","optional","`",",","defaults","to",":","obj",":","`","-1","`",")",":","The","number","of","samples","to","successfully","attack","when","generating","adversarial","training","set","before","start","of","every","epoch",".","If",":","obj",":","`","num_train_adv_examples","`","is","a",":","obj",":","`","float","`","between","0","and","1",",","the","number","of","adversarial","examples","generated","is","fraction","of","the","original","training","set",".","query_budget_train","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","None","`",")",":","The","max","query","budget","to","use","when","generating","adversarial","training","set",".",":","obj",":","`","None","`","means","infinite","query","budget",".","attack_num_workers_per_device","(",":","obj",":","`","int","`",",","defaults","to","`","optional","`",",",":","obj",":","`","1","`",")",":","Number","of","worker","processes","to","run","per","device","for","attack",".","Same","as",":","obj",":","`","num_workers_per_device","`","argument","for",":","class",":","`","~textattack.AttackArgs","`",".","output_dir","(",":","obj",":","`","str","`",",","`","optional","`",")",":","Directory","to","output","training","logs","and","checkpoints",".","Defaults","to",":","obj",":","`",".\/outputs\/","%","Y-","%","m-","%","d-","%","H-","%","M-","%","S-","%","f","`","format",".","checkpoint_interval_steps","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","None","`",")",":","If","set",",","save","model","checkpoint","after","every","`","N","`","updates","to","the","model",".","checkpoint_interval_epochs","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","None","`",")",":","If","set",",","save","model","checkpoint","after","every","`","N","`","epochs",".","save_last","(",":","obj",":","`","bool","`",",","`","optional","`",",","defaults","to",":","obj",":","`","True","`",")",":","If",":","obj",":","`","True","`",",","save","the","model","at","end","of","training",".","Can","be","used","with",":","obj",":","`","load_best_model_at_end","`","to","save","the","best","model","at","the","end",".","log_to_tb","(",":","obj",":","`","bool","`",",","`","optional","`",",","defaults","to",":","obj",":","`","False","`",")",":","If",":","obj",":","`","True","`",",","log","to","Tensorboard",".","tb_log_dir","(",":","obj",":","`","str","`",",","`","optional","`",",","defaults","to",":","obj",":","`","``",".\/runs","''","`",")",":","Path","of","Tensorboard","log","directory",".","log_to_wandb","(",":","obj",":","`","bool","`",",","`","optional","`",",","defaults","to",":","obj",":","`","False","`",")",":","If",":","obj",":","`","True","`",",","log","to","Wandb",".","wandb_project","(",":","obj",":","`","str","`",",","`","optional","`",",","defaults","to",":","obj",":","`","``","textattack","''","`",")",":","Name","of","Wandb","project","for","logging",".","logging_interval_step","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","1","`",")",":","Log","to","Tensorboard\/Wandb","every","`","N","`","training","steps","."]
code: def __post_init__(self):
      assert self.num_epochs > 0, "`num_epochs` must be greater than 0."
      assert (
          self.num_clean_epochs >= 0
      ), "`num_clean_epochs` must be greater than or equal to 0."
      if self.early_stopping_epochs is not None:
          assert (
              self.early_stopping_epochs > 0
          ), "`early_stopping_epochs` must be greater than 0."
      if self.attack_epoch_interval is not None:
          assert (
              self.attack_epoch_interval > 0
          ), "`attack_epoch_interval` must be greater than 0."
      assert (
          self.num_warmup_steps >= 0
      ), "`num_warmup_steps` must be greater than or equal to 0."
      assert (
          self.gradient_accumulation_steps > 0
      ), "`gradient_accumulation_steps` must be greater than 0."
      assert (
          self.num_clean_epochs <= self.num_epochs
      ), f"`num_clean_epochs` cannot be greater than `num_epochs` ({self.num_clean_epochs} > {self.num_epochs})."
  
      if isinstance(self.num_train_adv_examples, float):
          assert (
              self.num_train_adv_examples >= 0.0
              and self.num_train_adv_examples <= 1.0
          ), "If `num_train_adv_examples` is float, it must be between 0 and 1."
      elif isinstance(self.num_train_adv_examples, int):
          assert (
              self.num_train_adv_examples > 0
              or self.num_train_adv_examples == -1
          ), "If `num_train_adv_examples` is int, it must be greater than 0 or equal to -1."
      else:
          raise TypeError(
              "`num_train_adv_examples` must be of either type `int` or `float`."
          )
  
imports: from dataclasses import dataclass, field
  import datetime
  import os
  from typing import Union
  from textattack.datasets import HuggingFaceDataset
  from textattack.models.helpers import LSTMForClassification, WordCNNForClassification
  from textattack.models.wrappers import HuggingFaceModelWrapper, ModelWrapper, PyTorchModelWrapper
  from textattack.shared import logger
  from textattack.shared.utils import ARGS_SPLIT_TOKEN
  from .attack import Attack
  from .attack_args import ATTACK_RECIPE_NAMES
label_desc: Use image node_id 1 for calling the TrainingArgs obj's underlying member method code with example usage: obj.__post_init__() without return types