MrYxJ / calculate-flops.pytorch

The calflops is designed to calculate FLOPs、MACs and Parameters in all various neural networks, such as Linear、 CNN、 RNN、 GCN、Transformer(Bert、LlaMA etc Large Language Model)
https://pypi.org/project/calflops/
MIT License
393 stars 14 forks source link

ImportError: cannot import name 'is_timm_available' from 'accelerate.utils' #6

Closed jiabao-wang closed 7 months ago

jiabao-wang commented 9 months ago

when I run "from calflops import calculate_flops", the error is showing below:

ImportError Traceback (most recent call last) Cell In[14], line 1 ----> 1 from calflops import calculate_flops 2 flops, macs, params = calculate_flops(model=model, 3 kwargs = inputs, 4 print_results=True) 5 print("Bert(hfl/chinese-roberta-wwm-ext) FLOPs:%s MACs:%s Params:%s \n" %(flops, macs, params))

File /opt/conda/lib/python3.10/site-packages/calflops/init.py:16 4 ''' 5 Description : 6 Version : 1.0 (...) 12 Copyright (C) 2023 mryxj. All rights reserved. 13 ''' 15 from .flops_counter import calculate_flops ---> 16 from .flops_counter_hf import calculate_flops_hf 18 from .utils import generate_transformer_input 19 from .utils import number_to_string

File /opt/conda/lib/python3.10/site-packages/calflops/flops_counter_hf.py:24 22 from .utils import macs_to_string 23 from .utils import params_to_string ---> 24 from .estimate import create_empty_model 25 from .calculate_pipline import CalFlopsPipline 28 def calculate_flops_hf(model_name, 29 empty_model=None, 30 input_shape=None, (...) 41 ignore_modules=None, 42 return_results=False):

File /opt/conda/lib/python3.10/site-packages/calflops/estimate.py:22 19 from huggingface_hub.utils import GatedRepoError, RepositoryNotFoundError 21 from accelerate import init_empty_weights ---> 22 from accelerate.utils import ( 23 # calculate_maximum_sizes, 24 # convert_bytes, 25 is_timm_available, 26 is_transformers_available, 27 ) 30 if is_transformers_available(): 31 import transformers

ImportError: cannot import name 'is_timm_available' from 'accelerate.utils' (/opt/conda/lib/python3.10/site-packages/accelerate/utils/init.py)

jiabao-wang commented 9 months ago

I have solved this problem, when I upgrade accelerate to version 0.23.0.

MrYxJ commented 9 months ago

Yeah, you can upgrade accelerate to the latest.