Skip to content

[XPU] [CI] Add comprehensive tests for refactored get_padding_offset kernel#1

Open
devin-ai-integration[bot] wants to merge 1 commit into
developfrom
devin/1780032974-test-get-padding-offset-refactor
Open

[XPU] [CI] Add comprehensive tests for refactored get_padding_offset kernel#1
devin-ai-integration[bot] wants to merge 1 commit into
developfrom
devin/1780032974-test-get-padding-offset-refactor

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Motivation

PR PaddlePaddle#7029 refactored get_padding_offset from two separate XPU kernels into a single kernel. The existing test only covers one basic scenario (seq_lens=[4,3,6], max_len=10). This PR adds comprehensive test coverage to verify correctness across edge cases and confirm behavioral equivalence with the old implementation.

Modifications

Added tests/operators/test_get_padding_offset_refactor.py with 23 test cases:

Core algorithm tests:

  • Basic case matching the commit's test data (seq_lens=[4,3,6])
  • Single batch (bs=1)
  • Single token total (bs=1, seq_len=1)
  • All sequences at full length (no padding)
  • All sequences at length 1 (maximum padding)
  • Mixed/identical/increasing/decreasing sequence lengths
  • Large batch size (bs=64)
  • Large int64 token values (overflow check)
  • max_len=1 edge case
  • Zero token_num edge case (all seq_lens=0)

Equivalence verification:

  • Confirms x_remove_padding, cum_offsets_out, cu_seqlens_q, cu_seqlens_k match the old two-kernel implementation
  • 50 randomized configurations tested for equivalence

Property-based invariant tests:

  • Output array lengths match expected dimensions (100 random configs)
  • cu_seqlens is monotonically non-decreasing
  • batch_id_per_token values are in [0, bs-1]
  • cum_offsets_out values are non-negative

Usage or Command

python -m pytest tests/operators/test_get_padding_offset_refactor.py -v --noconftest

Accuracy Tests

All 23 tests pass locally. The tests validate that:

  1. The refactored single-kernel algorithm produces identical x_remove_padding, cum_offsets_out, cu_seqlens_q, cu_seqlens_k as the old two-kernel implementation
  2. The new batch_id_per_token output correctly stores batch indices (replacing the old padding_offset which stored cumulative offsets)

Checklist

  • Add at least a tag in the PR title.
  • Format your code, run pre-commit before commit.
  • Add unit tests. This PR is specifically adding unit tests.
  • Provide accuracy results. All 23 tests pass.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch. (N/A - targeting develop)

Link to Devin session: https://app.devin.ai/sessions/0a98367efe304de197b296c0940bb3d4
Requested by: @ShaneGZhu

Adds test_get_padding_offset_refactor.py with 23 test cases validating
the single-kernel refactor (PR PaddlePaddle#7029). Tests include:

- Basic case matching the commit's test data
- Edge cases: single batch, single token, max_len=1, zero tokens
- All sequences at full length (no padding)
- All sequences at length 1 (maximum padding)
- Mixed/identical/increasing/decreasing sequence lengths
- Large batch size (bs=64)
- Large int64 token values
- Equivalence with old two-kernel implementation (50 random configs)
- Property-based invariants (output lengths, monotonicity, value ranges)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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.

1 participant