class_docstr: TorchModel wraps a PyTorch model as a single layer, thus the PyTorch model can be used for
  distributed inference or training.
class_docstr_tok: ["TorchModel","wraps","a","PyTorch","model","as","a","single","layer",",","thus","the","PyTorch","model","can","be","used","for","distributed","inference","or","training","."]
docstr: Convert to pytorch model
  :return: a pytorch model
docstr_tok: ["Convert","to","pytorch","model",":","return",":","a","pytorch","model"]
code: def to_pytorch(self):
      """
      Convert to pytorch model
      :return: a pytorch model
      """
      new_weight = self.get_weights()
      invalidInputError(
          len(new_weight) == 1,
          "TorchModel's weights should be one tensor",
      )
      # set weights
      m = torch.load(
          io.BytesIO(self.module_bytes), pickle_module=zoo_pickle_module
      )
      import types
  
      if isinstance(m, types.FunctionType) or isinstance(m, type):
          m = m()
      w = torch.Tensor(new_weight[0])
      torch.nn.utils.vector_to_parameters(w, trainable_param(m))
  
      # set named buffers
      new_extra_params = callZooFunc(
          self.bigdl_type, "getModuleExtraParameters", self.value
      )
      if len(new_extra_params) != 0:
          idx = 0
          for named_buffer in m.named_buffers():
              named_buffer[1].copy_(
                  torch.reshape(
                      torch.Tensor(new_extra_params[idx].to_ndarray()),
                      named_buffer[1].size(),
                  )
              )
              idx += 1
      return m
  
file_path: BigDL/python/orca/src/bigdl/orca/torch/torch_model.py
imports: import sys
  import io
  import torch
  from bigdl.dllib.nn.layer import Layer
  from bigdl.dllib.utils.common import JTensor
  from bigdl.dllib.utils.file_utils import callZooFunc
  from bigdl.orca.torch.utils import trainable_param
  from bigdl.orca.torch import zoo_pickle_module
  from importlib.util import find_spec
  from bigdl.dllib.utils.log4Error import *
  from deprecated import deprecated
label_desc: Use image node_id 4 for calling the TorchModel obj's underlying member method code with example usage: obj.to_pytorch() and returns: m