code: def test_set_shared_parameters():
      model = ParameterSharingModule()
      set_shared_parameters(
          model, [["layer_1.weight", "layer_3.weight"]]
      )
  
      assert torch.all(
          torch.eq(model.layer_1.weight, model.layer_3.weight)
      )
  
      class SubModule(nn.Module):
          def __init__(self, layer):
              super().__init__()
              self.layer = layer
  
          def forward(self, x):
              return self.layer(x)
  
      class NestedModule(BoringModel):
          def __init__(self):
              super().__init__()
              self.layer = nn.Linear(32, 10, bias=False)
              self.net_a = SubModule(self.layer)
              self.layer_2 = nn.Linear(10, 32, bias=False)
              self.net_b = SubModule(self.layer)
  
          def forward(self, x):
              x = self.net_a(x)
              x = self.layer_2(x)
              x = self.net_b(x)
              return x
  
      model = NestedModule()
      set_shared_parameters(
          model,
          [
              [
                  "layer.weight",
                  "net_a.layer.weight",
                  "net_b.layer.weight",
              ]
          ],
      )
  
      assert torch.all(
          torch.eq(model.net_a.layer.weight, model.net_b.layer.weight)
      )
  
file_path: pytorch-lightning/tests/tests_pytorch/utilities/test_parameter_tying.py
imports: import pytest
  import torch
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.utilities import find_shared_parameters, set_shared_parameters
  from torch import nn
label_desc: Use image node_id 2 for calling a global function with example usage: test_set_shared_parameters() and returns: self, x