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: Create a TorchModel directly from PyTorch model, e.g. model in torchvision.models.
  :param model: a PyTorch model, or a function to create PyTorch model
docstr_tok: ["Create","a","TorchModel","directly","from","PyTorch","model",",","e.g",".","model","in","torchvision.models",".",":","param","model",":","a","PyTorch","model",",","or","a","function","to","create","PyTorch","model"]
code: def from_pytorch(model):
      """
      Create a TorchModel directly from PyTorch model, e.g. model in torchvision.models.
      :param model: a PyTorch model, or a function to create PyTorch model
      """
      weights = []
      import types
  
      if isinstance(model, types.FunctionType) or isinstance(
          model, type
      ):
          for param in trainable_param(model()):
              weights.append(param.view(-1))
      else:
          for param in trainable_param(model):
              weights.append(param.view(-1))
      flatten_weight = torch.nn.utils.parameters_to_vector(
          weights
      ).data.numpy()
      bys = io.BytesIO()
      torch.save(model, bys, pickle_module=zoo_pickle_module)
      weights = JTensor.from_ndarray(flatten_weight)
      jvalue = callZooFunc(
          "float", "createTorchModel", bys.getvalue(), weights
      )
      net = TorchModel(jvalue, bys.getvalue())
      return net
  
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 3 for calling the TorchModel obj's underlying member method code with example usage: obj.from_pytorch(model) and returns: net