Download tests/test_task_acceptance.py from humanfia-lab/inference-kernels: direct link, hf CLI and curl.
- Browser
- Download file 2.51 kB
-
https://huggingface.co/datasets/humanfia-lab/inference-kernels/resolve/refs%2Fpr%2F2/tests/test_task_acceptance.py
- Command line
-
hf download hf://datasets/humanfia-lab/inference-kernels@refs/pr/2/tests/test_task_acceptance.py
-
curl -L -o test_task_acceptance.py https://huggingface.co/datasets/humanfia-lab/inference-kernels/resolve/refs%2Fpr%2F2/tests/test_task_acceptance.py
2.51 kB
| """Regression cases for the task policies used by both validation runners.""" | |
| import sys | |
| import unittest | |
| from pathlib import Path | |
| import torch | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) | |
| from task_acceptance import compare_output | |
| class TaskAcceptanceTests(unittest.TestCase): | |
| def test_contest_or_is_not_additive_tolerance(self): | |
| expected = torch.tensor([100.0]) | |
| actual = torch.tensor([115.0]) | |
| additive = dict(atol=10.0, rtol=0.1) | |
| compare_output(actual, expected, additive) | |
| with self.assertRaises(AssertionError): | |
| compare_output( | |
| actual, expected, dict(additive, comparison="absolute_or_relative") | |
| ) | |
| def test_strict_gdn_diagnostic_is_distinct_from_contest(self): | |
| expected, actual = torch.tensor([0.05]), torch.tensor([0.05151]) | |
| with self.assertRaises(AssertionError): | |
| compare_output(actual, expected, dict(atol=2e-5, rtol=1e-4)) | |
| compare_output( | |
| actual, | |
| expected, | |
| dict(atol=0.01, rtol=0.01, comparison="absolute_or_relative"), | |
| ) | |
| def test_matched_ratio_boundary_uses_integer_counts(self): | |
| expected = torch.zeros(10000) | |
| actual = expected.clone() | |
| actual[0] = 1.0 | |
| metrics = compare_output( | |
| actual, expected, dict(atol=0.0, rtol=0.0, required_matched_ratio=0.9999) | |
| ) | |
| self.assertEqual(metrics["mismatched_elements"], 1) | |
| actual[1] = 1.0 | |
| with self.assertRaises(AssertionError): | |
| compare_output( | |
| actual, | |
| expected, | |
| dict(atol=0.0, rtol=0.0, required_matched_ratio=0.9999), | |
| ) | |
| metrics = compare_output(expected, expected, dict(atol=0.0, rtol=0.0)) | |
| self.assertEqual(metrics["matched_ratio"], 1.0) | |
| def test_nonfinite_values_and_integer_mismatches_fail(self): | |
| for value in [float("nan"), float("inf")]: | |
| with self.assertRaises(AssertionError): | |
| compare_output( | |
| torch.tensor([value]), | |
| torch.tensor([value]), | |
| dict(atol=1.0, rtol=1.0), | |
| ) | |
| with self.assertRaises(AssertionError): | |
| compare_output( | |
| torch.tensor([1]), torch.tensor([2]), dict(atol=100.0, rtol=100.0) | |
| ) | |
| compare_output(torch.tensor([1]), torch.tensor([1]), dict(atol=0.0, rtol=0.0)) | |
| if __name__ == "__main__": | |
| unittest.main() | |