class_docstr: The base class for model search space based on PyTorch.
  The out-est module should inherit this class.
  
  Model space is written as PyTorch module for the convenience of writing code.
  It's not a real PyTorch model, and shouldn't be used as one for most cases.
  Most likely, the forward of :class:`ModelSpace` is a dry run of an arbitrary model in the model space.
  But since there is no guarantee on which model will be chosen, and the behavior is not well tested,
  it's only used for sanity check and tracing the space, and its semantics are not well-defined.
  
  Similarly for ``state_dict`` and ``load_state_dict``.
  Users should bear in mind that :class:`ModelSpace` is NOT a one-shot supernet,
  directly exporting its weights are unreliable and prone to error.
  Use :ref:`one-shot strategies <one-shot-nas>` to mutate the model space into a supernet for such needs.
  
  Mutables in model space **must all be labeled manually**, unless a label prefix is provided.
  Every model space can have a label prefix, which is used to provide a stable automatic label generation.
  For example, if the label prefix is ``model``, all the mutables initialized in a subclass of ModelSpace
  (in ``__init__`` function of itself and submodules, to be specific),
  will be automatically labeled with a prefix ``model/``.
  The label prefix can be manually specified upon definition of the class::
  
      class MyModelSpace(ModelSpace, label_prefix='backbone'):
          def __init__(self):
              super().__init__()
  
              self.choice = self.add_mutable(nni.choice('depth', [2, 3, 4]))
              print(self.choice.label)  # backbone/choice
  
  Notes
  -----
  The ``__init__`` implementation of :class:`ModelSpace` is in :func:`model_space_init_wrapper`.
class_docstr_tok: ["The","base","class","for","model","search","space","based","on","PyTorch",".","The","out-est","module","should","inherit","this","class",".","Model","space","is","written","as","PyTorch","module","for","the","convenience","of","writing","code",".","It","'s","not","a","real","PyTorch","model",",","and","should","n't","be","used","as","one","for","most","cases",".","Most","likely",",","the","forward","of",":","class",":","`","ModelSpace","`","is","a","dry","run","of","an","arbitrary","model","in","the","model","space",".","But","since","there","is","no","guarantee","on","which","model","will","be","chosen",",","and","the","behavior","is","not","well","tested",",","it","'s","only","used","for","sanity","check","and","tracing","the","space",",","and","its","semantics","are","not","well-defined",".","Similarly","for","``","state_dict","``","and","``","load_state_dict","``",".","Users","should","bear","in","mind","that",":","class",":","`","ModelSpace","`","is","NOT","a","one-shot","supernet",",","directly","exporting","its","weights","are","unreliable","and","prone","to","error",".","Use",":","ref",":","`","one-shot","strategies","<","one-shot-nas",">","`","to","mutate","the","model","space","into","a","supernet","for","such","needs",".","Mutables","in","model","space","*","*","must","all","be","labeled","manually","*","*",",","unless","a","label","prefix","is","provided",".","Every","model","space","can","have","a","label","prefix",",","which","is","used","to","provide","a","stable","automatic","label","generation",".","For","example",",","if","the","label","prefix","is","``","model","``",",","all","the","mutables","initialized","in","a","subclass","of","ModelSpace","(","in","``","__init__","``","function","of","itself","and","submodules",",","to","be","specific",")",",","will","be","automatically","labeled","with","a","prefix","``","model\/","``",".","The","label","prefix","can","be","manually","specified","upon","definition","of","the","class",":",":","class","MyModelSpace","(","ModelSpace",",","label_prefix='backbone","'",")",":","def","__init__","(","self",")",":","super","(",")",".__init__","(",")","self.choice","=","self.add_mutable","(","nni.choice","(","'depth","'",",","[","2",",","3",",","4","]",")",")","print","(","self.choice.label",")","#","backbone\/choice","Notes","--","--","-","The","``","__init__","``","implementation","of",":","class",":","`","ModelSpace","`","is","in",":","func",":","`","model_space_init_wrapper","`","."]
code: def __init_subclass__(
      cls,
      disable_init_wrapper: bool = False,
      label_prefix: Optional[str] = None,
      **kwargs,
  ) -> None:
      # The init wrapper can be turned off in tricky cases.
      if not disable_init_wrapper:
          cls._init_wrapped = cls.__init__
          cls.__init__ = model_space_init_wrapper(cls.__init__)
  
      cls._label_prefix = label_prefix
  
imports: import copy
  import itertools
  import inspect
  import logging
  from typing import Any, Callable, Type, Iterable, Dict, Tuple, List, Optional, TypeVar
  import torch
  from torch import nn
  from nni.mutable import Mutable, LabeledMutable, Sample, SampleValidationError, ensure_frozen, frozen_context, label_scope, frozen
  from nni.nas.space import BaseModelSpace, current_model, model_context
  from nni.common.serializer import SerializableObject, _formulate_arguments, _copy_class_wrapper_attributes
label_desc: Use image node_id 1 for calling the ModelSpace obj's underlying member method code with example usage: obj.__init_subclass__(cls, disable_init_wrapper, label_prefix) without return types