Skip to content

Commit

Permalink
Fixed GPU tests and failing metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
vfdev-5 committed Nov 7, 2024
1 parent 0d8b8a1 commit 448a75b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions ignite/metrics/clustering/calinski_harabasz_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
def _calinski_harabasz_score(features: Tensor, labels: Tensor) -> float:
from sklearn.metrics import calinski_harabasz_score

np_features = features.numpy()
np_labels = labels.numpy()
np_features = features.cpu().numpy()
np_labels = labels.cpu().numpy()
score = calinski_harabasz_score(np_features, np_labels)
return score

Expand Down
4 changes: 2 additions & 2 deletions ignite/metrics/clustering/davies_bouldin_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
def _davies_bouldin_score(features: Tensor, labels: Tensor) -> float:
from sklearn.metrics import davies_bouldin_score

np_features = features.numpy()
np_labels = labels.numpy()
np_features = features.cpu().numpy()
np_labels = labels.cpu().numpy()
score = davies_bouldin_score(np_features, np_labels)
return score

Expand Down
4 changes: 2 additions & 2 deletions ignite/metrics/clustering/silhouette_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(
def _silhouette_score(self, features: Tensor, labels: Tensor) -> float:
from sklearn.metrics import silhouette_score

np_features = features.numpy()
np_labels = labels.numpy()
np_features = features.cpu().numpy()
np_labels = labels.cpu().numpy()
score = silhouette_score(np_features, np_labels, **self._silhouette_kwargs)
return score
4 changes: 2 additions & 2 deletions ignite/metrics/regression/kendall_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def _get_kendall_tau(variant: str = "b") -> Callable[[Tensor, Tensor], float]:
raise ValueError(f"variant accepts 'b' or 'c', got {variant!r}.")

def _tau(predictions: Tensor, targets: Tensor) -> float:
np_preds = predictions.flatten().numpy()
np_targets = targets.flatten().numpy()
np_preds = predictions.flatten().cpu().numpy()
np_targets = targets.flatten().cpu().numpy()
r = kendalltau(np_preds, np_targets, variant=variant).statistic
return r

Expand Down
4 changes: 2 additions & 2 deletions ignite/metrics/regression/spearman_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
def _spearman_r(predictions: Tensor, targets: Tensor) -> float:
from scipy.stats import spearmanr

np_preds = predictions.flatten().numpy()
np_targets = targets.flatten().numpy()
np_preds = predictions.flatten().cpu().numpy()
np_targets = targets.flatten().cpu().numpy()
r = spearmanr(np_preds, np_targets).statistic
return r

Expand Down
5 changes: 2 additions & 3 deletions tests/common_test_functionality.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ run_tests() {
skip_distrib_opt=""
fi


echo [pytest] > pytest.ini ; echo "cache_dir=${cache_dir}" >> pytest.ini

# Assemble options for the pytest command
Expand All @@ -103,8 +102,8 @@ run_tests() {

# Run the command
if [ "$trap_deselected_exit_code" -eq "1" ]; then
CUDA_VISIBLE_DEVICES="" eval "pytest ${pytest_args}" || { exit_code=$?; if [ "$exit_code" -eq ${last_failed_no_failures_code} ]; then echo "All tests deselected"; else exit $exit_code; fi; }
eval "pytest ${pytest_args}" || { exit_code=$?; if [ "$exit_code" -eq ${last_failed_no_failures_code} ]; then echo "All tests deselected"; else exit $exit_code; fi; }
else
CUDA_VISIBLE_DEVICES="" eval "pytest ${pytest_args}"
eval "pytest ${pytest_args}"
fi
}
4 changes: 2 additions & 2 deletions tests/ignite/metrics/test_hsic.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ def test_integration(self, sigma_x: float, sigma_y: float):
metric_devices.append(device)

for metric_device in metric_devices:
x = torch.randn((n_iters * batch_size, n_dims_x)).float().to(device)
x = torch.randn((n_iters * batch_size, n_dims_x), device=device).float()

lin = nn.Linear(n_dims_x, n_dims_y).to(device)
y = torch.sin(lin(x) * 100) + torch.randn(n_iters * batch_size, n_dims_y) * 1e-4
y = torch.sin(lin(x) * 100) + torch.randn(n_iters * batch_size, n_dims_y, device=x.device) * 1e-4

def data_loader(i, input_x, input_y):
return input_x[i * batch_size : (i + 1) * batch_size], input_y[i * batch_size : (i + 1) * batch_size]
Expand Down
5 changes: 2 additions & 3 deletions tests/run_cpu_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ skip_distrib_tests=${SKIP_DISTRIB_TESTS:-0}
use_last_failed=${USE_LAST_FAILED:-0}
match_tests_expression=${1:-""}


run_tests \
CUDA_VISIBLE_DEVICES="" run_tests \
--core_args "--tx 4*popen//python=python -vvv tests/ignite" \
--cache_dir ".cpu-not-distrib" \
--skip_distrib_tests "${skip_distrib_tests}" \
Expand All @@ -21,7 +20,7 @@ if [ "${skip_distrib_tests}" -eq "1" ]; then
fi

# Run 2 processes with --dist=each
run_tests \
CUDA_VISIBLE_DEVICES="" run_tests \
--core_args "-m distributed -vvv tests/ignite" \
--world_size 2 \
--cache_dir ".cpu-distrib" \
Expand Down
10 changes: 5 additions & 5 deletions tests/run_gpu_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
source "$(dirname "$0")/common_test_functionality.sh"
set -xeu

skip_distrib_tests=${SKIP_DISTRIB_TESTS:-1}
# https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02
skip_distrib_tests=${SKIP_DISTRIB_TESTS:-0}
use_last_failed=${USE_LAST_FAILED:-0}
ngpus=${1:-1}

match_tests_expression=${2:-""}
if [ -z "$match_tests_expression" ]; then
cuda_pattern="cuda"
cuda_pattern="cuda or nccl or gloo"
else
cuda_pattern="cuda and $match_tests_expression"
cuda_pattern="(cuda or nccl or gloo) and $match_tests_expression"
fi

run_tests \
--core_args "-vvv tests/ignite" \
--core_args "-vvv tests/ignite -m 'not distributed'" \
--cache_dir ".gpu-cuda" \
--skip_distrib_tests "${skip_distrib_tests}" \
--use_coverage 1 \
--match_tests_expression "${cuda_pattern}" \
--use_last_failed ${use_last_failed}

# https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02
if [ "${skip_distrib_tests}" -eq "1" ]; then
exit 0
fi
Expand Down

0 comments on commit 448a75b

Please sign in to comment.