Skip to content

Tighten TQ4 SDPA input validation#20410

Open
fallintoplace wants to merge 1 commit into
pytorch:mainfrom
fallintoplace:fix/tq4-sdpa-validation-errors
Open

Tighten TQ4 SDPA input validation#20410
fallintoplace wants to merge 1 commit into
pytorch:mainfrom
fallintoplace:fix/tq4-sdpa-validation-errors

Conversation

@fallintoplace

Copy link
Copy Markdown

Summary

Tightens the Python wrapper validation for the TQ4 SDPA kernel so malformed inputs fail before shape unpacking, indexing, reshaping, or launching Triton.

Changes include:

  • validate ranks first for query, packed K/V, norms, centroids, rotation, mask, and kv_len
  • validate all tensors are on the same CUDA device as query
  • validate dtypes before layout-sensitive shape checks
  • validate packed K/V shape symmetry, norm layout, centroids shape, rotation shape, mask shape, and kv_len scalar shape
  • add malformed-input coverage for 3D query, 3D mask, bad rotation, bad centroids, CPU k_norms, and v_packed shape mismatch

Test Plan

  • python3 -m py_compile backends/cuda/triton/kernels/tq4_sdpa.py backends/cuda/tests/test_tq4_sdpa.py
  • git diff --check -- backends/cuda/triton/kernels/tq4_sdpa.py backends/cuda/tests/test_tq4_sdpa.py

I could not run the targeted CUDA unittest locally because the available Python environment is missing numpy and torch.

@pytorch-bot

pytorch-bot Bot commented Jun 21, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20410

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

⚠️ 13 Awaiting Approval

As of commit d906314 with merge base 55c54c7 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 21, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 21, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: fallintoplace / name: Minh Vu (d906314)

@pytorch-bot pytorch-bot Bot added the release notes: none Do not include this in the release notes label Jun 21, 2026
@fallintoplace

Copy link
Copy Markdown
Author

@pytorchbot label "release notes: none"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants