PyTorch torch.set_num_interop_threads Function


Pytorch torch 参考手册PyTorch torch Reference Manual

torch.set_num_interop_threadsThis function in PyTorch is used to set the number of inter-op parallel threads. These threads are used to execute independent different operations in parallel.

Function Definition

torch.set_num_interop_threads(num_threads)

Parameter Description

  • num_threads: The number of inter-op threads to set

Usage Example

Example

import torch

# Set the number of inter-op threads
torch.set_num_interop_threads(4)

print("The number of inter-op threads has been set to:", torch.get_num_interop_threads())

# Restore default value
torch.set_num_interop_threads(1)

print("Default inter-op thread count restored")

The output result is:

跨域线程数已设置为: 4
已恢复默认跨域线程数

Pytorch torch 参考手册PyTorch torch Reference Manual

Other Extensions