parameters: (
      model: torch.nn.Module,
      inputs: Sequence[Any],
      target_submodules: Iterable[str]
  )
return_statement: return results
docstring: Generate inputs for targeting submdoules in the given model. Note that if two submodules refer to the same obj, this
      function doesn't work.
  
      Args:
          model: root model.
          inputs: inputs to the root model.
          target_submodules: submodules that we want to generate inputs for.
  
      Returns:
          A dict that maps from submodule name to its inputs.
docstring_summary: Generate inputs for targeting submdoules in the given model. Note that if two submodules refer to the same obj, this
      function doesn't work.
docstring_tokens: Generate inputs for targeting submdoules in the given model . Note that if two submodules refer to the same obj this function doesn t work .
function: def generate_inputs_for_submodules(
      model: torch.nn.Module,
      inputs: Sequence[Any],
      target_submodules: Iterable[str]
  ) -> Dict[str, Any]:
      """
      Generate inputs for targeting submdoules in the given model. Note that if two submodules refer to the same obj, this
      function doesn't work.
  
      Args:
          model: root model.
          inputs: inputs to the root model.
          target_submodules: submodules that we want to generate inputs for.
  
      Returns:
          A dict that maps from submodule name to its inputs.
      """
  
      handles = []
      results = {}
      submodule_to_names = dict((mod, name) for name, mod in model.named_modules())
  
      def pre_forward(module, module_inputs):
          results[submodule_to_names[module]] = module_inputs
      try:
          for name, mod in model.named_modules():
              if name in target_submodules:
                  handles.append(mod.register_forward_pre_hook(pre_forward))
          model(*inputs)
      except Exception as e:
          warnings.warn(f"Failed to generate submodule inputs because of the following error:\n{e}")
      finally:
          for h in handles:
              h.remove()
      return results
function_tokens: def generate_inputs_for_submodules ( model : torch . nn . Module , inputs : Sequence [ Any ] , target_submodules : Iterable [ str ] ) -> Dict [ str , Any ] : handles = [ ] results = { } submodule_to_names = dict ( ( mod , name ) for name , mod in model . named_modules ( ) ) def pre_forward ( module , module_inputs ) : results [ submodule_to_names [ module ] ] = module_inputs try : for name , mod in model . named_modules ( ) : if name in target_submodules : handles . append ( mod . register_forward_pre_hook ( pre_forward ) ) model ( * inputs ) except Exception as e : warnings . warn ( f"Failed to generate submodule inputs because of the following error:\n{e}" ) finally : for h in handles : h . remove ( ) return results