class_docstr: An attack generates adversarial examples on text.
  
  An attack is comprised of a goal function, constraints, transformation, and a search method. Use :meth:`attack` method to attack one sample at a time.
  
  Args:
      goal_function (:class:`~textattack.goal_functions.GoalFunction`):
          A function for determining how well a perturbation is doing at achieving the attack's goal.
      constraints (list of :class:`~textattack.constraints.Constraint` or :class:`~textattack.constraints.PreTransformationConstraint`):
          A list of constraints to add to the attack, defining which perturbations are valid.
      transformation (:class:`~textattack.transformations.Transformation`):
          The transformation applied at each step of the attack.
      search_method (:class:`~textattack.search_methods.SearchMethod`):
          The method for exploring the search space of possible perturbations
      transformation_cache_size (:obj:`int`, `optional`, defaults to :obj:`2**15`):
          The number of items to keep in the transformations cache
      constraint_cache_size (:obj:`int`, `optional`, defaults to :obj:`2**15`):
          The number of items to keep in the constraints cache
  
  Example::
  
      >>> import textattack
      >>> import transformers
  
      >>> # Load model, tokenizer, and model_wrapper
      >>> model = transformers.AutoModelForSequenceClassification.from_pretrained("textattack/bert-base-uncased-imdb")
      >>> tokenizer = transformers.AutoTokenizer.from_pretrained("textattack/bert-base-uncased-imdb")
      >>> model_wrapper = textattack.models.wrappers.HuggingFaceModelWrapper(model, tokenizer)
  
      >>> # Construct our four components for `Attack`
      >>> from textattack.constraints.pre_transformation import RepeatModification, StopwordModification
      >>> from textattack.constraints.semantics import WordEmbeddingDistance
      >>> from textattack.transformations import WordSwapEmbedding
      >>> from textattack.search_methods import GreedyWordSwapWIR
  
      >>> goal_function = textattack.goal_functions.UntargetedClassification(model_wrapper)
      >>> constraints = [
      ...     RepeatModification(),
      ...     StopwordModification(),
      ...     WordEmbeddingDistance(min_cos_sim=0.9)
      ... ]
      >>> transformation = WordSwapEmbedding(max_candidates=50)
      >>> search_method = GreedyWordSwapWIR(wir_method="delete")
  
      >>> # Construct the actual attack
      >>> attack = textattack.Attack(goal_function, constraints, transformation, search_method)
  
      >>> input_text = "I really enjoyed the new movie that came out last month."
      >>> label = 1 #Positive
      >>> attack_result = attack.attack(input_text, label)
class_docstr_tok: ["An","attack","generates","adversarial","examples","on","text",".","An","attack","is","comprised","of","a","goal","function",",","constraints",",","transformation",",","and","a","search","method",".","Use",":","meth",":","`","attack","`","method","to","attack","one","sample","at","a","time",".","Args",":","goal_function","(",":","class",":","`","~textattack.goal_functions.GoalFunction","`",")",":","A","function","for","determining","how","well","a","perturbation","is","doing","at","achieving","the","attack","'s","goal",".","constraints","(","list","of",":","class",":","`","~textattack.constraints.Constraint","`","or",":","class",":","`","~textattack.constraints.PreTransformationConstraint","`",")",":","A","list","of","constraints","to","add","to","the","attack",",","defining","which","perturbations","are","valid",".","transformation","(",":","class",":","`","~textattack.transformations.Transformation","`",")",":","The","transformation","applied","at","each","step","of","the","attack",".","search_method","(",":","class",":","`","~textattack.search_methods.SearchMethod","`",")",":","The","method","for","exploring","the","search","space","of","possible","perturbations","transformation_cache_size","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","2","*","*","15","`",")",":","The","number","of","items","to","keep","in","the","transformations","cache","constraint_cache_size","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to",":","obj",":","`","2","*","*","15","`",")",":","The","number","of","items","to","keep","in","the","constraints","cache","Example",":",":",">",">",">","import","textattack",">",">",">","import","transformers",">",">",">","#","Load","model",",","tokenizer",",","and","model_wrapper",">",">",">","model","=","transformers.AutoModelForSequenceClassification.from_pretrained","(","``","textattack\/bert-base-uncased-imdb","''",")",">",">",">","tokenizer","=","transformers.AutoTokenizer.from_pretrained","(","``","textattack\/bert-base-uncased-imdb","''",")",">",">",">","model_wrapper","=","textattack.models.wrappers.HuggingFaceModelWrapper","(","model",",","tokenizer",")",">",">",">","#","Construct","our","four","components","for","`","Attack","`",">",">",">","from","textattack.constraints.pre_transformation","import","RepeatModification",",","StopwordModification",">",">",">","from","textattack.constraints.semantics","import","WordEmbeddingDistance",">",">",">","from","textattack.transformations","import","WordSwapEmbedding",">",">",">","from","textattack.search_methods","import","GreedyWordSwapWIR",">",">",">","goal_function","=","textattack.goal_functions.UntargetedClassification","(","model_wrapper",")",">",">",">","constraints","=","[","...","RepeatModification","(",")",",","...","StopwordModification","(",")",",","...","WordEmbeddingDistance","(","min_cos_sim=0.9",")","...","]",">",">",">","transformation","=","WordSwapEmbedding","(","max_candidates=50",")",">",">",">","search_method","=","GreedyWordSwapWIR","(","wir_method=","''","delete","''",")",">",">",">","#","Construct","the","actual","attack",">",">",">","attack","=","textattack.Attack","(","goal_function",",","constraints",",","transformation",",","search_method",")",">",">",">","input_text","=","``","I","really","enjoyed","the","new","movie","that","came","out","last","month",".","''",">",">",">","label","=","1","#","Positive",">",">",">","attack_result","=","attack.attack","(","input_text",",","label",")"]
docstr: Move any `torch.nn.Module` models that are part of Attack to GPU.
docstr_tok: ["Move","any","`","torch.nn.Module","`","models","that","are","part","of","Attack","to","GPU","."]
code: def cuda_(self):
      """Move any `torch.nn.Module` models that are part of Attack to GPU."""
      visited = set()
  
      def to_cuda(obj):
          visited.add(id(obj))
          if isinstance(obj, torch.nn.Module):
              obj.to(textattack.shared.utils.device)
          elif isinstance(
              obj,
              (
                  Attack,
                  GoalFunction,
                  Transformation,
                  SearchMethod,
                  Constraint,
                  PreTransformationConstraint,
                  ModelWrapper,
              ),
          ):
              for key in obj.__dict__:
                  s_obj = obj.__dict__[key]
                  if id(s_obj) not in visited:
                      to_cuda(s_obj)
          elif isinstance(obj, (list, tuple)):
              for item in obj:
                  if id(item) not in visited and isinstance(
                      item,
                      (
                          Transformation,
                          Constraint,
                          PreTransformationConstraint,
                      ),
                  ):
                      to_cuda(item)
  
      to_cuda(self)
  
imports: from collections import OrderedDict
  from typing import List, Union
  import lru
  import torch
  import textattack
  from textattack.attack_results import FailedAttackResult, MaximizedAttackResult, SkippedAttackResult, SuccessfulAttackResult
  from textattack.constraints import Constraint, PreTransformationConstraint
  from textattack.goal_function_results import GoalFunctionResultStatus
  from textattack.goal_functions import GoalFunction
  from textattack.models.wrappers import ModelWrapper
  from textattack.search_methods import SearchMethod
  from textattack.shared import AttackedText, utils
  from textattack.transformations import CompositeTransformation, Transformation
label_desc: Use image node_id 4 for calling the Attack obj's underlying member method code with example usage: obj.cuda_() without return types