code: def _unique_state_dict(module, keep_vars=False):
      # since Parameter.detach() always creates a new torch.Tensor instance,
      # id(v) doesn't work with it. So we always get the Parameter or Buffer
      # as values, and deduplicate the params using Parameters and Buffers
      state_dict = module.state_dict(keep_vars=True)
      filtered_dict = type(state_dict)()
      seen_ids: Set[int] = set()
      for k, v in state_dict.items():
          if id(v) in seen_ids:
              continue
          seen_ids.add(id(v))
          if keep_vars:
              filtered_dict[k] = v
          else:
              filtered_dict[k] = v.detach()
      return filtered_dict
  
imports: import contextlib
  import copy
  import functools
  import inspect
  import os
  import re
  import warnings
  from typing import Any, Callable, Dict, List, Optional, Set, TypeVar
  from typing_extensions import ParamSpec
  import torch
  from torch._jit_internal import _qualified_name, get_callable_argument_names, is_scripting
  from torch.autograd import function
  from torch.jit._script import _CachedForward, script, ScriptModule
  from torch.jit._state import _enabled, _python_cu
  from torch.nn import Module
  from torch.testing._comparison import default_tolerances
label_desc: Use image node_id 2 for calling a global function with example usage: _unique_state_dict(module, keep_vars) and returns: filtered_dict