W3cubDocs

/PyTorch 2.9

torch.set_num_threads

torch.set_num_threads(int)

Sets the number of threads used for intraop parallelism on CPU.

Warning

To ensure that the correct number of threads is used, set_num_threads must be called before running eager, JIT or autograd code.

© 2025, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://docs.pytorch.org/docs/2.9/generated/torch.set_num_threads.html