Repository navigation
[Inductor max autotune] Multithreaded Precompilation - #119003
Conversation
When using the Cutlass backend, the compilation of CUDA source files can totally dominate the runtime required for the benchmarking done as part of Autotuning. This change adds a multithreaded precompilation phase, which serves to pre-populate the compilation cache ( both in-memory, and a possible on-disk sccache ). Also it ensures that no unneccessary compilation and benchmarking steps are performed, which was peviously the case. [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/119003
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 907de97 with merge base 520771d ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
When using the Cutlass backend, the compilation of CUDA source files can totally dominate the runtime required for the benchmarking done as part of Autotuning. This change adds a multithreaded precompilation phase, which serves to pre-populate the compilation cache ( both in-memory, and a possible on-disk sccache ). Also it ensures that no unneccessary compilation and benchmarking steps are performed, which was peviously the case. [ghstack-poisoned]
| and check_cache(self.get_global_cache(), callback=log_stats) | ||
| ): | ||
| try: | ||
| # re-benchmark everything to try to get consistent numbers from the same machine |
There was a problem hiding this comment.
This comment seems important. I think we do want consistent numbers from the same machine. If you mix old numbers with new numbers it may not be apples-to-apples.
Typically, compiling is much more expensive than running. So the cost of re-running (with a cached compile) should be very low.
There was a problem hiding this comment.
I will change that back if you like. It will literally mean that we run the same code again on the same machine, just at a different point in time. So I can imagine there is a difference if GPU / CPU power settings or background load have changed in the meantime, but not really much else.
| int( | ||
| os.environ.get( | ||
| "TORCHINDUCTOR_MAX_AUTOTUNE_PRECOMPILATION_WORKERS", | ||
| str(torch.get_num_threads() - 8), |
There was a problem hiding this comment.
Why -8? This could be negative on some machines.
There was a problem hiding this comment.
Yes, negative values are allowed, in that case we simply don't have parallel precompilation. The idea is to leave at least 8 CPUs unused by parallel precompilation by default. But we could change that of course. If you have a clear preference what to put here instead just tell me.
There was a problem hiding this comment.
Why not use just use torch.get_num_threads()?
There was a problem hiding this comment.
The idea is to leave 8 CPUs unused under the assumption that these are required for whatever else is happening on the system. But I will remove the -8.
| len(choices), | ||
| num_workers, | ||
| ) | ||
| with ThreadPoolExecutor(max_workers=num_workers) as executor: |
There was a problem hiding this comment.
Why not reuse the same threadpool and infra for parallel compiles? This seems like it is doing the same thing as async compile...
There was a problem hiding this comment.
Several reasons:
1.) Threads are relatively lightweight to construct but (a bit) costly to keep alive, so there's no real benefit but a downside to maintain a persistent threadpool.
2.) If I would reuse the AsyncCompile threadpool, I could run into deadlocks or have strange performance issues, depending on what other code does. I could of course ensure this is bug free right now, but that's hard to keep ensured as the code evolves. Unit tests would be insufficient to guard against sporadic deadlocks through certain race conditions. Encapsulating this is more robust in the long run.
3.) This code works well, is compact and doesn't couple otherwise unrelated code sections design-wise via global state or code. The DRY principle and avoiding unneccessary coupling as design principles are in conflict here. I would prefer to avoid unneccessary coupling, as it's much more important IMO.
UPDATE:
Removing the "-8" in the number of precompilation workers makes it unneccessary to discern between the two config settings. I will reuse the existing config.
This is actually on the default codepath for all unit tests that involve max autotune. So while there were no dedicated unit tests of the precompilation functionality per-se, a lot of tests would immediately fail if this would not work. Performance benefits in practice are proven through manual tests. But I will add a test where I force the config setting. UPDATE: I have added two additional unit tests. One acts as an integration test, forcing parallel precompilation, the other is a whitebox unit test which ensures that the precompile method on the ChoiceCallers is being called properly. |
When using the Cutlass backend, the compilation of CUDA source files can totally dominate the runtime required for the benchmarking done as part of Autotuning. This change adds a multithreaded precompilation phase, which serves to pre-populate the compilation cache ( both in-memory, and a possible on-disk sccache ). Also it ensures that no unneccessary compilation and benchmarking steps are performed, which was peviously the case. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 muchulee8 aakhundov ColinPeppler [ghstack-poisoned]
When using the Cutlass backend, the compilation of CUDA source files can totally dominate the runtime required for the benchmarking done as part of Autotuning. This change adds a multithreaded precompilation phase, which serves to pre-populate the compilation cache ( both in-memory, and a possible on-disk sccache ). Also it ensures that no unneccessary compilation and benchmarking steps are performed, which was peviously the case. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 muchulee8 aakhundov ColinPeppler [ghstack-poisoned]
When using the Cutlass backend, the compilation of CUDA source files can totally dominate the runtime required for the benchmarking done as part of Autotuning. This change adds a multithreaded precompilation phase, which serves to pre-populate the compilation cache ( both in-memory, and a possible on-disk sccache ). Also it ensures that no unneccessary compilation and benchmarking steps are performed, which was peviously the case. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 muchulee8 aakhundov ColinPeppler [ghstack-poisoned]
When using the Cutlass backend, the compilation of CUDA source files can totally dominate the runtime required for the benchmarking done as part of Autotuning. This change adds a multithreaded precompilation phase, which serves to pre-populate the compilation cache ( both in-memory, and a possible on-disk sccache ). Also it ensures that no unneccessary compilation and benchmarking steps are performed, which was peviously the case. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 muchulee8 aakhundov ColinPeppler [ghstack-poisoned]
|
@pytorchbot merge |
|
Can't merge closed PR #119003 |
|
Accidentally clicked merge, which doesn't work with ghstack. I can't reopen it, so I had to recreate the PR here: #119386 |
Stack from ghstack (oldest at bottom):
When using the Cutlass backend, the compilation
of CUDA source files can totally dominate the runtime required for the benchmarking done
as part of Autotuning.
This change adds a multithreaded precompilation phase, which serves to pre-populate the compilation cache ( both in-memory, and a
possible on-disk sccache ).
Also it ensures that no unneccessary compilation
and benchmarking steps are performed, which was peviously the case.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @muchulee8 @aakhundov @ColinPeppler