When torch.use_deterministic_algorithms(True) is enabled, make topk resolve tied values with stable index tie-breaking.
CPU topk now compares by value and then index in deterministic mode. CUDA keeps the existing top-k selection path and uses stable sorting for the selected top-k outputs so threshold ties preserve input-index order without falling back to a full sort on NVIDIA. ROCm uses stable sort in deterministic mode because its current top-k gather reserves tie slots through atomics.
This gives deterministic mode a topk behavior analogous to scatter_add: fast default kernels remain available, while deterministic mode uses stable algorithms when requested.
Test Plan:
Rebuilt PyTorch from source with CUDA enabled.
python -m py_compile test/test_sort_and_select.py torch/init.py torch/_torch_docs.py
python test/test_sort_and_select.py -k topk_deterministic
python test/test_sort_and_select.py -k topk
git diff --check HEAD^
lintrunner --config=.lintrunner.toml --skip=PYREFLY aten/src/ATen/native/TopKImpl.h aten/src/ATen/native/cuda/TensorTopK.cpp test/test_sort_and_select.py torch/init.py torch/_torch_docs.py
Pull Request resolved:
Community-Analysen & Experten-Meinungen 0
Verwandte Story-Cluster & Quellen (Vektor-KI)
Ähnliche Beiträge
Auch interessante Nachrichten trunk/1100802ab6ce07f48d6ad543fa87318d10bbfb49: Make topk deterministic under deterministic algorithms (#186653)
Thematisch verwandte Begriffe: trunk1100802ab6ce07f48d6ad543fa87318d10bbfb49, Make, topk, deterministic · 6 Treffer
Unveiling malware behavior trends
Building Agentic RAG, Step by Step: From Static Retrieval to Reasoning Pipelines
Getting the Most Out of Transformers in Elastic
How to Evaluate Live & Voice Agents in ADK
How to Evaluate Live & Voice Agents in ADK
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
SOCIAL SHARE CARD GENERATOR