code: def share_parameters(source, target):
      """Share parameters recursively from source model to target model.
  
      For example, if you want ``dense1`` to share ``dense0``'s weights, you can do::
  
          dense0 = nn.Linear(20)
          dense1 = nn.Linear(20)
          share_parameters(dense0, dense)
  
      which equals to
          dense1.weight = dense0.weight
          dense1.bias = dense0.bias
  
      Parameters
      ----------
      source : nn.Module
      target : nn.Module
      """
  
      def _named_members(
          module, get_members_fn, prefix="", recurse=True
      ):
          r"""Helper method for yielding various names + members of modules.
  
          Unlike upstream torch implementation, this implementation returns
          members that are known under multiple names, such as shared
          parameters.
  
          """
          modules = (
              module.named_modules(prefix=prefix)
              if recurse
              else [(prefix, module)]
          )
          for module_prefix, module in modules:
              members = get_members_fn(module)
              for k, v in members:
                  if v is None:
                      continue
                  name = (
                      module_prefix + ("." if module_prefix else "") + k
                  )
                  yield name, v
  
      source_names = set(
          n
          for n, p in _named_members(
              source, lambda m: m._parameters.items()
          )
      )
      target_names = set(
          n
          for n, p in _named_members(
              target, lambda m: m._parameters.items()
          )
      )
      if not source_names == target_names:
          raise ValueError(
              "Source and target modules do not have the same set of parameters. "
              f'The following parameters are missing from target: "{source_names - target_names}"'
              f'The following parameters are missing from source: "{target_names - source_names}"'
          )
  
      for name in source_names:
          module_names = name.split(".")
          weight_name = module_names.pop()
          tmp_source, tmp_target = source, target
          for module_name in module_names:
              tmp_source = tmp_source._modules[module_name]
              tmp_target = tmp_target._modules[module_name]
          setattr(
              tmp_target, weight_name, getattr(tmp_source, weight_name)
          )
  
imports: import torch
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: share_parameters(source, target) without return types