Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve testing time #820

Merged
merged 22 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
better solution
  • Loading branch information
SkafteNicki committed Feb 4, 2022
commit 85627e5f495992290bea106bfc6e79f8d811baab
4 changes: 2 additions & 2 deletions tests/audio/test_pit.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def pit_diff(preds, target, metric_func, eval_func):
return permutation_invariant_training(preds, target, metric_func, eval_func)[0]

self.run_differentiability_test(
preds=preds.unsqueeze(0),
target=target.unsqueeze(0),
preds=preds,
target=target,
metric_module=PermutationInvariantTraining,
metric_functional=pit_diff,
metric_args={"metric_func": metric_func, "eval_func": eval_func},
Expand Down
4 changes: 2 additions & 2 deletions tests/classification/test_accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def test_accuracy_fn(self, preds, target, subset_accuracy):

def test_accuracy_differentiability(self, preds, target, subset_accuracy):
self.run_differentiability_test(
preds=preds.unsqueeze(0),
target=target.unsqueeze(0),
preds=preds,
target=target,
metric_module=Accuracy,
metric_functional=accuracy,
metric_args={"threshold": THRESHOLD, "subset_accuracy": subset_accuracy},
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/testers.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,15 @@ def run_differentiability_test(
metric = metric_module(**metric_args)
if preds.is_floating_point():
preds.requires_grad = True
out = metric(preds[0, 0], target[0, 0])
out = metric(preds[0, :1], target[0, :1])

# Check if requires_grad matches is_differentiable attribute
_assert_requires_grad(metric, out)

if metric.is_differentiable and metric_functional is not None:
# check for numerical correctness
assert torch.autograd.gradcheck(
partial(metric_functional, **metric_args), (preds[0, 0].double(), target[0, 0])
partial(metric_functional, **metric_args), (preds[0, :1].double(), target[0, :1])
)

# reset as else it will carry over to other tests
Expand Down