From 9aa9e4674711548b09cbecf9112df49470786874 Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Mon, 27 Nov 2023 06:14:16 +0900 Subject: [PATCH 1/5] Update setup script and license headers --- ptflops/pytorch_engine.py | 2 +- ptflops/pytorch_ops.py | 2 +- setup.py | 30 ++++++++++++++++++++++-------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ptflops/pytorch_engine.py b/ptflops/pytorch_engine.py index 0ec0114..a2e71e4 100644 --- a/ptflops/pytorch_engine.py +++ b/ptflops/pytorch_engine.py @@ -1,5 +1,5 @@ ''' -Copyright (C) 2021 Sovrasov V. - All Rights Reserved +Copyright (C) 2021-2023 Sovrasov V. - All Rights Reserved * You may use, distribute and modify this code under the * terms of the MIT license. * You should have received a copy of the MIT license with diff --git a/ptflops/pytorch_ops.py b/ptflops/pytorch_ops.py index 3801070..fe1c4c4 100644 --- a/ptflops/pytorch_ops.py +++ b/ptflops/pytorch_ops.py @@ -1,5 +1,5 @@ ''' -Copyright (C) 2021 Sovrasov V. - All Rights Reserved +Copyright (C) 2021-2023 Sovrasov V. - All Rights Reserved * You may use, distribute and modify this code under the * terms of the MIT license. * You should have received a copy of the MIT license with diff --git a/setup.py b/setup.py index a451b80..bff06b2 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,14 @@ +''' +Copyright (C) 2018-2023 Sovrasov V. - All Rights Reserved + * You may use, distribute and modify this code under the + * terms of the MIT license. + * You should have received a copy of the MIT license with + * this file. If not visit https://opensource.org/licenses/MIT +''' + from setuptools import find_packages, setup -readme = open('README.md').read() +from pathlib import Path VERSION = '0.7.1.2' @@ -8,8 +16,14 @@ 'torch', ] +SETUP_DIR = Path(__file__).resolve().parent + +TEST_BASE_EXTRAS = (SETUP_DIR / 'test_requirements.txt').read_text() +EXTRAS_REQUIRE = { + 'dev': TEST_BASE_EXTRAS, +} + setup( - # Metadata name='ptflops', version=VERSION, author='Vladislav Sovrasov', @@ -17,19 +31,19 @@ url='https://github.com/sovrasov/flops-counter.pytorch', description='Flops counter for convolutional networks in' 'pytorch framework', - long_description=readme, + long_description=(SETUP_DIR / 'README.md').read_text(), long_description_content_type='text/markdown', license='MIT', - # Package info - packages=find_packages(exclude=('*test*',)), + packages=find_packages(SETUP_DIR, exclude=('*test*',)), + package_dir={'ptflops': str(SETUP_DIR / 'ptflops')}, - # zip_safe=True, install_requires=requirements, + extras_require=EXTRAS_REQUIRE, + python_requires='>=3.7', - # Classifiers classifiers=[ - 'Programming Language :: Python :: 3', + 'MIT Software License :: Programming Language :: Python :: 3', ], ) From 95113522eb1cb3e4151aebd4b7a68310b1af10ab Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Mon, 27 Nov 2023 06:15:58 +0900 Subject: [PATCH 2/5] Update gha setup commands --- .github/workflows/main.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index cc6a5b0..e7ca569 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -37,10 +37,9 @@ jobs: run: | python -m pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - if [ -f test_requirements.txt ]; then pip install -r test_requirements.txt; fi - name: Install ptflops run: | - python setup.py develop + pip install .[dev] - name: Testing with pytest run: | python -m pytest . -s From 8d85573ffc302908459a94b7ce350899e34f8446 Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Mon, 27 Nov 2023 06:18:51 +0900 Subject: [PATCH 3/5] Fix pylint --- ptflops/flops_counter.py | 2 +- setup.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ptflops/flops_counter.py b/ptflops/flops_counter.py index fe9c0fc..a4def46 100644 --- a/ptflops/flops_counter.py +++ b/ptflops/flops_counter.py @@ -1,5 +1,5 @@ ''' -Copyright (C) 2019-2021 Sovrasov V. - All Rights Reserved +Copyright (C) 2019-2023 Sovrasov V. - All Rights Reserved * You may use, distribute and modify this code under the * terms of the MIT license. * You should have received a copy of the MIT license with diff --git a/setup.py b/setup.py index bff06b2..efd9106 100644 --- a/setup.py +++ b/setup.py @@ -6,9 +6,10 @@ * this file. If not visit https://opensource.org/licenses/MIT ''' +from pathlib import Path + from setuptools import find_packages, setup -from pathlib import Path VERSION = '0.7.1.2' From f6e4ee3a1b38c70e5a0fe9c8a8b34e6c82d508c3 Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Mon, 27 Nov 2023 06:24:35 +0900 Subject: [PATCH 4/5] Update gh actions --- .github/workflows/main.yaml | 2 +- setup.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e7ca569..74976d0 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -46,4 +46,4 @@ jobs: - name: Linting with flake8 run: | python -m flake8 . - python -m isort -rc --check-only --diff . \ No newline at end of file + python -m isort -rc --check-only --diff ./ptflops ./tests \ No newline at end of file diff --git a/setup.py b/setup.py index efd9106..8f76cc0 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,6 @@ from setuptools import find_packages, setup - VERSION = '0.7.1.2' requirements = [ From 4245bae7bf2d4f74590a037026074bd908066bfb Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Tue, 28 Nov 2023 05:59:52 +0900 Subject: [PATCH 5/5] Add type annotations to get_complexity funciton --- ptflops/flops_counter.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ptflops/flops_counter.py b/ptflops/flops_counter.py index a4def46..296ea49 100644 --- a/ptflops/flops_counter.py +++ b/ptflops/flops_counter.py @@ -7,6 +7,7 @@ ''' import sys +from typing import Any, Callable, Dict, TextIO, Tuple, Union import torch.nn as nn @@ -14,14 +15,17 @@ from .utils import flops_to_string, params_to_string -def get_model_complexity_info(model, input_res, - print_per_layer_stat=True, - as_strings=True, - input_constructor=None, ost=sys.stdout, - verbose=False, ignore_modules=[], - custom_modules_hooks={}, backend='pytorch', - flops_units=None, param_units=None, - output_precision=2): +def get_model_complexity_info(model: nn.Module, input_res: Tuple[int, ...], + print_per_layer_stat: bool = True, + as_strings: bool = True, + input_constructor: Union[Callable, None] = None, + ost: TextIO = sys.stdout, + verbose: bool = False, ignore_modules=[], + custom_modules_hooks: Dict[nn.Module, Any] = {}, + backend: str = 'pytorch', + flops_units: Union[str, None] = None, + param_units: Union[str, None] = None, + output_precision: int = 2): assert type(input_res) is tuple assert len(input_res) >= 1 assert isinstance(model, nn.Module)