Skip to content

[paddle-adapt] test_topk: adapt tests/utils/test_topk.py for Paddle compat (1276/1346 PASS)#22

Merged
BingooYang merged 4 commits into
PFCCLab:0.6from
BingooYang:adapt/test_topk_sampling
May 19, 2026
Merged

[paddle-adapt] test_topk: adapt tests/utils/test_topk.py for Paddle compat (1276/1346 PASS)#22
BingooYang merged 4 commits into
PFCCLab:0.6from
BingooYang:adapt/test_topk_sampling

Conversation

@BingooYang
Copy link
Copy Markdown

📌 Description

Adapt tests/utils/test_topk.py and 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 utilities
    • §44/§45: torch.testing.assert_close bfloat16/float16 fallback (walk exception chain, numpy allclose)
    • §46: torch.equal() returns Python bool via .all().item()
    • §47: tensor.multiply(scalar) accepts int args
    • §48: tensor.clamp_min / tensor.clamp_max aliases
  • flashinfer/utils.py: get_shared_bytes_per_block_optin with hasattr + ctypes CUDA Runtime + SM heuristic fallback
  • flashinfer/topk.py: torch.sort wrapped in try/except for Paddle compat
  • tests/utils/test_topk.py: cast to float32 before amin/amax; positional dim arg for min/max
  • tests/utils/test_sampling.py: torch.cosine_similaritynn.functional.cosine_similarity
  • scripts/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

  • I have installed pre-commit by running pip install pre-commit (or used your preferred method).
  • I have installed the hooks with pre-commit install.
  • I have run the hooks manually with pre-commit run --all-files and fixed any reported issues.

🧪 Tests

  • 1276/1346 tests passing in tests/utils/test_topk.py
  • Regression: all cases in paddle_all_test_cases.sh PASS (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.

…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
@BingooYang BingooYang merged commit a2485b4 into PFCCLab:0.6 May 19, 2026
2 checks passed
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