class_docstr: A class that provides a way to access the submodules and parameters/buffers of a module.
  
  It provides caching mechanism to speed up submodule lookups.
  This is useful for functional programming to manipulate the module state.
class_docstr_tok: ["A","class","that","provides","a","way","to","access","the","submodules","and","parameters\/buffers","of","a","module",".","It","provides","caching","mechanism","to","speed","up","submodule","lookups",".","This","is","useful","for","functional","programming","to","manipulate","the","module","state","."]
docstr: Swap the attributes specified by the given paths to values.
  
  For example, to swap the attributes mod.layer1.conv1.weight and
  mod.layer1.conv1.bias, use accessor.swap_tensors_dict({
      "layer1.conv1.weight": weight,
      "layer1.conv1.bias": bias,
  })
docstr_tok: ["Swap","the","attributes","specified","by","the","given","paths","to","values",".","For","example",",","to","swap","the","attributes","mod.layer1.conv1.weight","and","mod.layer1.conv1.bias",",","use","accessor.swap_tensors_dict","(","{","``","layer1.conv1.weight","''",":","weight",",","``","layer1.conv1.bias","''",":","bias",",","}",")"]
code: def swap_tensors_dict(
      self,
      named_tensors: Dict[str, torch.Tensor],
      allow_missing: bool = False,
  ) -> Tuple[Dict[str, torch.Tensor], List[str]]:
      """
      Swap the attributes specified by the given paths to values.
  
      For example, to swap the attributes mod.layer1.conv1.weight and
      mod.layer1.conv1.bias, use accessor.swap_tensors_dict({
          "layer1.conv1.weight": weight,
          "layer1.conv1.bias": bias,
      })
      """
      orig_named_tensors = {}
      missing_keys = []
      try:
          for name, tensor in named_tensors.items():
              orig_tensor = self.swap_tensor(
                  name, tensor, allow_missing=True
              )
              if orig_tensor is _MISSING:
                  missing_keys.append(name)
              orig_named_tensors[name] = orig_tensor
      except Exception:
          # Swap back if any exception occurs
          for name, orig_tensor in orig_named_tensors.items():
              self.swap_tensor(name, orig_tensor, allow_missing=True)
          raise
      if missing_keys and not allow_missing:
          # Swap back if any key is missing when allow_missing is False
          for name, orig_tensor in orig_named_tensors.items():
              self.swap_tensor(name, orig_tensor, allow_missing=True)
          raise RuntimeError(
              f"Missing key(s): {', '.join(map(repr, missing_keys))}."
          )
      return orig_named_tensors, missing_keys
  
imports: from typing import Dict, Iterable, List, Tuple
  import torch
label_desc: Use image node_id 13 for calling the NamedMemberAccessor obj's underlying member method code with example usage: obj.swap_tensors_dict(named_tensors, allow_missing) and returns: orig_named_tensors,  missing_keys