class_docstr: :class:`~nni.nas.space.GraphModelSpace` specialized for PyTorch.
  It converts a PyTorch model into a graph, and provides a method to convert the graph back.
  
  Warning
  -------
  As of now, :class:`PytorchGraphModelSpace` is known to be problematic, and NOT recommended to use unless necessary.
  
  Firstly, the graph converter will put users' models through :meth:`torch.jit.script`,
  which will cause some ad-hoc models to fail.
  The traced model will be converted into our graph representation,
  which has quite limited supported for control flows, loops, etc.
  
  Other than unsupported types of models,
  the graph converter will also induce some unexpected behaviors due to the implementation changes.
  For example candidate names of :class:`~nni.nas.nn.pytorch.LayerChoice` will be prefixed,
  so that ``freeze()`` might not work as expected.
docstr: Create a GraphModelSpace instance based on a model and evaluator.
  Model-to-IR conversion happens here.
docstr_tok: ["Create","a","GraphModelSpace","instance","based","on","a","model","and","evaluator",".","Model-to-IR","conversion","happens","here","."]
code: def from_model(
      cls,
      model_space: ModelSpace,
      evaluator: Evaluator | None = None,
      dummy_input: tuple[int, ...]
      | tuple[torch.Tensor, ...]
      | list[int]
      | None = None,
  ) -> GraphModelSpace:
      """Create a GraphModelSpace instance based on a model and evaluator.
      Model-to-IR conversion happens here.
      """
      if isinstance(dummy_input, list):
          dummy_input = tuple(dummy_input)
  
      try:
          script_module = torch.jit.script(model_space)
      except:
          _logger.error(
              "Your base model cannot be parsed by torch.jit.script, please fix the following error:"
          )
          raise
      if dummy_input is not None:
          if isinstance(dummy_input, tuple) and all(
              isinstance(i, int) for i in dummy_input
          ):
              dummy_input = torch.randn(*dummy_input)  # type: ignore
          converter = GraphConverterWithShape()
          base_model_ir = cls.convert_to_graph(
              script_module,
              model_space,
              converter,
              dummy_input=dummy_input,
          )
      else:
          base_model_ir = cls.convert_to_graph(
              script_module, model_space
          )
  
      mutator_generated = len(base_model_ir.mutators) > 0
  
      if hasattr(model_space, "mutables"):
          for mutable in model_space.mutables:
              if isinstance(mutable, Mutator) and mutator_generated:
                  base_model_ir.mutators.append(mutable)
              elif not isinstance(mutable, Mutator):
                  _logger.warning(
                      f"Mutable is not a mutator. Will be ignored: {mutable}"
                  )
  
      base_model_ir.evaluator = evaluator
  
      mutators = process_inline_mutation(base_model_ir)
      if len(base_model_ir.mutators) > 0 and mutators:
          _logger.warning(
              "Some mutators have been generated automatically. "
              "We do not recommend a mixed usage of generated mutator and manually defined mutator, "
              "because sometimes it induces unexpected side effects."
          )
      base_model_ir.mutators.extend(mutators)
  
      return base_model_ir
  
file_path: nni/nni/nas/space/pytorch/graph.py
imports: from __future__ import annotations
  import logging
  from typing import Any, TYPE_CHECKING
  import torch
  from nni.nas.evaluator import Evaluator
  from nni.nas.space import GraphModelSpace, Mutator
  from nni.nas.nn.pytorch.repeat import repeat_jit_forward_patch
  from .codegen import model_to_pytorch_script
  from .converter import GraphConverter, GraphConverterWithShape
  from .mutator import process_inline_mutation
label_desc: Use image node_id 1 for calling the PytorchGraphModelSpace obj's underlying member method code with example usage: obj.from_model(cls, model_space, evaluator, dummy_input) and returns: base_model_ir