Skip to content

TypeError for Pytorch Model  #94

@hongshanli23

Description

@hongshanli23

Hello, I am trying to use hiddenlayer to draw a pytorch model, I got some error coming out of onnx

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/ubuntu/mstar/scripts/rlfh/visualization.ipynb Cell 4' in <cell line: 13>()
      [6](vscode-notebook-cell://ssh-remote%2Bmistd/home/ubuntu/mstar/scripts/rlfh/visualization.ipynb#ch0000003vscode-remote?line=5) #model = torchvision.models.vgg16()
      [8](vscode-notebook-cell://ssh-remote%2Bmistd/home/ubuntu/mstar/scripts/rlfh/visualization.ipynb#ch0000003vscode-remote?line=7) model = torch.nn.Sequential(
      [9](vscode-notebook-cell://ssh-remote%2Bmistd/home/ubuntu/mstar/scripts/rlfh/visualization.ipynb#ch0000003vscode-remote?line=8)     nn.Linear(10, 10),
     [10](vscode-notebook-cell://ssh-remote%2Bmistd/home/ubuntu/mstar/scripts/rlfh/visualization.ipynb#ch0000003vscode-remote?line=9)     nn.Linear(10, 2)
     [11](vscode-notebook-cell://ssh-remote%2Bmistd/home/ubuntu/mstar/scripts/rlfh/visualization.ipynb#ch0000003vscode-remote?line=10) )
---> [13](vscode-notebook-cell://ssh-remote%2Bmistd/home/ubuntu/mstar/scripts/rlfh/visualization.ipynb#ch0000003vscode-remote?line=12) hl.build_graph(model, torch.zeros([1, 10]))

File ~/py38/lib/python3.8/site-packages/hiddenlayer/graph.py:143, in build_graph(model, args, input_names, transforms, framework_transforms)
    [141](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/graph.py?line=140)     from .pytorch_builder import import_graph, FRAMEWORK_TRANSFORMS
    [142](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/graph.py?line=141)     assert args is not None, "Argument args must be provided for Pytorch models."
--> [143](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/graph.py?line=142)     import_graph(g, model, args)
    [144](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/graph.py?line=143) elif framework == "tensorflow":
    [145](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/graph.py?line=144)     from .tf_builder import import_graph, FRAMEWORK_TRANSFORMS

File ~/py38/lib/python3.8/site-packages/hiddenlayer/pytorch_builder.py:71, in import_graph(hl_graph, model, args, input_names, verbose)
     [66](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/pytorch_builder.py?line=65) def import_graph(hl_graph, model, args, input_names=None, verbose=False):
     [67](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/pytorch_builder.py?line=66)     # TODO: add input names to graph
     [68](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/pytorch_builder.py?line=67) 
     [69](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/pytorch_builder.py?line=68)     # Run the Pytorch graph to get a trace and generate a graph from it
     [70](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/pytorch_builder.py?line=69)     trace, out = torch.jit._get_trace_graph(model, args)
---> [71](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/pytorch_builder.py?line=70)     torch_graph = torch.onnx._optimize_trace(trace, torch.onnx.OperatorExportTypes.ONNX)
     [73](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/pytorch_builder.py?line=72)     # Dump list of nodes (DEBUG only)
     [74](file:///home/ubuntu/py38/lib/python3.8/site-packages/hiddenlayer/pytorch_builder.py?line=73)     if verbose:

File ~/py38/lib/python3.8/site-packages/torch/onnx/__init__.py:394, in _optimize_trace(graph, operator_export_type)
    [391](file:///home/ubuntu/py38/lib/python3.8/site-packages/torch/onnx/__init__.py?line=390) def _optimize_trace(graph, operator_export_type):
    [392](file:///home/ubuntu/py38/lib/python3.8/site-packages/torch/onnx/__init__.py?line=391)     from torch.onnx import utils
--> [394](file:///home/ubuntu/py38/lib/python3.8/site-packages/torch/onnx/__init__.py?line=393)     return utils._optimize_graph(graph, operator_export_type)

File ~/py38/lib/python3.8/site-packages/torch/onnx/utils.py:276, in _optimize_graph(graph, operator_export_type, _disable_torch_constant_prop, fixed_batch_size, params_dict, dynamic_axes, input_names, module)
    [274](file:///home/ubuntu/py38/lib/python3.8/site-packages/torch/onnx/utils.py?line=273) symbolic_helper._quantized_ops.clear()
    [275](file:///home/ubuntu/py38/lib/python3.8/site-packages/torch/onnx/utils.py?line=274) # Unpack quantized weights for conv and linear ops and insert into graph.
--> [276](file:///home/ubuntu/py38/lib/python3.8/site-packages/torch/onnx/utils.py?line=275) _C._jit_pass_onnx_unpack_quantized_weights(
    [277](file:///home/ubuntu/py38/lib/python3.8/site-packages/torch/onnx/utils.py?line=276)     graph, params_dict, symbolic_helper.is_caffe2_aten_fallback()
    [278](file:///home/ubuntu/py38/lib/python3.8/site-packages/torch/onnx/utils.py?line=277) )
    [279](file:///home/ubuntu/py38/lib/python3.8/site-packages/torch/onnx/utils.py?line=278) if symbolic_helper.is_caffe2_aten_fallback():
    [280](file:///home/ubuntu/py38/lib/python3.8/site-packages/torch/onnx/utils.py?line=279)     # Insert permutes before and after each conv op to ensure correct order.
    [281](file:///home/ubuntu/py38/lib/python3.8/site-packages/torch/onnx/utils.py?line=280)     _C._jit_pass_onnx_quantization_insert_permutes(graph, params_dict)

TypeError: _jit_pass_onnx_unpack_quantized_weights(): incompatible function arguments. The following argument types are supported:
    1. (arg0: torch::jit::Graph, arg1: Dict[str, IValue], arg2: bool) -> Dict[str, IValue]

Invoked with: graph(%0 : Float(1, 10, strides=[10, 1], requires_grad=0, device=cpu),
      %1 : Float(10, 10, strides=[10, 1], requires_grad=1, device=cpu),
      %2 : Float(10, strides=[1], requires_grad=1, device=cpu),
      %3 : Float(2, 10, strides=[10, 1], requires_grad=1, device=cpu),
      %4 : Float(2, strides=[1], requires_grad=1, device=cpu)):
  %15 : Float(1, 10, strides=[10, 1], requires_grad=1, device=cpu) = aten::linear(%0, %1, %2) # /home/ubuntu/py38/lib/python3.8/site-packages/torch/nn/modules/linear.py:114:0
  %16 : Float(1, 2, strides=[2, 1], requires_grad=1, device=cpu) = aten::linear(%15, %3, %4) # /home/ubuntu/py38/lib/python3.8/site-packages/torch/nn/modules/linear.py:114:0
  return (%16)
, None, False

runtime:

ubuntu 20.04, python 3.8, torch 1.13.0 (experimental), hiddenlayer 0.3

script to reproduce the error:

import hiddenlayer as hl
import torch
import torch.nn as nn
import torchvision.models

#model = torchvision.models.vgg16()

model = torch.nn.Sequential(
    nn.Linear(10, 10),
    nn.Linear(10, 2)
)

hl.build_graph(model, torch.zeros([1, 10]))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions