Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tandav committed Mar 20, 2023
1 parent deab447 commit f30bff4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ jobs:
- name: build image
run: make build

- name: test image
- name: test
run: make test

- name: test-no-gpu
run: make test-no-gpu

# - name: push image
# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
# run: make push
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ push:
.PHONY: test
test: build
docker run --rm -t --gpus all \
-e PITCH_DETECTORS_ERROR_GPU_NOT_AVAILABLE=true \
-e PITCH_DETECTORS_GPU=true \
-v $$PWD/pitch_detectors:/app/pitch_detectors \
-v $$PWD/tests:/app/tests \
tandav/pitch-detectors:11.8.0-cudnn8-devel-ubuntu22.04 \
pytest -v --cov pitch_detectors --cov-fail-under 90

.PHONY: test-no-gpu
test-no-gpu: build
docker run --rm -t \
-e PITCH_DETECTORS_GPU=false \
-v $$PWD/pitch_detectors:/app/pitch_detectors \
-v $$PWD/tests:/app/tests \
tandav/pitch-detectors:11.8.0-cudnn8-devel-ubuntu22.04 \
Expand Down
4 changes: 1 addition & 3 deletions pitch_detectors/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, a: np.ndarray, fs: int, hz_min: float = 75, hz_max: float = 6
self.f0: tp.Optional[np.ndarray] = None
self.t: tp.Optional[np.ndarray] = None
if (
os.environ.get('PITCH_DETECTORS_ERROR_GPU_NOT_AVAILABLE') and
os.environ.get('PITCH_DETECTORS_GPU') == 'true' and
self.use_gpu and
not self.gpu_available()
):
Expand Down Expand Up @@ -128,8 +128,6 @@ def __init__(
torch.device(device)

super().__init__(a, fs, hz_min, hz_max)
if not torch.cuda.is_available():
raise RuntimeError('TorchCrepe requires a GPU')

f0, confidence = torchcrepe.predict(
torch.from_numpy(a[np.newaxis, ...]),
Expand Down
4 changes: 4 additions & 0 deletions tests/gpu_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import subprocess

import pytest
Expand All @@ -6,15 +7,18 @@


@pytest.mark.order(0)
@pytest.mark.skipif(os.environ.get('PITCH_DETECTORS_GPU') == 'false', reason='gpu is not used')
def test_nvidia_smi():
subprocess.check_call('nvidia-smi')


@pytest.mark.order(1)
@pytest.mark.skipif(os.environ.get('PITCH_DETECTORS_GPU') == 'false', reason='gpu is not used')
def test_tensorflow():
assert tf.config.experimental.list_physical_devices('GPU')


@pytest.mark.order(2)
@pytest.mark.skipif(os.environ.get('PITCH_DETECTORS_GPU') == 'false', reason='gpu is not used')
def test_pytorch():
assert torch.cuda.is_available()

0 comments on commit f30bff4

Please sign in to comment.