Skip to content

fix: protect dependency headers during extension builds - #96

Open
WindDaoist wants to merge 3 commits into
MooreThreads:mainfrom
WindDaoist:fix/protect-dependency-porting
Open

fix: protect dependency headers during extension builds#96
WindDaoist wants to merge 3 commits into
MooreThreads:mainfrom
WindDaoist:fix/protect-dependency-porting

Conversation

@WindDaoist

Copy link
Copy Markdown
Contributor

Summary

  • Prevent in-place CUDA-to-MUSA porting from treating editable torch or torch_musa include roots as project source roots.
  • Keep dependency paths available to the compiler while excluding them from SimplePorting candidate roots.
  • Limit the legacy torch_musa stable-ABI header backport to stable-ABI extensions instead of every MUSA extension.
  • Add the explicit CUDAExtension(..., torchada_stable_abi=True) opt-in while retaining detection for existing vLLM/SGLang stable extension names and source layouts.
  • Document the new stable-ABI behavior in English and Chinese.

Motivation

With torch_musa installed in editable mode from a checkout such as /home/torch_musa, downstream torchvision builds receive that checkout as an include root. The previous path heuristic classified it as a project root and rewrote CUDA/C++ files in place. This patch separates compiler include paths from porting roots and protects dependency package roots based on their resolved module paths.

The stable header backport was originally added for libtorch-stable kernels on older torch_musa releases. It was previously invoked for every MUSA extension build, which could mutate torch/torch_musa headers during ordinary torchvision builds. It is now triggered only for explicit or recognized stable-ABI extensions.

Tests

51 passed, 1 skipped, 204 deselected

Executed in a clean worktree with:

PYTHONPATH=src python -m pytest -q tests/test_cpp_extension.py tests/test_inplace_porting.py tests/test_cuda_patching.py -k 'stable or dependency or inplace' tests/test_stable_abi_mappings.py

@WindDaoist
WindDaoist force-pushed the fix/protect-dependency-porting branch from 8f79b0a to 9346f0b Compare July 29, 2026 06:48
Comment thread src/torchada/utils/cpp_extension.py Outdated
@WindDaoist
WindDaoist force-pushed the fix/protect-dependency-porting branch from 2f5c290 to 4834445 Compare July 29, 2026 08:30
Comment thread src/torchada/utils/cpp_extension.py Outdated
@WindDaoist
WindDaoist force-pushed the fix/protect-dependency-porting branch from 4834445 to 085a2b5 Compare July 29, 2026 08:41
@WindDaoist
WindDaoist force-pushed the fix/protect-dependency-porting branch from 822ed01 to 85f6c67 Compare August 3, 2026 07:04
@yeahdongcn

Copy link
Copy Markdown
Collaborator

@Joey-gvwal Please take a look. Thanks!

package root is protected as well. The value adds to the existing system
directory rules and is read at build time.
"""
value = os.environ.get("TORCHADA_EXCLUDE_DIRS", "")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should dependency protection be enabled by default when TORCHADA_EXCLUDE_DIRS is not configured?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System dependency paths remain protected by default. TORCHADA_EXCLUDE_DIRS is additive and only needed for environment-specific paths such as editable torch_musa checkouts.
The current plan is to set TORCHADA_EXCLUDE_DIRS in the build environment of downstream projects that integrate torchada, such as torchvision, because those projects know which editable dependency
directories must be protected. This also avoids requiring frequent torchada version updates whenever downstream dependency layouts change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants