Toolchain: Block installation of prebuilt libtorch when enabling MKL#7525
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents the toolchain from automatically installing the prebuilt CPU libtorch package when MKL/oneMKL is enabled, to avoid runtime symbol interposition between libtorch’s bundled MKL symbols and an externally linked oneMKL runtime (which can lead to instability/segfaults even outside libtorch usage).
Changes:
- Add a configuration guard that hard-errors if
MATH_MODE=mkland--with-libtorchrequests the prebuilt installer (__INSTALL__). - Provide a clear remediation path in the error message: use
--with-libtorch=systemor--with-libtorch=<path>for a compatible externally-linked libtorch.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mohanchen
approved these changes
Jun 27, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The prebuilt CPU libtorch package embeds and exports MKL implementation symbols, while the oneMKL configuration links against an external oneMKL runtime. These overlapping globally visible symbols can be interposed by the dynamic loader, resulting in an ill-conditioned mixed-MKL process and segmentation faults even in calculations that do not use libtorch functionality at all.
Users of oneMKL builds can still provide a compatible libtorch installation explicitly via
--with-libtorch=systemor--with-libtorch=<path>. A compatible libtorch should be built against the same external oneMKL stack rather than bundling a separate MKL implementation.The CMake logic of the orders with MKL and Torch is invalid and thus removed, since this error happens due to symbol conflicts and can't be resolved by simply adjusting linking orders. The right order (BLAS before Torch) is preserved.