From 1acc89b4db7119544e49128b133dd2363c46dda5 Mon Sep 17 00:00:00 2001 From: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com> Date: Fri, 8 Aug 2025 12:02:18 +0530 Subject: [PATCH] Fix hadamard and FP4 gpu tests Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com> --- .github/workflows/gpu_tests.yml | 19 ++++++------- .../workflows/multi_version_unit_tests.yml | 10 +++---- .github/workflows/partial_unit_tests.yml | 6 ++--- .github/workflows/unit_tests.yml | 27 +++++++++++++------ README.md | 1 + pyproject.toml | 7 +++-- tests/gpu/torch/quantization/test_hadamard.py | 4 +-- .../quantization/test_tensor_quant_cuda.py | 2 +- tox.ini | 2 +- 9 files changed, 42 insertions(+), 36 deletions(-) diff --git a/.github/workflows/gpu_tests.yml b/.github/workflows/gpu_tests.yml index f91c29be..89c3d692 100644 --- a/.github/workflows/gpu_tests.yml +++ b/.github/workflows/gpu_tests.yml @@ -3,12 +3,13 @@ name: GPU tests on: push: branches: ["pull-request/[0-9]+"] - paths: - - ".github/workflows/gpu_tests.yml" - - "modelopt/**" - - "tests/**" - - "setup.py" - - "tox.ini" + # TODO: paths cannot be used since push happens to copied PR and only latest commit to PR is used + # paths: + # - ".github/workflows/gpu_tests.yml" + # - "modelopt/**" + # - "tests/gpu/**" + # - "setup.py" + # - "tox.ini" # Cancel previous runs if new commit is pushed to the same PR concurrency: @@ -28,7 +29,7 @@ jobs: PIP_CONSTRAINT: "" # Disable pip constraint for upgrading packages steps: - uses: actions/checkout@v4 - - name: Install dependencies - run: pip install tox-current-env + - name: Setup proxy cache + uses: nv-gha-runners/setup-proxy-cache@main - name: Run gpu tests - run: tox -e py312-cuda12-gpu --current-env + run: pip install tox-current-env && tox -e py312-cuda12-gpu --current-env diff --git a/.github/workflows/multi_version_unit_tests.yml b/.github/workflows/multi_version_unit_tests.yml index 2e43bfa2..bb2bfa39 100644 --- a/.github/workflows/multi_version_unit_tests.yml +++ b/.github/workflows/multi_version_unit_tests.yml @@ -7,7 +7,7 @@ on: paths: - ".github/workflows/multi_version_unit_tests.yml" - "modelopt/**" - - "tests/**" + - "tests/unit/**" - "setup.py" - "tox.ini" @@ -28,10 +28,8 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.${{ matrix.py }}" - - name: Install dependencies - run: pip install tox - name: Run unit tests - run: tox -e py3${{ matrix.py }}-torch28-unit + run: pip install tox && tox -e py3${{ matrix.py }}-torch28-unit multi-torch-unit: runs-on: ubuntu-latest timeout-minutes: 30 @@ -43,7 +41,5 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.12" - - name: Install dependencies - run: pip install tox - name: Run unit tests - run: tox -e py312-torch${{ matrix.torch }}-unit + run: pip install tox && tox -e py312-torch${{ matrix.torch }}-unit diff --git a/.github/workflows/partial_unit_tests.yml b/.github/workflows/partial_unit_tests.yml index cc540c9c..7895cda1 100644 --- a/.github/workflows/partial_unit_tests.yml +++ b/.github/workflows/partial_unit_tests.yml @@ -6,7 +6,7 @@ on: paths: - ".github/workflows/partial_unit_tests.yml" - "modelopt/**" - - "tests/**" + - "tests/unit/**" - "setup.py" - "tox.ini" @@ -27,7 +27,5 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.12" - - name: Install dependencies - run: pip install tox - name: Run unit tests - run: tox -e py312-partial-unit-${{ matrix.test-env }} + run: pip install tox && tox -e py312-partial-unit-${{ matrix.test-env }} diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 52b45496..c96a2a1c 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -6,7 +6,7 @@ on: paths: - ".github/workflows/unit_tests.yml" - "modelopt/**" - - "tests/**" + - "tests/unit/**" - "setup.py" - "tox.ini" @@ -17,17 +17,28 @@ concurrency: jobs: unit-tests: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest timeout-minutes: 30 - strategy: - matrix: - os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: "3.12" - - name: Install dependencies - run: pip install tox - name: Run unit tests - run: tox -e py312-torch28-unit + run: pip install tox && COV_ARGS="--cov" tox -e py312-torch28-unit + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: true + verbose: true + unit-tests-windows: + runs-on: windows-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Run unit tests (without coverage) + run: pip install tox && tox -e py312-torch28-unit diff --git a/README.md b/README.md index 24090825..5ddf9afa 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ [![Documentation](https://img.shields.io/badge/Documentation-latest-brightgreen.svg?style=flat)](https://nvidia.github.io/TensorRT-Model-Optimizer) [![version](https://img.shields.io/pypi/v/nvidia-modelopt?label=Release)](https://pypi.org/project/nvidia-modelopt/) [![license](https://img.shields.io/badge/License-Apache%202.0-blue)](./LICENSE) +[![codecov](https://codecov.io/github/NVIDIA/TensorRT-Model-Optimizer/graph/badge.svg?token=r1bw4LC1WH)](https://codecov.io/github/NVIDIA/TensorRT-Model-Optimizer) [Examples](#examples) | [Documentation](https://nvidia.github.io/TensorRT-Model-Optimizer) | diff --git a/pyproject.toml b/pyproject.toml index 86dc0ceb..df1ac58a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,9 +51,8 @@ extend-ignore = [ "PLR0402", "PLR0912", "PLR0913", "PLR0915", "PLR2004", "PLR0911", "PT011", "PT018", "RUF002", "RUF012", - "SIM115", - "UP038", "UP032", - "SIM108", "SIM102", + "SIM102", "SIM108", "SIM115", + "UP032", "UP038", ] @@ -120,7 +119,7 @@ markers = ["manual: Only run when --run-manual is given"] [tool.coverage.run] # measure branch coverage in addition to statement coverage -branch = true +branch = false include = ["modelopt/*"] omit = ["*/plugins/*", "*/export/*"] diff --git a/tests/gpu/torch/quantization/test_hadamard.py b/tests/gpu/torch/quantization/test_hadamard.py index 486e1e40..9df95b96 100644 --- a/tests/gpu/torch/quantization/test_hadamard.py +++ b/tests/gpu/torch/quantization/test_hadamard.py @@ -39,7 +39,7 @@ def test_hadamard_transform(dim): xxt = x @ x.T x_h = normalized_hadamard_transform(x) xxt_h = x_h @ x_h.T - assert torch.allclose(xxt_h, xxt, atol=1e-5) + assert torch.allclose(xxt_h, xxt, atol=1e-3) def test_kv_rotate(): @@ -59,7 +59,7 @@ def test_kv_rotate(): }, ): output_test = model(dummy_input) - assert torch.allclose(output_ref, output_test, atol=1e-5) + assert torch.allclose(output_ref, output_test, atol=1e-3) set_quantizer_by_cfg( model, diff --git a/tests/gpu/torch/quantization/test_tensor_quant_cuda.py b/tests/gpu/torch/quantization/test_tensor_quant_cuda.py index 71aa1d10..f8be4ff4 100644 --- a/tests/gpu/torch/quantization/test_tensor_quant_cuda.py +++ b/tests/gpu/torch/quantization/test_tensor_quant_cuda.py @@ -231,7 +231,7 @@ def _test_fp4_kernel(test_in, test_out): assert torch.allclose(quantized_outputs, expected_outputs) if triton_kernel.IS_AVAILABLE: quantized_outputs_triton = triton_kernel.fp4_fake_quant_block( - inputs, inputs.abs().amax().item() + inputs, inputs.abs().amax() ) assert torch.allclose(quantized_outputs_triton, expected_outputs) diff --git a/tox.ini b/tox.ini index dc3dcc9d..4ae9bac8 100644 --- a/tox.ini +++ b/tox.ini @@ -22,7 +22,7 @@ deps = -e .[all,dev-test] commands = - python -m pytest tests/unit --cov + python -m pytest tests/unit {env:COV_ARGS:} #####################################################################