Skip to content

Refactor test utilities and add CUDA tensor operation tests#254

Merged
LoserCheems merged 2 commits intomainfrom
optim_triton_version
Mar 19, 2026
Merged

Refactor test utilities and add CUDA tensor operation tests#254
LoserCheems merged 2 commits intomainfrom
optim_triton_version

Conversation

@LoserCheems
Copy link
Collaborator

Summary

  • Enhance the structure and readability of test utilities while adding new utility functions for tensor operations.

Root Cause

  • The existing test utilities lacked organization and clarity, making it difficult to maintain and extend.

Changes

  • Refactored test_utils.py and introduced new utility functions for dense and sparse tensor operations.

Reproduction

  • Run the new unit tests for dense and sparse tensor operations with CUDA checks.

Tests

  • Added unit tests for various tensor operations, ensuring correctness with CUDA availability checks.

Compatibility

  • No backward compatibility issues identified.

Checklist

  • Linked issue provided
  • Adds or updates tests
  • Updates docs if needed
  • No perf regressions

Copilot AI review requested due to automatic review settings March 19, 2026 07:24
@LoserCheems LoserCheems merged commit ed0c542 into main Mar 19, 2026
3 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py with 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants