-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add control over the number of torch threads
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import torch | ||
|
||
def configure_threads(pytorch_threads=None): | ||
"""Configure the number of threads available. | ||
This is necessary when using PyTorch on the CPU as by default it will use | ||
all available threads. | ||
Notes | ||
----- | ||
Uses ``torch.set_num_threads``. If pytorch threads is None but other | ||
arguments are specified then the value is inferred from them. | ||
Parameters | ||
---------- | ||
pytorch_threads: int, optional | ||
Maximum number of threads for PyTorch on CPU. If None, pytorch will | ||
use all available threads. | ||
""" | ||
if pytorch_threads: | ||
torch.set_num_threads(pytorch_threads) |