summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjdj <jdj@kunix.org>2026-10-29 11:50:22 -0700
committerjdj <jdj@kunix.org>2026-10-29 11:50:22 -0700
commita0ddfb1b2f6242fac72f98e8d6ee1888e79667f3 (patch)
treea6e19658bae8466cb177d2ade41ad9176d23c2f8 /tests
parent2a02fecc86a87a6f1639b80da932b1f9daed8f17 (diff)
downloadvolta-train-kernels-master.tar.gz
volta-train-kernels-master.zip
Validate offsets and canon_rope_attention shapes; default test device cuda:0 with safe skip; narrow README claimsHEADmaster
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/_ref.py8
-rw-r--r--tests/test_attention.py8
-rw-r--r--tests/test_canon_rope.py13
-rw-r--r--tests/test_ref.py5
4 files changed, 32 insertions, 2 deletions
diff --git a/tests/_ref.py b/tests/_ref.py
index dc8626b..d4d8543 100644
--- a/tests/_ref.py
+++ b/tests/_ref.py
@@ -7,7 +7,7 @@ from torch.nn.attention import SDPBackend, sdpa_kernel
def device():
- return torch.device(os.environ.get("VK_TEST_DEVICE", "cuda:1"))
+ return torch.device(os.environ.get("VK_TEST_DEVICE", "cuda:0"))
def select(dev):
@@ -20,7 +20,11 @@ def usable(dev):
"""None if the kernels can run on dev, else the reason to skip."""
if not torch.cuda.is_available():
return "no CUDA"
- if torch.cuda.get_device_capability(dev) < (7, 0):
+ try:
+ cap = torch.cuda.get_device_capability(dev)
+ except (AssertionError, RuntimeError) as e:
+ return f"{dev} unavailable: {e}"
+ if cap < (7, 0):
return "needs compute capability >= 7.0"
return None
diff --git a/tests/test_attention.py b/tests/test_attention.py
index 0def2cf..99b6dcc 100644
--- a/tests/test_attention.py
+++ b/tests/test_attention.py
@@ -60,6 +60,14 @@ class TestAttention(unittest.TestCase):
with self.assertRaisesRegex(RuntimeError, "q"):
varlen_causal_attention(q, k, v, off)
+ def test_rejects_offsets_not_covering_tokens(self):
+ from volta_kernels import varlen_causal_attention
+ q, k, v, off = packed_qkv([128, 64], dev=device())
+ with self.assertRaisesRegex(RuntimeError, "offsets"):
+ varlen_causal_attention(q, k, v, off[:-1]) # last 64 tokens uncovered
+ with self.assertRaisesRegex(RuntimeError, "offsets"):
+ varlen_causal_attention(q, k, v, off + 1) # does not start at 0
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/test_canon_rope.py b/tests/test_canon_rope.py
index c9f939d..9a4db6e 100644
--- a/tests/test_canon_rope.py
+++ b/tests/test_canon_rope.py
@@ -39,6 +39,19 @@ class TestCanonRope(unittest.TestCase):
for name, a, b in zip("qkv", ours, ref):
self.assertTrue(torch.equal(a.reshape(b.shape), b), f"{name} differs from the Triton reference")
+ def test_canon_attention_rejects_bad_shapes(self):
+ from volta_kernels import canon_rope_attention
+ qkv, w, m1, m2, cos, sin = canon_inputs(B=1, T=192, doc_starts=(0,), dev=device())
+ off = torch.tensor([0, 192], device=device())
+ with self.assertRaisesRegex(RuntimeError, "128"): # T=192 passes fwd, fails bwd
+ canon_rope_attention(qkv, w, m1, m2, cos, sin, off)
+ qkv, w, m1, m2, cos, sin = canon_inputs(B=1, T=256, doc_starts=(0,), dev=device())
+ off = torch.tensor([0, 256], device=device())
+ with self.assertRaisesRegex(RuntimeError, "1536"):
+ canon_rope_attention(qkv[..., :1024].contiguous(), w, m1, m2, cos, sin, off)
+ with self.assertRaisesRegex(RuntimeError, "fp16"):
+ canon_rope_attention(qkv.float(), w, m1, m2, cos, sin, off)
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/test_ref.py b/tests/test_ref.py
index 5024971..c9fd93d 100644
--- a/tests/test_ref.py
+++ b/tests/test_ref.py
@@ -19,5 +19,10 @@ class TestReference(unittest.TestCase):
self.assertLess(((m[name] - want).norm() / want.norm()).item(), 1e-12, name)
+class TestDeviceSelection(unittest.TestCase):
+ def test_missing_device_is_a_skip_reason_not_an_error(self):
+ self.assertIsInstance(usable(torch.device("cuda:99")), str)
+
+
if __name__ == "__main__":
unittest.main()