code: def test_shared(
      space_format: Type[ExecutableModelSpace], nn: ModuleType
  ):
      class Net(ModelSpace, label_prefix="model"):
          def __init__(self, shared=True):
              super().__init__()
              labels = ["x", "x"] if shared else [None, None]
              self.module1 = LayerChoice(
                  [
                      MutableConv2d(3, 3, kernel_size=1),
                      MutableConv2d(3, 5, kernel_size=1),
                  ],
                  label=labels[0],
              )
              self.module2 = LayerChoice(
                  [
                      MutableConv2d(3, 3, kernel_size=1),
                      MutableConv2d(3, 5, kernel_size=1),
                  ],
                  label=labels[1],
              )
  
          def forward(self, x):
              return self.module1(x) + self.module2(x)
  
      model = space_format.from_model(Net())
      assert len(model.simplify()) == 1
      # sanity check
      assert (
          model.random()
          .executable_model()(torch.randn(1, 3, 3, 3))
          .size(0)
          == 1
      )
  
      model = space_format.from_model(Net(shared=False))
      assert len(model.simplify()) == 2
      # repeat test. Expectation: sometimes succeeds, sometimes fails.
      failed_count = 0
      for _ in range(30):
          try:
              model.random().executable_model()(torch.randn(1, 3, 3, 3))
          except RuntimeError:
              failed_count += 1
      assert 0 < failed_count < 30
  
imports: import copy
  import random
  from types import ModuleType
  from typing import Type
  import pytest
  import nni
  import nni.nas.nn.pytorch.layers
  import nni.nas.evaluator.pytorch.lightning
  import torch
  import torch.nn.functional
  from nni.mutable import Categorical, ensure_frozen, label_scope, SampleValidationError
  from nni.nas.evaluator import FunctionalEvaluator
  from nni.nas.space import RawFormatModelSpace, SimplifiedModelSpace, ExecutableModelSpace, GraphModelSpace, model_context
  from nni.nas.space.pytorch import PytorchGraphModelSpace
  from nni.nas.nn.pytorch import ParametrizedModule, MutableModule, ModelSpace, LayerChoice, InputChoice, Cell, ChosenInputs, MutableConv2d, MutableLinear
label_desc: Use image node_id 17 for calling a global function with example usage: test_shared(space_format, nn) and returns: unknown