Lyken17 / pytorch-OpCounter

Count the MACs / FLOPs of your PyTorch model.
MIT License
4.9k stars 528 forks source link

Add onnx to avoid import error #175

Closed nzw0301 closed 2 years ago

nzw0301 commented 2 years ago

When I installed thop via pip, I could not import thop successfully as follows:

In [1]: import thop
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 import thop

File /opt/homebrew/Caskroom/miniconda/base/envs/optuna/lib/python3.9/site-packages/thop/__init__.py:3, in <module>
      1 from .utils import clever_format
      2 from .profile import profile, profile_origin
----> 3 from .onnx_profile import OnnxProfile
      4 import torch
      6 default_dtype = torch.float64

File /opt/homebrew/Caskroom/miniconda/base/envs/optuna/lib/python3.9/site-packages/thop/onnx_profile.py:3, in <module>
      1 import torch
      2 import torch.nn
----> 3 import onnx
      4 from onnx import numpy_helper
      5 import numpy as np

ModuleNotFoundError: No module named 'onnx'

Depedencies:

Lyken17 commented 2 years ago

Unfortunately, ONNX does not support python 3.10 yet and including this in dependency will lead to build failure on some enviroments.

Maybe a better way to move import onnx to deeper location so users do not use onnx profiler will not trigger related issues.

Lyken17 commented 2 years ago

ONNX import has been moved to a deeper location.