From 8f4ac61a12842027bb1dfa5287089b10c65bce22 Mon Sep 17 00:00:00 2001 From: David Yastremsky Date: Thu, 9 May 2024 10:35:06 -0700 Subject: [PATCH 1/7] Add tests as hook, ignore mypy cacheg --- .github/workflows/python-package.yaml | 57 +++++++++++++++++++++++++++ .gitignore | 3 ++ 2 files changed, 60 insertions(+) create mode 100644 .github/workflows/python-package.yaml diff --git a/.github/workflows/python-package.yaml b/.github/workflows/python-package.yaml new file mode 100644 index 000000000..c2d3cc287 --- /dev/null +++ b/.github/workflows/python-package.yaml @@ -0,0 +1,57 @@ +# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + pull_request: + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: ["ubuntu-22.04"] + python-version: ["3.8", "3.10"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -e . + - name: Test with unittest + run: | + pip install unittest-parallel + python3 -m unittest_parallel -v -s ./tests -t . diff --git a/.gitignore b/.gitignore index 4317f0aed..0c2e14c21 100644 --- a/.gitignore +++ b/.gitignore @@ -366,3 +366,6 @@ MigrationBackup/ # Fody - auto-generated XML schema FodyWeavers.xsd + +# Files generated by linters +.mypy_cache/ \ No newline at end of file From 66220797712c3bdce90a80ee6660fcf6bccd07d3 Mon Sep 17 00:00:00 2001 From: David Yastremsky Date: Thu, 9 May 2024 10:52:27 -0700 Subject: [PATCH 2/7] Add missing dependency, test 3.6 and 3.8 --- .github/workflows/python-package.yaml | 2 +- requirements.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yaml b/.github/workflows/python-package.yaml index c2d3cc287..c5d2e535d 100644 --- a/.github/workflows/python-package.yaml +++ b/.github/workflows/python-package.yaml @@ -39,7 +39,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-22.04"] - python-version: ["3.8", "3.10"] + python-version: ["3.6", "3.8"] steps: - uses: actions/checkout@v3 diff --git a/requirements.txt b/requirements.txt index 467956767..cc6b5ba07 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,6 +18,7 @@ docker>=4.3.1 gevent>=22.08.0 grpcio>=1.41.0 httplib2>=0.19.0 +importlib_metadata>=7.1.0 matplotlib>=3.3.4 numba>=0.51.2 pdfkit>=0.6.1 From c6813378f433ed36bd2d4ad2f71fedb6ba873ed5 Mon Sep 17 00:00:00 2001 From: David Yastremsky Date: Thu, 9 May 2024 10:57:24 -0700 Subject: [PATCH 3/7] Update supported Python versions --- .github/workflows/python-package.yaml | 2 +- setup.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-package.yaml b/.github/workflows/python-package.yaml index c5d2e535d..c2d3cc287 100644 --- a/.github/workflows/python-package.yaml +++ b/.github/workflows/python-package.yaml @@ -39,7 +39,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-22.04"] - python-version: ["3.6", "3.8"] + python-version: ["3.8", "3.10"] steps: - uses: actions/checkout@v3 diff --git a/setup.py b/setup.py index 831900f4f..0fd1e06c3 100755 --- a/setup.py +++ b/setup.py @@ -102,9 +102,10 @@ def get_tag(self): "Topic :: Utilities", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Environment :: Console", "Natural Language :: English", "Operating System :: POSIX :: Linux", From 04a552a928c2126bbba92bac18def7fe9818b56d Mon Sep 17 00:00:00 2001 From: David Yastremsky Date: Thu, 9 May 2024 11:48:12 -0700 Subject: [PATCH 4/7] Fix type hint --- tests/test_parameter_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_parameter_search.py b/tests/test_parameter_search.py index fda4c649c..bad471d01 100755 --- a/tests/test_parameter_search.py +++ b/tests/test_parameter_search.py @@ -285,7 +285,7 @@ def _create_single_model_no_constraints(self): def _create_single_model_with_constraints( self, latency_budget: str - ) -> Union[ConfigCommandProfile | ConfigCommandReport]: + ) -> Union[ConfigCommandProfile, ConfigCommandReport]: args = [ "model-analyzer", "profile", From 1f039db91e9bd6fc83b0718731750bb8717b1783 Mon Sep 17 00:00:00 2001 From: David Yastremsky Date: Thu, 9 May 2024 11:56:09 -0700 Subject: [PATCH 5/7] Skip tests that require a GPU to pass --- .github/workflows/python-package.yaml | 4 +++- tests/test_model_config.py | 4 ++++ tests/test_result_table_manager.py | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yaml b/.github/workflows/python-package.yaml index c2d3cc287..a89a883c0 100644 --- a/.github/workflows/python-package.yaml +++ b/.github/workflows/python-package.yaml @@ -39,7 +39,9 @@ jobs: fail-fast: false matrix: os: ["ubuntu-22.04"] - python-version: ["3.8", "3.10"] + python-version: ["3.8", "3.11"] + env: + SKIP_GPU_TESTS: 1 # Set this variable to skip GPU tests steps: - uses: actions/checkout@v3 diff --git a/tests/test_model_config.py b/tests/test_model_config.py index 5371107dc..19e30a559 100755 --- a/tests/test_model_config.py +++ b/tests/test_model_config.py @@ -262,6 +262,8 @@ def test_write_config_to_file_with_relative_path(self, mock_os_symlink, *args): def test_instance_group_string(self): """Test out all corner cases of instance_group_string()""" + if os.getenv("SKIP_GPU_TESTS"): + self.skipTest("Skipping this test as it requires GPU") def _test_helper(config_dict, expected_result, gpu_count=None): model_config = ModelConfig.create_from_dictionary(config_dict) @@ -318,6 +320,8 @@ def _test_helper(config_dict, expected_result, gpu_count=None): def test_instance_group_count(self): """Test out all corner cases of instance_group_count()""" + if os.getenv("SKIP_GPU_TESTS"): + self.skipTest("Skipping this test as it requires GPU") def _test_helper(config_dict, expected_result, gpu_count=None): model_config = ModelConfig.create_from_dictionary(config_dict) diff --git a/tests/test_result_table_manager.py b/tests/test_result_table_manager.py index 278ceb5ea..dd7284036 100755 --- a/tests/test_result_table_manager.py +++ b/tests/test_result_table_manager.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os import unittest from filecmp import cmp from shutil import rmtree @@ -79,6 +80,8 @@ def test_multi_model_csv_against_golden(self): Match the csvs against the golden versions in tests/common/multi-model-ckpt """ + if os.getenv("SKIP_GPU_TESTS"): + self.skipTest("Skipping this test as it requires GPU") table_manager = self._create_multi_model_result_table_manager() table_manager.create_tables() From ce1af91e22e826e9c03dd785b91387c0502914d5 Mon Sep 17 00:00:00 2001 From: David Yastremsky Date: Thu, 9 May 2024 12:01:58 -0700 Subject: [PATCH 6/7] Remove redundant comment --- .github/workflows/python-package.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yaml b/.github/workflows/python-package.yaml index a89a883c0..b61d147d8 100644 --- a/.github/workflows/python-package.yaml +++ b/.github/workflows/python-package.yaml @@ -41,7 +41,7 @@ jobs: os: ["ubuntu-22.04"] python-version: ["3.8", "3.11"] env: - SKIP_GPU_TESTS: 1 # Set this variable to skip GPU tests + SKIP_GPU_TESTS: 1 steps: - uses: actions/checkout@v3 From d6f1eceff7329a4f5ecaa6010a46b5376a9c180f Mon Sep 17 00:00:00 2001 From: David Yastremsky Date: Thu, 9 May 2024 12:03:29 -0700 Subject: [PATCH 7/7] Fix copyright, endline --- .github/workflows/python-package.yaml | 4 ++-- .gitignore | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-package.yaml b/.github/workflows/python-package.yaml index b61d147d8..2a509fb46 100644 --- a/.github/workflows/python-package.yaml +++ b/.github/workflows/python-package.yaml @@ -1,4 +1,4 @@ -# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -24,7 +24,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# This workflow will install Python dependencies and run unit tests. # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python name: Python package diff --git a/.gitignore b/.gitignore index 0c2e14c21..841e073af 100644 --- a/.gitignore +++ b/.gitignore @@ -368,4 +368,4 @@ MigrationBackup/ FodyWeavers.xsd # Files generated by linters -.mypy_cache/ \ No newline at end of file +.mypy_cache/