class_docstr: Interface for torch models.
class_docstr_tok: ["Interface","for","torch","models","."]
docstr: In every iteration yields a copy of the model with one additional layer's parameters randomized.
  For cascading randomization, set order (str) to 'top_down'. For independent randomization,
  set it to 'independent'. For bottom-up order, set it to 'bottom_up'.
  
  Parameters
  ----------
  order: string
      The various ways that a model's weights of a layer can be randomised.
  seed: integer
      The seed of the random layer generator.
  
  Returns
  -------
  layer.name, random_layer_model: string, torch.nn
      The layer name and the model.
docstr_tok: ["In","every","iteration","yields","a","copy","of","the","model","with","one","additional","layer","'s","parameters","randomized",".","For","cascading","randomization",",","set","order","(","str",")","to","'top_down","'",".","For","independent","randomization",",","set","it","to","'independent","'",".","For","bottom-up","order",",","set","it","to","'bottom_up","'",".","Parameters","--","--","--","--","--","order",":","string","The","various","ways","that","a","model","'s","weights","of","a","layer","can","be","randomised",".","seed",":","integer","The","seed","of","the","random","layer","generator",".","Returns","--","--","--","-","layer.name",",","random_layer_model",":","string",",","torch.nn","The","layer","name","and","the","model","."]
code: def get_random_layer_generator(
      self, order: str = "top_down", seed: int = 42
  ) -> Generator[Tuple[str, nn.Module], None, None]:
      """
      In every iteration yields a copy of the model with one additional layer's parameters randomized.
      For cascading randomization, set order (str) to 'top_down'. For independent randomization,
      set it to 'independent'. For bottom-up order, set it to 'bottom_up'.
  
      Parameters
      ----------
      order: string
          The various ways that a model's weights of a layer can be randomised.
      seed: integer
          The seed of the random layer generator.
  
      Returns
      -------
      layer.name, random_layer_model: string, torch.nn
          The layer name and the model.
      """
      original_parameters = self.state_dict()
      random_layer_model = deepcopy(self.model)
  
      modules = [
          l
          for l in random_layer_model.named_modules()
          if (hasattr(l[1], "reset_parameters"))
      ]
  
      if order == "top_down":
          modules = modules[::-1]
  
      for module in modules:
          if order == "independent":
              random_layer_model.load_state_dict(original_parameters)
          torch.manual_seed(seed=seed + 1)
          module[1].reset_parameters()
          yield module[0], random_layer_model
  
imports: import copy
  from contextlib import suppress
  from copy import deepcopy
  from typing import Any, Dict, Optional, Tuple, List, Union, Generator
  import warnings
  import logging
  import numpy
  import torch
  from torch import nn
  from functools import lru_cache
  from quantus.helpers import utils
  from quantus.helpers.model.model_interface import ModelInterface
label_desc: Use image node_id 9 for calling the PyTorchModel obj's underlying member method code with example usage: obj.get_random_layer_generator(order, seed) without return types