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: Convert module to our graph ir, i.e., build a :class:`GraphModelSpace` type.
  
  Parameters
  ----------
  script_module : torch.jit.RecursiveScriptModule
      the script module obtained with torch.jit.script
  module : nn.Module
      the targeted module instance
  converter : `TorchConverter`
      default `GraphConverter` is used
  kwargs:
      will be passed to `converter.convert_module()`
  
  Returns
  -------
  GraphModelSpace
      the constructed IR model
docstr_tok: ["Convert","module","to","our","graph","ir",",","i.e.",",","build","a",":","class",":","`","GraphModelSpace","`","type",".","Parameters","--","--","--","--","--","script_module",":","torch.jit.RecursiveScriptModule","the","script","module","obtained","with","torch.jit.script","module",":","nn.Module","the","targeted","module","instance","converter",":","`","TorchConverter","`","default","`","GraphConverter","`","is","used","kwargs",":","will","be","passed","to","`","converter.convert_module","(",")","`","Returns","--","--","--","-","GraphModelSpace","the","constructed","IR","model"]
code: def convert_to_graph(
      cls, script_module, module, converter=None, **kwargs
  ):
      """
      Convert module to our graph ir, i.e., build a :class:`GraphModelSpace` type.
  
      Parameters
      ----------
      script_module : torch.jit.RecursiveScriptModule
          the script module obtained with torch.jit.script
      module : nn.Module
          the targeted module instance
      converter : `TorchConverter`
          default `GraphConverter` is used
      kwargs:
          will be passed to `converter.convert_module()`
  
      Returns
      -------
      GraphModelSpace
          the constructed IR model
      """
      model = cls(_internal=True)
      module_name = "_model"
      if converter is None:
          converter = GraphConverter()
      converter.convert_module(
          script_module, module, module_name, model, **kwargs
      )
      return model
  
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 2 for calling the PytorchGraphModelSpace obj's underlying member method code with example usage: obj.convert_to_graph(cls, script_module, module, converter) and returns: model