Skip to content

Commit cd456dd

Browse files
authored
Run CPU-only unit tests automatically for pull requests (#873)
This pull request adds an automation to automatically run unit tests for new pull requests. It checks them against Python 3.8 and 3.11. I updated the supported Python versions to be aligned with those supported in PyTriton, Triton CLI, and GenAI-Perf, especially since Ubuntu 22.04 only supports 3.9+. The automation uses unittest-parallel to speed up the running of unit tests. I also added the mypy cache to gitignore to avoid accidentally committing those files. You can see the results in the new jobs that are running for this PR.
1 parent 0f3520f commit cd456dd

File tree

7 files changed

+74
-3
lines changed

7 files changed

+74
-3
lines changed

.github/workflows/python-package.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions
5+
# are met:
6+
# * Redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer.
8+
# * Redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution.
11+
# * Neither the name of NVIDIA CORPORATION nor the names of its
12+
# contributors may be used to endorse or promote products derived
13+
# from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
16+
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
# This workflow will install Python dependencies and run unit tests.
28+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
29+
30+
name: Python package
31+
32+
on:
33+
pull_request:
34+
35+
jobs:
36+
build:
37+
runs-on: ${{ matrix.os }}
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
os: ["ubuntu-22.04"]
42+
python-version: ["3.8", "3.11"]
43+
env:
44+
SKIP_GPU_TESTS: 1
45+
46+
steps:
47+
- uses: actions/checkout@v3
48+
- name: Set up Python ${{ matrix.python-version }}
49+
uses: actions/setup-python@v3
50+
with:
51+
python-version: ${{ matrix.python-version }}
52+
- name: Install dependencies
53+
run: |
54+
python -m pip install --upgrade pip
55+
python -m pip install -e .
56+
- name: Test with unittest
57+
run: |
58+
pip install unittest-parallel
59+
python3 -m unittest_parallel -v -s ./tests -t .

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,6 @@ MigrationBackup/
366366

367367
# Fody - auto-generated XML schema
368368
FodyWeavers.xsd
369+
370+
# Files generated by linters
371+
.mypy_cache/

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ docker>=4.3.1
1818
gevent>=22.08.0
1919
grpcio>=1.41.0
2020
httplib2>=0.19.0
21+
importlib_metadata>=7.1.0
2122
matplotlib>=3.3.4
2223
numba>=0.51.2
2324
pdfkit>=0.6.1

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ def get_tag(self):
102102
"Topic :: Utilities",
103103
"License :: OSI Approved :: BSD License",
104104
"Programming Language :: Python :: 3",
105-
"Programming Language :: Python :: 3.6",
106-
"Programming Language :: Python :: 3.7",
107105
"Programming Language :: Python :: 3.8",
106+
"Programming Language :: Python :: 3.9",
107+
"Programming Language :: Python :: 3.10",
108+
"Programming Language :: Python :: 3.11",
108109
"Environment :: Console",
109110
"Natural Language :: English",
110111
"Operating System :: POSIX :: Linux",

tests/test_model_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ def test_write_config_to_file_with_relative_path(self, mock_os_symlink, *args):
262262

263263
def test_instance_group_string(self):
264264
"""Test out all corner cases of instance_group_string()"""
265+
if os.getenv("SKIP_GPU_TESTS"):
266+
self.skipTest("Skipping this test as it requires GPU")
265267

266268
def _test_helper(config_dict, expected_result, gpu_count=None):
267269
model_config = ModelConfig.create_from_dictionary(config_dict)
@@ -318,6 +320,8 @@ def _test_helper(config_dict, expected_result, gpu_count=None):
318320

319321
def test_instance_group_count(self):
320322
"""Test out all corner cases of instance_group_count()"""
323+
if os.getenv("SKIP_GPU_TESTS"):
324+
self.skipTest("Skipping this test as it requires GPU")
321325

322326
def _test_helper(config_dict, expected_result, gpu_count=None):
323327
model_config = ModelConfig.create_from_dictionary(config_dict)

tests/test_parameter_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def _create_single_model_no_constraints(self):
285285

286286
def _create_single_model_with_constraints(
287287
self, latency_budget: str
288-
) -> Union[ConfigCommandProfile | ConfigCommandReport]:
288+
) -> Union[ConfigCommandProfile, ConfigCommandReport]:
289289
args = [
290290
"model-analyzer",
291291
"profile",

tests/test_result_table_manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import os
1718
import unittest
1819
from filecmp import cmp
1920
from shutil import rmtree
@@ -79,6 +80,8 @@ def test_multi_model_csv_against_golden(self):
7980
Match the csvs against the golden versions in
8081
tests/common/multi-model-ckpt
8182
"""
83+
if os.getenv("SKIP_GPU_TESTS"):
84+
self.skipTest("Skipping this test as it requires GPU")
8285
table_manager = self._create_multi_model_result_table_manager()
8386

8487
table_manager.create_tables()

0 commit comments

Comments
 (0)