[paddle-adapt] test_topk: adapt tests/utils/test_topk.py for Paddle compat (1276/1346 PASS)#22
Merged
Conversation
…ompat (1276/1346 PASS) - §44/§45: conftest.py monkey-patch torch.testing.assert_close for bfloat16/float16 (walk exception chain to detect paddle.isclose dtype error, fallback to numpy allclose) - §46: conftest.py monkey-patch torch.equal to return Python bool via .all().item() - §47: conftest.py monkey-patch tensor.multiply to accept scalar args - §48: conftest.py add clamp_min/clamp_max as torch.clamp aliases - §49: test_topk.py cast to float32 before amin/amax for bfloat16/float16 tensors - §50: test_topk.py replace .min(dim=N).values with .amin(N) (positional arg + no named tuple) - utils.py: get_shared_bytes_per_block_optin add hasattr + ctypes + SM heuristic fallback - topk.py: wrap torch.sort with try/except for Paddle compat (sort returns values only) - test_sampling.py: torch.cosine_similarity -> nn.functional.cosine_similarity - Add tests/utils/test_topk.py to paddle_all_test_cases.sh Remaining 70/1346 failures are pre-existing upstream issues unrelated to Paddle compat. Regression: adp_test.sh all PASS (attention_sink, MoE, allreduce, norm, gemm). Refs: MISMATCH_EXPERIMENT §44-§50
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/utils/test_topk.pyand related utilities for Paddle compat mode.Results: 1276/1346 tests PASS (70 remaining failures are pre-existing upstream issues unrelated to Paddle compat).
Changes
tests/utils/conftest.py(new): Paddle compat monkey-patches for test utilitiestorch.testing.assert_closebfloat16/float16 fallback (walk exception chain, numpy allclose)torch.equal()returns Python bool via.all().item()tensor.multiply(scalar)accepts int argstensor.clamp_min/tensor.clamp_maxaliasesflashinfer/utils.py:get_shared_bytes_per_block_optinwith hasattr + ctypes CUDA Runtime + SM heuristic fallbackflashinfer/topk.py:torch.sortwrapped in try/except for Paddle compattests/utils/test_topk.py: cast to float32 before amin/amax; positional dim arg for min/maxtests/utils/test_sampling.py:torch.cosine_similarity→nn.functional.cosine_similarityscripts/paddle_all_test_cases.sh: add passing test_topk.py cases🔍 Related Issues
Part of FlashInfer Paddle adaptation effort.
🚀 Pull Request Checklist
✅ Pre-commit Checks
pre-commitby runningpip install pre-commit(or used your preferred method).pre-commit install.pre-commit run --all-filesand fixed any reported issues.🧪 Tests
tests/utils/test_topk.pypaddle_all_test_cases.shPASS (attention_sink, MoE, allreduce, norm, gemm)Reviewer Notes
Remaining 70 failures are pre-existing upstream issues (deterministic/tie-break edge cases, multi-cta correctness) unrelated to Paddle compat adaptation.