Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotImplementedError: this Node If-If_xxxx has no value_infer #66

Closed
Thaslim opened this issue Jan 30, 2024 · 4 comments
Closed

NotImplementedError: this Node If-If_xxxx has no value_infer #66

Thaslim opened this issue Jan 30, 2024 · 4 comments

Comments

@Thaslim
Copy link

Thaslim commented Jan 30, 2024

Describe the bug
Hi , I have exported the SSD300_VGG16 model to ONNX. When I try to profile using onnx_tool, I get NotImplementedError: this Node If-If_3160 has no value_infer

To Reproduce
Steps to reproduce the behavior:

import torch
import torch.onnx
import torchvision
import onnx_tool

dummy_input = torch.randn(1, 3, 300, 300)
model = torchvision.models.detection.ssd300_vgg16(weights=SSD300_VGG16_Weights.DEFAULT)
model.eval()
torch.onnx.export(model, dummy_input, "ssd300_vgg16.onnx",opset_version=11)
m = onnx_tool.Model("ssd300_vgg16.onnx")
m.graph.shape_infer()
m.graph.profile()
m.graph.print_node_map("ssd300_vgg16.csv")  

Expected behavior
csv file with profiled results

Error

/home/user/.local/lib/python3.6/site-packages/onnx_tool/node.py:2445: UserWarning: node If is not registed for profiling, return 0 Macs and 0 params as default. Use NODEPROFILER_REGISTRY to register your profiler for this node.
  warnings.warn(f'node {n.op_type} is not registed for profiling, return 0 Macs and 0 params as default. '
ERROR:root:Traceback (most recent call last):
  File "scripts/onnx_model_profile.py", line 27, in profile_model
    m.graph.shape_infer()  # update tensor shapes with new input tensor
  File "/home/user/.local/lib/python3.6/site-packages/onnx_tool/graph.py", line 844, in shape_infer
    node.shape_infer(itensors, otensors)
  File "/home/user/.local/lib/python3.6/site-packages/onnx_tool/node.py", line 155, in shape_infer
    self.value_infer(intensors, outtensors)
  File "/home/user/.local/lib/python3.6/site-packages/onnx_tool/node.py", line 158, in value_infer
    raise NotImplementedError(f'this Node {self.op_type}-{self.name} has no value_infer')
NotImplementedError: this Node If-If_3160 has no value_infer

I am profiling to get the list of OPs in this model. Please share if there are any workarounds to get past this error. Thank you

@ThanatosShinji
Copy link
Owner

ThanatosShinji commented Feb 2, 2024 via email

@ThanatosShinji
Copy link
Owner

ThanatosShinji commented Feb 22, 2024

@Thaslim One workaround for this. batched_nms creates this Op which I think it's a bad design of ONNX export.
Here are the python codes of torchvision\ops\boxes.py L79-L90:

def _batched_nms_coordinate_trick(
....
    # if boxes.numel() == 0:
    #     return torch.empty((0,), dtype=torch.int64, device=boxes.device)

You can try comment the if condition as I did in your local code. This will remove If in your model. I can get the correct MACs after this change.

Total _ 34,985,765,664 100% 561,420,728 100% 35,637,878 100% _ _

@ThanatosShinji
Copy link
Owner

@Thaslim I've updated the example code here

@Thaslim
Copy link
Author

Thaslim commented Mar 8, 2024

@ThanatosShinji Thank you, Appreciate your response.

@Thaslim Thaslim closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants