Refactor test utilities and add CUDA tensor operation tests#254
Merged
LoserCheems merged 2 commits intomainfrom Mar 19, 2026
Merged
Refactor test utilities and add CUDA tensor operation tests#254LoserCheems merged 2 commits intomainfrom
LoserCheems merged 2 commits intomainfrom
Conversation
…utility functions for tensor operations
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors tests/test_utils.py to add reusable correctness helpers (reference implementations + runners) and introduces a set of CUDA-only unit tests validating forward/backward behavior for dense, sparse, and gated Triton attention kernels in both fixed-length and varlen modes.
Changes:
- Expanded
tests/test_utils.pywith reference attention implementations, seed/seqlens helpers, and forward/backward correctness runners. - Added CUDA-gated pytest suites for dense/sparse/gated forward/backward correctness (base + varlen).
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_utils.py | Adds reference implementations and runner utilities for kernel correctness checks. |
| tests/test_dense_base_forward.py | New CUDA test for dense base forward correctness. |
| tests/test_dense_base_backward.py | New CUDA test for dense base backward correctness. |
| tests/test_dense_varlen_forward.py | New CUDA test for dense varlen forward correctness. |
| tests/test_dense_varlen_backward.py | New CUDA test for dense varlen backward correctness. |
| tests/test_sparse_base_forward.py | New CUDA test for sparse base forward correctness. |
| tests/test_sparse_base_backward.py | New CUDA test for sparse base backward correctness. |
| tests/test_sparse_varlen_forward.py | New CUDA test for sparse varlen forward correctness. |
| tests/test_sparse_varlen_backward.py | New CUDA test for sparse varlen backward correctness. |
| tests/test_gated_base_forward.py | New CUDA test for gated base forward correctness. |
| tests/test_gated_base_backward.py | New CUDA test for gated base backward correctness. |
| tests/test_gated_varlen_forward.py | New CUDA test for gated varlen forward correctness. |
| tests/test_gated_varlen_backward.py | New CUDA test for gated varlen backward correctness. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+4
to
+7
| from test_utils import run_forward_varlen_case, set_seed | ||
|
|
||
| pytestmark = pytest.mark.skipif( | ||
| not torch.cuda.is_available(), reason="CUDA is required" |
Comment on lines
+6
to
+7
| pytestmark = pytest.mark.skipif( | ||
| not torch.cuda.is_available(), reason="CUDA is required" |
Comment on lines
+6
to
+7
| pytestmark = pytest.mark.skipif( | ||
| not torch.cuda.is_available(), reason="CUDA is required" |
Comment on lines
+5
to
+7
|
|
||
| pytestmark = pytest.mark.skipif( | ||
| not torch.cuda.is_available(), reason="CUDA is required" |
| from test_utils import run_forward_base_case, set_seed | ||
|
|
||
| pytestmark = pytest.mark.skipif( | ||
| not torch.cuda.is_available(), reason="CUDA is required" |
Comment on lines
+5
to
+7
|
|
||
| pytestmark = pytest.mark.skipif( | ||
| not torch.cuda.is_available(), reason="CUDA is required" |
Comment on lines
+4
to
+7
| from test_utils import run_forward_varlen_case, set_seed | ||
|
|
||
| pytestmark = pytest.mark.skipif( | ||
| not torch.cuda.is_available(), reason="CUDA is required" |
Comment on lines
+4
to
+7
| from test_utils import run_forward_varlen_case, set_seed | ||
|
|
||
| pytestmark = pytest.mark.skipif( | ||
| not torch.cuda.is_available(), reason="CUDA is required" |
Comment on lines
+5
to
+7
|
|
||
| pytestmark = pytest.mark.skipif( | ||
| not torch.cuda.is_available(), reason="CUDA is required" |
Comment on lines
+5
to
+7
|
|
||
| pytestmark = pytest.mark.skipif( | ||
| not torch.cuda.is_available(), reason="CUDA is required" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root Cause
Changes
test_utils.pyand introduced new utility functions for dense and sparse tensor operations.Reproduction
Tests
Compatibility
Checklist