Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default number of threads to min(8, cpu count) #57

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sybil/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def _torch_set_num_threads(threads) -> int:
if threads < 0:
return torch.get_num_threads()
if threads is None or threads == 0:
threads = os.cpu_count()
# I've never seen a benefit to going higher than 8 and sometimes there is a big slowdown
threads = min(8, os.cpu_count())

torch.set_num_threads(threads)
return torch.get_num_threads()
Expand Down Expand Up @@ -315,7 +316,7 @@ def predict(
return_attentions : bool
If True, returns attention scores for each serie. See README for details.
threads : int
Number of CPU threads to use for PyTorch inference. Default is 0 (use all available cores).
Number of CPU threads to use for PyTorch inference.

Returns
-------
Expand Down
Loading