[paddle-adapt] model_optimizations: 690 PASS with torch.sort compat patch#24
Merged
Merged
Conversation
…atch - §51: torch.sort in Paddle compat returns values-only Tensor (no indices namedtuple); patch wraps result in _SortResult(values, indices) with stable=True argsort for correct bfloat16 tie-breaking semantics - §51: torch.sort does not accept dim= kwarg in Paddle compat; patch accepts dim= and passes it as positional arg to bypass Paddle TypeError - No existing test files modified; all fixes isolated in tests/model_optimizations/conftest.py - Regression: tests/utils/test_topk.py 1335 PASS, tests/grouped_mm 4 PASS all still OK - Result: 690 passed, 4164 skipped (env-level SM architecture constraints), 0 failed Refs: MISMATCH_EXPERIMENT §51
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.
📌 Description
Adapt tests/model_optimizations for Paddle compat mode.
The key fix is a monkey-patch for torch.sort in tests/model_optimizations/conftest.py, which addresses two Paddle compat issues:
The patch introduces a _SortResult class wrapping (values, indices) where indices are computed via argsort with stable=True to preserve correct bfloat16 tie-breaking semantics.
Result: 690 passed, 4164 skipped (SM architecture env-level), 0 failed
🔍 Related Issues
Part of the FlashInfer Paddle compat adaptation effort.
Changes
🚀 Pull Request Checklist
✅ Pre-commit Checks
🧪 Tests
Reviewer Notes
Key insight: torch.sort must use stable=True in argsort for bfloat16 cases. Without stable=True, many tied values in bfloat16 are broken differently than PyTorch, causing ~210 new failures. The fix must live in conftest.py (not inline in test files) to apply the stable sort globally.
Refs: MISMATCH_EXPERIMENT §51