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

fix: numba.*_num_threads resets torch num_threads #8141 #8145

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,13 @@ def __init__(
self.num_threads_ = num_threads
self.batch_first = batch_first

_torch_num_threads = torch.get_num_threads()
if num_threads > 0:
numba.set_num_threads(min(multiprocessing.cpu_count(), num_threads))
self.num_threads_ = numba.get_num_threads()
else:
self.num_threads_ = numba.get_num_threads()
torch.set_num_threads(_torch_num_threads)

def cost_and_grad_kernel(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ def __init__(
self.num_threads_ = num_threads
self.stream_ = stream # type: cuda.cudadrv.driver.Stream

_torch_num_threads = torch.get_num_threads()
if num_threads > 0:
numba.set_num_threads(min(multiprocessing.cpu_count(), num_threads))
self.num_threads_ = numba.get_num_threads()
else:
self.num_threads_ = numba.get_num_threads()
torch.set_num_threads(_torch_num_threads)

def log_softmax(self, acts: torch.Tensor, denom: torch.Tensor):
"""
Expand Down
Loading