Menu

Does your thread count change your model's output? I tested torch.set_num_threads on 11 operations
📰

Does your thread count change your model's output? I tested torch.set_num_threads on 11 operations

DEV Community: pytorch·Vahana·about 8 hours ago
#BW4BbSRd
#devtopytorch#devto#dev#thread#torch
Long article (2060 words) — no AI summary yet.
Reading 0:00
15s threshold

I summed the same 10 million float32 numbers five times on my laptop, changing only torch.set_num_threads . I got five different answers:

1 thread: -177.465576171875 2 threads: -177.46554565429688 4 threads: -177.46632385253906 8 threads: -177.4659423828125 16 threads: -177.46597290039062

Enter fullscreen mode

Exit fullscreen mode

Then I ran a transformer layer plus a 32,000-way output head at the same five thread counts. All 32,000 logits came out bit-identical every time.

So the honest answer to "does the thread count change my output?" is: sometimes, and you can predict when. This post shows which operations changed, which didn't, and why the line falls where it does.

The setup

One script, blog_04_script.py (full code at the end).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.