No safe way to set the CPU thread count from Python: _unsafe_reset_threadpool after load_method crashes or hangs XNNPACK
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 25/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Veraltet
- Bereich
- backend, machine-learning
Rechercherichtung
Start with the Python binding for _unsafe_reset_threadpool and the thread pool lifetime rules in threadpool.h; trace how loaded methods retain the pool pointer. The issue includes a reproducer using XNNPACK and Runtime.load_method, so use it to check the reset-before-load and reset-after-load cases. Done means Python has a supported way to choose the thread count or rejects a reset after loading before it can crash or hang; an open linked pull request indicates work is already underway.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
🐛 Describe the bug
From Python, _unsafe_reset_threadpool(n) is the only way to set the thread count that XNNPACK uses. Called after a method is loaded, it makes the following execute calls segfault or hang forever (all threads waiting on a futex). Called before load_method, it works.
import torch
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
from executorch.exir import to_edge_transform_and_lower
from executorch.extension.pybindings.portable_lib import (
_threadpool_get_thread_count,
_unsafe_reset_threadpool,
)
from executorch.runtime import Runtime
model = torch.nn.Sequential(torch.nn.Linear(256, 256), torch.nn.ReLU(), torch.nn.Linear(256, 256)).eval()
x = torch.randn(64, 256)
ep = torch.export.export(model, (x,))
pte = to_edge_transform_and_lower(ep, partitioner=[XnnpackPartitioner()]).to_executorch()
method = Runtime.get().load_program(pte.buffer).load_method("forward")
_unsafe_reset_threadpool(2 * _threadpool_get_thread_count())
for _ in range(20):
method.execute([x]) # segfaults or hangs
On Linux x86_64 with 8 threads by default, a reset to 16 after load_method crashed or hung in 10 of 11 runs, and a reset to 4 in 3 of 5. The same resets before load_method passed 10 of 10. Linux aarch64 shows the same pattern, including the hang and an abort with The futex facility returned an unexpected error code. A reset to the current count does nothing, so it always looks fine.
Cause: the XNNPACK runtime gets the thread pool pointer when the method is loaded (xnn_create_runtime_v4(..., get_pthreadpool(), ...)), and the reset frees that pool and creates a new one.
threadpool.h warns that other code may still hold the old pointer and says to reset before loading. The Python function has no such note and does not stop the call. This is different from #14321 (a macOS crash from two copies of pthreadpool): here there is one copy, and the trigger is the order of the calls.
Ask:
- A supported way to set the thread count from Python, for example a runtime or backend option.
- Until then, raise an error instead of crashing when the reset comes after a method is loaded.
Versions
- executorch 1.6.0 (PyPI) and the 2026-11-05 nightly
- torch 2.15.0, and 2.16 nightly with the ExecuTorch nightly
- Linux x86_64 and Linux aarch64, CPU
- Vorherrschende Sprache
- Python
- Sterne
- 5.2k
- Forks
- 1.2k
- Ø Merge
- 1 T. 23 Std.
- Gemergte PRs (30 T.)
- 700
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus pytorch/executorch
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
pytorch/executorch#24767 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
pytorch/executorch#24434 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
pytorch/executorch#24410 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement triaged
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 68/100
pytorch/executorch#21640 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
pytorch/executorch#24766 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in pytorch/executorch
Ähnliche Issues
-
ChatBedrockConverse changes the keys of JSON tool results to camelCase (`order_id` becomes `orderId`)Evtl. vergeben @geyazheng hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
langchain-ai/langchain-aws#1469 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
EESSI/docs#949 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
b4b usability
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
fix(schedule): align list_tasks since cursor filter boundary from strict > to >=Evtl. vergeben @bfs2021 hat das heute übernommen. Offenagent-ready bug p2 schedule
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
allenporter/supernote#540 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
frazane/scoringrules#164 ·
Maintainer antworten meist innerhalb von 1 Tag