You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today tests/run_tests.sh is the only place that knows which test module runs under which
backend, so a plain pytest collects torch-only modules under the keras backend and fails at import
(cannot import name 'PQBatchNorm2d' from 'pquant.core.keras.layers'). CI's matrix runs plain pytest per backend, so this must be fixed in the test files themselves.
Implementation note: gating must use pytest.skip(..., allow_module_level=True) placed above the backend-specific imports (or pytest.importorskip). A pytest.mark.skipif or a
custom marker will not work — markers are evaluated after the module is imported, and the
failure here happens at import time. (This is also why no markers = [...] entry is needed in [tool.pytest.ini_options].)
Backend-gate each backend-specific test module so it skips at collection instead of
erroring. Guard before the backend-specific imports, e.g.: python import keras, pytest if keras.backend.backend() != "torch": pytest.skip("torch backend only", allow_module_level=True)
Apply to the torch-only modules (test_torch_compression_layers.py, test_torch_onnx_converter.py, test_torch_alkaid_conversion.py, test_hgq_torch.py) and
symmetrically to the keras-only ones (test_keras_*, test_hgq_keras.py). Leave test_ap.py / test_pdp.py / test_wanda.py ungated — they run under both.
Remove the ineffective os.environ["KERAS_BACKEND"] = "torch" at the top of test_torch_compression_layers.py — it's a no-op once keras is already imported by conftest.py, and it masks the real gating problem.
Skip optional-dependency tests when the dep is absent: add pytest.importorskip("onnx")
to the onnx converter tests and pytest.importorskip("alkaid") to the alkaid conversion
tests. (alkaid is the plugin host — it must not become a pquant dependency; onnx is
opt-in via the [onnx] extra.)
Preserve channels_last coverage:run_tests.sh runs test_keras_compression_layers.py
a second time with DATA_FORMAT=channels_last. Keep this axis alive by parametrizing the set_image_data_format fixture in conftest.py over channels_first/channels_last (or by
adding a dedicated CI job) — otherwise it silently stops being tested.
Delete tests/run_tests.sh once the above lands — KERAS_BACKEND=<backend> pytest then
selects the right tests automatically, and the CI matrix supersedes the script.
Fix CUDA-forcing in the torch tests so they run on CPU-only machines. ~40 torch tests
currently fail with AssertionError: Torch not compiled with CUDA enabled
(torch/cuda/__init__.py:522) on any machine without a GPU. conftest.py already tries to
fall back correctly (device = "cuda" if torch.cuda.is_available() else "cpu"), so something
in the tests or library code is initialising CUDA regardless — find and fix it. This is a CI
blocker: GitHub's ubuntu-latest runners have no GPU, so these tests will fail in the KERAS_BACKEND=torch matrix jobs exactly as they do locally on macOS. Verify with KERAS_BACKEND=torch pytest tests on a CPU-only machine — expect zero CUDA-related failures.
Fix hardcoded CUDA in add_compression_layers.src/pquant/core/torch/layers.py:641-644
calls model.to("cuda") (and .to("cuda") on the warm-up tensor) unconditionally, with no torch.cuda.is_available() guard — so the function crashes with AssertionError: Torch not compiled with CUDA enabled on any CPU-only machine. This is the
root cause of the ~40 failing torch tests, it makes the library unusable for CPU users, and it blocks the CI torch matrix (GitHub runners have no GPU). Fix by resolving the device once
("cuda" if torch.cuda.is_available() else "cpu") and using it for all three calls. Verify
with KERAS_BACKEND=torch pytest tests on a CPU-only machine.
Today
tests/run_tests.shis the only place that knows which test module runs under whichbackend, so a plain
pytestcollects torch-only modules under the keras backend and fails at import(
cannot import name 'PQBatchNorm2d' from 'pquant.core.keras.layers'). CI's matrix runs plainpytestper backend, so this must be fixed in the test files themselves.erroring. Guard before the backend-specific imports, e.g.:
python import keras, pytest if keras.backend.backend() != "torch": pytest.skip("torch backend only", allow_module_level=True)Apply to the torch-only modules (
test_torch_compression_layers.py,test_torch_onnx_converter.py,test_torch_alkaid_conversion.py,test_hgq_torch.py) andsymmetrically to the keras-only ones (
test_keras_*,test_hgq_keras.py). Leavetest_ap.py/test_pdp.py/test_wanda.pyungated — they run under both.os.environ["KERAS_BACKEND"] = "torch"at the top oftest_torch_compression_layers.py— it's a no-op once keras is already imported byconftest.py, and it masks the real gating problem.pytest.importorskip("onnx")to the onnx converter tests and
pytest.importorskip("alkaid")to the alkaid conversiontests. (
alkaidis the plugin host — it must not become a pquant dependency;onnxisopt-in via the
[onnx]extra.)channels_lastcoverage:run_tests.shrunstest_keras_compression_layers.pya second time with
DATA_FORMAT=channels_last. Keep this axis alive by parametrizing theset_image_data_formatfixture inconftest.pyoverchannels_first/channels_last(or byadding a dedicated CI job) — otherwise it silently stops being tested.
tests/run_tests.shonce the above lands —KERAS_BACKEND=<backend> pytestthenselects the right tests automatically, and the CI matrix supersedes the script.
currently fail with
AssertionError: Torch not compiled with CUDA enabled(
torch/cuda/__init__.py:522) on any machine without a GPU.conftest.pyalready tries tofall back correctly (
device = "cuda" if torch.cuda.is_available() else "cpu"), so somethingin the tests or library code is initialising CUDA regardless — find and fix it. This is a CI
blocker: GitHub's
ubuntu-latestrunners have no GPU, so these tests will fail in theKERAS_BACKEND=torchmatrix jobs exactly as they do locally on macOS. Verify withKERAS_BACKEND=torch pytest testson a CPU-only machine — expect zero CUDA-related failures.add_compression_layers.src/pquant/core/torch/layers.py:641-644calls
model.to("cuda")(and.to("cuda")on the warm-up tensor) unconditionally, with notorch.cuda.is_available()guard — so the function crashes withAssertionError: Torch not compiled with CUDA enabledon any CPU-only machine. This is theroot cause of the ~40 failing torch tests, it makes the library unusable for CPU users, and it
blocks the CI torch matrix (GitHub runners have no GPU). Fix by resolving the device once
(
"cuda" if torch.cuda.is_available() else "cpu") and using it for all three calls. Verifywith
KERAS_BACKEND=torch pytest testson a CPU-only machine.