Repository navigation
fix(torch_utils): explicitly inject cached build directory into sys.path - #661
Open
rahulsdhar wants to merge 1 commit into
Open
rahulsdhar wants to merge 1 commit into
rahulsdhar wants to merge 1 commit into
Conversation
Fixes a ModuleNotFoundError when compiling custom CUDA extensions on modern Python environments (e.g., Python 3.11/3.12). While torch.utils.cpp_extension.load compiles the custom plugins successfully into the hashed caching directory, modern PyTorch/Python path hooks sometimes fail to register this dynamic path automatically. Adding the verified cached_build_dir directly to sys.path guarantees that importlib can find and resolve the plugin seamlessly.
This branch has not been deployed
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.
Description
This PR resolves a silent compilation blocker where
importlib.import_modulethrows aModuleNotFoundError: No module named 'bias_act_plugin'(and subsequentlyupfirdn2d_plugin) when trying to generate images on modern Python setups (specifically Python 3.11 and 3.12).Root Cause
While
torch.utils.cpp_extension.load()successfully compiles the CUDA/C++ source code into the.cache/torch_extensions/...hashed directory, modern Python environments do not always inherit or automatically discover this dynamic path via standard PyTorch path registration hooks.Solution
Explicitly check if
cached_build_diris evaluated, and if so, safely insert it intosys.pathright before invokingimportlib.import_module(module_name). This mirrors standard dynamic linking paths and guarantees cross-compatibility with newer Python interpreters.Testing
Verified on:
python3 gen_images.py --outdir=out --trunc=1 --seeds=2 --network=...