Skip to content

Commit

Permalink
[inductor] subproc parallel-compile: start thread last in init (pytor…
Browse files Browse the repository at this point in the history
…ch#128037)

Summary: Observed on an internal workload: the helper thread started and attempted to access member variables before they were initialized.

Differential Revision: [D58239827](https://our.internmc.facebook.com/intern/diff/D58239827)
Pull Request resolved: pytorch#128037
Approved by: https://github.com/Skylion007, https://github.com/eellison
  • Loading branch information
masnesral authored and pytorchmergebot committed Jun 7, 2024
1 parent e8e0bdf commit 6a2bf48
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion torch/_inductor/compile_worker/subproc_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ def __init__(self, nprocs: int):
self.write_lock = threading.Lock()
self.read_pipe: Pipe = typing.cast(Pipe, self.process.stdout)
self.read_thread = threading.Thread(target=self._read_thread, daemon=True)
self.read_thread.start()

self.futures_lock = threading.Lock()
self.pending_futures: Dict[int, Future[Any]] = {}
self.job_id_count = itertools.count()

self.running = True

# Start thread last to ensure all member variables are initialized
# before any access.
self.read_thread.start()

def submit(self, job_fn: Callable[..., Any], *args):
if args:
job_fn = functools.partial(job_fn, *args)
Expand Down

0 comments on commit 6a2bf48

Please sign in to comment.