Repository navigation
Conversation
tools/build_with_debinfo.py recompiles named source files with `-g` to give a
targeted file debug info without a full (slow, ABI-incompatible) debug build.
It derived the compile/link commands from `ninja -j1 -v -n torch_python`
(a dry run) and rewrote `-O2`/`-O3` to `-g`.
That stopped working once the build adopted `file(GLOB ... CONFIGURE_DEPENDS)`.
CONFIGURE_DEPENDS wires a glob-verification step into build.ninja's own
regeneration (CMakeFiles/VerifyGlobs.cmake + regenerate-during-build). In
dry-run mode ninja cannot run that check or reload the regenerated graph, so
`ninja -n <target>` only ever reports the regeneration step and never the real
compile/link commands. The tool parsed an empty plan and printed
"Nothing to do", silently rebuilding nothing.
Source the commands from places the glob-check does not gate:
- the per-file compile command from build/compile_commands.json (rewrite
`-O2`/`-O3` -> `-g`, run in the entry's directory);
- the libtorch_python link command from `ninja -t commands torch_python`
(a graph walk, not a dry run; strip ninja's `: && ... && :` wrapper).
Then symlink build/lib into torch/lib as before.
The tool now rebuilds exactly the files you name plus the relink, instead of
touching sources and relying on ninja's staleness detection. The old
">100 stale items" guard was an artifact of the dry-run approach and is
removed; the tool now requires compile_commands.json and an already-built tree.
Test Plan:
Reproduced on a fresh editable CUDA build of viable/strict: the old tool
no-ops ("Nothing to do"); the new one works.
```
python tools/build_with_debinfo.py --verbose torch/csrc/Module.cpp
```
- torch_python.dir/csrc/Module.cpp.o is recompiled with .debug_info
(was -O2, none before).
- lib/libtorch_python.so is relinked and carries .debug_info.
- torch/lib/libtorch_python.so becomes a symlink into build/lib.
- `import torch` still works (2.13.0a0, cuda True).
Authored with assistance from Claude.
Add a regression guard for the tool in two tiers: - Unit tests (tools/test/test_build_with_debinfo.py) cover the pure plan-derivation helpers: the -O2/-O3 -> -g rewrite, compile_commands.json indexing, the command/arguments entry forms, and the `ninja -t commands` link extraction (including the `: && ... && :` unwrap). They need no build and run on the existing tools test job. - A build-tree smoke check. build_with_debinfo.py gains a --dry-run mode that prints the rebuild plan without compiling/relinking (and skips the is_devel_setup check, since CI build jobs install from a wheel rather than editable). .ci/pytorch/build.sh runs `--dry-run torch/csrc/Module.cpp` after the Linux build, guarded to configs that actually built Module.cpp and have ninja, and asserts the emitted plan contains a -g debug compile and the libtorch_python relink -- not just a zero exit. This exercises the real compile_commands.json and `ninja -t commands` and fails loudly if a future build-system change breaks those data sources or the -g rewrite -- the class of bug (CONFIGURE_DEPENDS) that broke the tool originally and that unit tests alone would not catch. --dry-run only reads the tree, so it does not dirty the checkout (assert_git_not_dirty). Test Plan: ``` python -m pytest tools/test/test_build_with_debinfo.py ``` -> 9 passed. On a real editable CUDA build of viable/strict: ``` python tools/build_with_debinfo.py --dry-run torch/csrc/Module.cpp ``` prints a compile command (with -g) plus the libtorch_python link command and exits 0, leaving the git tree clean; the build.sh `-g` and libtorch_python plan assertions both pass against that output. Authored with assistance from Claude.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/186780
Note: Links to docs will display an error until the docs builds have been completed. ❌ 5 New FailuresAs of commit 03c9084 with merge base 1d81f67 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review |
|
Claude finished @malfet's task in 2m 30s —— View job Code Review: Fix build_with_debinfo.py
Overall: This is a well-written fix. The root cause analysis is clear, the new approach is sound, and the testing strategy covers both unit logic and integration against real build trees. A few observations below: Strengths
Minor Issues / Suggestions
Potential concernThe tool now always calls VerdictThe PR is clean, well-tested, and solves a real breakage. The approach is well-justified in the commit messages and header comment. I'd approve this. The suggestions above are all minor/optional improvements that could be follow-ups. |
benjaminglass1
left a comment
There was a problem hiding this comment.
@zklaus Only one minor bit of feedback, and also a quick question: does this handle builds with USE_RELATIVE_PATHS enabled?
Per benjaminglass1's review on pytorchgh-186780: drop the unnecessary `echo` pipe in the .ci/pytorch/build.sh smoke check in favor of bash here-strings. Authored with assistance from Claude. Co-authored-by: Benjamin Glass <[email protected]>
|
@benjaminglass1, yes — |
|
@zklaus LGTM! |
|
@pytorchbot merge |
Merge failedReason: This PR needs a If not, please add the To add a label, you can comment to pytorchbot, for example For more information, see Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 5 checks: trunk / win-vs2022-cpu-py3 / test (default, 4, 4, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (default, 3, 4, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (default, 2, 4, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (default, 1, 4, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (openreg, 1, 1, windows.4xlarge.nonephemeral) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…ch#186780) ## Summary `tools/build_with_debinfo.py` recompiles named source files with `-g` so you can get debug info for a targeted file without a full (slow, ABI-incompatible) debug build. It is referenced in `CONTRIBUTING.md`, and it broke on current `main`: running it just prints `Nothing to do` and rebuilds nothing. ## Root cause The tool derived its compile/link commands from `ninja -j1 -v -n torch_python` (a dry run) and rewrote `-O2`/`-O3` to `-g`. The build now uses `file(GLOB ... CONFIGURE_DEPENDS)`, which wires a glob-verification step into `build.ninja`'s own regeneration (`CMakeFiles/VerifyGlobs.cmake` + `regenerate-during-build`). In dry-run (`-n`) mode ninja cannot run that check or reload the regenerated graph, so `ninja -n <target>` only ever reports the regeneration step and never the real compile/link commands. The tool parsed an empty plan and no-op'd. ## Fix Source the commands from places the glob-check does not gate: - the per-file compile command from `build/compile_commands.json` (rewrite `-O2`/`-O3` -> `-g`); - the `libtorch_python` link command from `ninja -t commands torch_python` (a graph walk, not a dry run; strip ninja's `: && ... && :` wrapper). Then symlink `build/lib` into `torch/lib` as before. The tool now rebuilds exactly the files you name plus the relink, rather than touching sources and relying on ninja's staleness detection. The old `>100 stale items` guard was a dry-run artifact and is removed; the tool now requires `compile_commands.json` and an already-built tree. ## Tests - **Unit tests** (`tools/test/test_build_with_debinfo.py`) for the pure plan-derivation helpers: the `-O` -> `-g` rewrite, `compile_commands.json` indexing, the command/arguments entry forms, and the `ninja -t commands` link extraction. - **Build-tree smoke check**: a new `--dry-run` mode plus a step in `.ci/pytorch/build.sh` that, after the Linux build, asserts the emitted plan contains a `-g` compile and the `libtorch_python` relink. This exercises the real `compile_commands.json` and `ninja -t commands` and fails loudly if a future build-system change breaks those data sources -- the class of bug here, which unit tests alone would not catch. `--dry-run` only reads the tree, so it does not dirty the checkout. ## Test plan Validated on a real editable CUDA build of `viable/strict`: ``` python tools/build_with_debinfo.py --verbose torch/csrc/Module.cpp ``` recompiles `Module.cpp.o` with `.debug_info`, relinks `libtorch_python.so` (which then carries `.debug_info`), symlinks it into `torch/lib`, and `import torch` still works. ``` python tools/build_with_debinfo.py --dry-run torch/csrc/Module.cpp ``` exits 0, prints the plan, and leaves the git tree clean; the build.sh `-g` and `libtorch_python` plan assertions both pass against that output. ``` python -m pytest tools/test/test_build_with_debinfo.py ``` -> 9 passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#186780 Approved by: https://github.com/benjaminglass1, https://github.com/atalman Co-authored-by: Benjamin Glass <[email protected]>
|
@pytorchbot cherry-pick --onto release/2.13 -c critical |
Cherry picking #186780The cherry pick PR is at #188192 and it is recommended to link a critical cherry pick PR with an issue. The following tracker issues are updated: Details for Dev Infra teamRaised by workflow job |
Fix build_with_debinfo.py broken by CONFIGURE_DEPENDS globbing (#186780) ## Summary `tools/build_with_debinfo.py` recompiles named source files with `-g` so you can get debug info for a targeted file without a full (slow, ABI-incompatible) debug build. It is referenced in `CONTRIBUTING.md`, and it broke on current `main`: running it just prints `Nothing to do` and rebuilds nothing. ## Root cause The tool derived its compile/link commands from `ninja -j1 -v -n torch_python` (a dry run) and rewrote `-O2`/`-O3` to `-g`. The build now uses `file(GLOB ... CONFIGURE_DEPENDS)`, which wires a glob-verification step into `build.ninja`'s own regeneration (`CMakeFiles/VerifyGlobs.cmake` + `regenerate-during-build`). In dry-run (`-n`) mode ninja cannot run that check or reload the regenerated graph, so `ninja -n <target>` only ever reports the regeneration step and never the real compile/link commands. The tool parsed an empty plan and no-op'd. ## Fix Source the commands from places the glob-check does not gate: - the per-file compile command from `build/compile_commands.json` (rewrite `-O2`/`-O3` -> `-g`); - the `libtorch_python` link command from `ninja -t commands torch_python` (a graph walk, not a dry run; strip ninja's `: && ... && :` wrapper). Then symlink `build/lib` into `torch/lib` as before. The tool now rebuilds exactly the files you name plus the relink, rather than touching sources and relying on ninja's staleness detection. The old `>100 stale items` guard was a dry-run artifact and is removed; the tool now requires `compile_commands.json` and an already-built tree. ## Tests - **Unit tests** (`tools/test/test_build_with_debinfo.py`) for the pure plan-derivation helpers: the `-O` -> `-g` rewrite, `compile_commands.json` indexing, the command/arguments entry forms, and the `ninja -t commands` link extraction. - **Build-tree smoke check**: a new `--dry-run` mode plus a step in `.ci/pytorch/build.sh` that, after the Linux build, asserts the emitted plan contains a `-g` compile and the `libtorch_python` relink. This exercises the real `compile_commands.json` and `ninja -t commands` and fails loudly if a future build-system change breaks those data sources -- the class of bug here, which unit tests alone would not catch. `--dry-run` only reads the tree, so it does not dirty the checkout. ## Test plan Validated on a real editable CUDA build of `viable/strict`: ``` python tools/build_with_debinfo.py --verbose torch/csrc/Module.cpp ``` recompiles `Module.cpp.o` with `.debug_info`, relinks `libtorch_python.so` (which then carries `.debug_info`), symlinks it into `torch/lib`, and `import torch` still works. ``` python tools/build_with_debinfo.py --dry-run torch/csrc/Module.cpp ``` exits 0, prints the plan, and leaves the git tree clean; the build.sh `-g` and `libtorch_python` plan assertions both pass against that output. ``` python -m pytest tools/test/test_build_with_debinfo.py ``` -> 9 passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: #186780 Approved by: https://github.com/benjaminglass1, https://github.com/atalman (cherry picked from commit 8f9a6c8) Co-authored-by: Klaus Zimmermann <[email protected]> Co-authored-by: Benjamin Glass <[email protected]>
…ch#186780) ## Summary `tools/build_with_debinfo.py` recompiles named source files with `-g` so you can get debug info for a targeted file without a full (slow, ABI-incompatible) debug build. It is referenced in `CONTRIBUTING.md`, and it broke on current `main`: running it just prints `Nothing to do` and rebuilds nothing. ## Root cause The tool derived its compile/link commands from `ninja -j1 -v -n torch_python` (a dry run) and rewrote `-O2`/`-O3` to `-g`. The build now uses `file(GLOB ... CONFIGURE_DEPENDS)`, which wires a glob-verification step into `build.ninja`'s own regeneration (`CMakeFiles/VerifyGlobs.cmake` + `regenerate-during-build`). In dry-run (`-n`) mode ninja cannot run that check or reload the regenerated graph, so `ninja -n <target>` only ever reports the regeneration step and never the real compile/link commands. The tool parsed an empty plan and no-op'd. ## Fix Source the commands from places the glob-check does not gate: - the per-file compile command from `build/compile_commands.json` (rewrite `-O2`/`-O3` -> `-g`); - the `libtorch_python` link command from `ninja -t commands torch_python` (a graph walk, not a dry run; strip ninja's `: && ... && :` wrapper). Then symlink `build/lib` into `torch/lib` as before. The tool now rebuilds exactly the files you name plus the relink, rather than touching sources and relying on ninja's staleness detection. The old `>100 stale items` guard was a dry-run artifact and is removed; the tool now requires `compile_commands.json` and an already-built tree. ## Tests - **Unit tests** (`tools/test/test_build_with_debinfo.py`) for the pure plan-derivation helpers: the `-O` -> `-g` rewrite, `compile_commands.json` indexing, the command/arguments entry forms, and the `ninja -t commands` link extraction. - **Build-tree smoke check**: a new `--dry-run` mode plus a step in `.ci/pytorch/build.sh` that, after the Linux build, asserts the emitted plan contains a `-g` compile and the `libtorch_python` relink. This exercises the real `compile_commands.json` and `ninja -t commands` and fails loudly if a future build-system change breaks those data sources -- the class of bug here, which unit tests alone would not catch. `--dry-run` only reads the tree, so it does not dirty the checkout. ## Test plan Validated on a real editable CUDA build of `viable/strict`: ``` python tools/build_with_debinfo.py --verbose torch/csrc/Module.cpp ``` recompiles `Module.cpp.o` with `.debug_info`, relinks `libtorch_python.so` (which then carries `.debug_info`), symlinks it into `torch/lib`, and `import torch` still works. ``` python tools/build_with_debinfo.py --dry-run torch/csrc/Module.cpp ``` exits 0, prints the plan, and leaves the git tree clean; the build.sh `-g` and `libtorch_python` plan assertions both pass against that output. ``` python -m pytest tools/test/test_build_with_debinfo.py ``` -> 9 passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#186780 Approved by: https://github.com/benjaminglass1, https://github.com/atalman Co-authored-by: Benjamin Glass <[email protected]>
…ch#186780) ## Summary `tools/build_with_debinfo.py` recompiles named source files with `-g` so you can get debug info for a targeted file without a full (slow, ABI-incompatible) debug build. It is referenced in `CONTRIBUTING.md`, and it broke on current `main`: running it just prints `Nothing to do` and rebuilds nothing. ## Root cause The tool derived its compile/link commands from `ninja -j1 -v -n torch_python` (a dry run) and rewrote `-O2`/`-O3` to `-g`. The build now uses `file(GLOB ... CONFIGURE_DEPENDS)`, which wires a glob-verification step into `build.ninja`'s own regeneration (`CMakeFiles/VerifyGlobs.cmake` + `regenerate-during-build`). In dry-run (`-n`) mode ninja cannot run that check or reload the regenerated graph, so `ninja -n <target>` only ever reports the regeneration step and never the real compile/link commands. The tool parsed an empty plan and no-op'd. ## Fix Source the commands from places the glob-check does not gate: - the per-file compile command from `build/compile_commands.json` (rewrite `-O2`/`-O3` -> `-g`); - the `libtorch_python` link command from `ninja -t commands torch_python` (a graph walk, not a dry run; strip ninja's `: && ... && :` wrapper). Then symlink `build/lib` into `torch/lib` as before. The tool now rebuilds exactly the files you name plus the relink, rather than touching sources and relying on ninja's staleness detection. The old `>100 stale items` guard was a dry-run artifact and is removed; the tool now requires `compile_commands.json` and an already-built tree. ## Tests - **Unit tests** (`tools/test/test_build_with_debinfo.py`) for the pure plan-derivation helpers: the `-O` -> `-g` rewrite, `compile_commands.json` indexing, the command/arguments entry forms, and the `ninja -t commands` link extraction. - **Build-tree smoke check**: a new `--dry-run` mode plus a step in `.ci/pytorch/build.sh` that, after the Linux build, asserts the emitted plan contains a `-g` compile and the `libtorch_python` relink. This exercises the real `compile_commands.json` and `ninja -t commands` and fails loudly if a future build-system change breaks those data sources -- the class of bug here, which unit tests alone would not catch. `--dry-run` only reads the tree, so it does not dirty the checkout. ## Test plan Validated on a real editable CUDA build of `viable/strict`: ``` python tools/build_with_debinfo.py --verbose torch/csrc/Module.cpp ``` recompiles `Module.cpp.o` with `.debug_info`, relinks `libtorch_python.so` (which then carries `.debug_info`), symlinks it into `torch/lib`, and `import torch` still works. ``` python tools/build_with_debinfo.py --dry-run torch/csrc/Module.cpp ``` exits 0, prints the plan, and leaves the git tree clean; the build.sh `-g` and `libtorch_python` plan assertions both pass against that output. ``` python -m pytest tools/test/test_build_with_debinfo.py ``` -> 9 passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#186780 Approved by: https://github.com/benjaminglass1, https://github.com/atalman Co-authored-by: Benjamin Glass <[email protected]>
#186780 introduced number of regressions to the logic, namely it only rebuilded one file and assumed its part of torch_python, rendering the tool useless for ATen changes (torch_cpu, torch_cuda) and also compile .metal shaders with line information. Build the plan from Ninja's command graph and transitively run every command that consumes the requested source's outputs. This restores rebuilding through intermediate libraries and custom steps, including Metal commands, while limiting debug flags to the requested source compilation. Extend test accordingly Authored with the assistance of Codex (OpenAI). Pull Request resolved: #192729 Approved by: https://github.com/atalman, https://github.com/albanD ghstack dependencies: #192349
pytorch#186780 introduced number of regressions to the logic, namely it only rebuilded one file and assumed its part of torch_python, rendering the tool useless for ATen changes (torch_cpu, torch_cuda) and also compile .metal shaders with line information. Build the plan from Ninja's command graph and transitively run every command that consumes the requested source's outputs. This restores rebuilding through intermediate libraries and custom steps, including Metal commands, while limiting debug flags to the requested source compilation. Extend test accordingly Authored with the assistance of Codex (OpenAI). Pull Request resolved: pytorch#192729 Approved by: https://github.com/atalman, https://github.com/albanD ghstack dependencies: pytorch#192349
Summary
tools/build_with_debinfo.pyrecompiles named source files with-gso youcan get debug info for a targeted file without a full (slow, ABI-incompatible)
debug build. It is referenced in
CONTRIBUTING.md, and it broke on currentmain: running it just printsNothing to doand rebuilds nothing.Root cause
The tool derived its compile/link commands from
ninja -j1 -v -n torch_python(a dry run) and rewrote
-O2/-O3to-g. The build now usesfile(GLOB ... CONFIGURE_DEPENDS), which wires a glob-verification step intobuild.ninja's own regeneration (CMakeFiles/VerifyGlobs.cmake+regenerate-during-build). In dry-run (-n) mode ninja cannot run that checkor reload the regenerated graph, so
ninja -n <target>only ever reports theregeneration step and never the real compile/link commands. The tool parsed an
empty plan and no-op'd.
Fix
Source the commands from places the glob-check does not gate:
build/compile_commands.json(rewrite-O2/-O3->-g);libtorch_pythonlink command fromninja -t commands torch_python(a graph walk, not a dry run; strip ninja's
: && ... && :wrapper).Then symlink
build/libintotorch/libas before. The tool now rebuildsexactly the files you name plus the relink, rather than touching sources and
relying on ninja's staleness detection. The old
>100 stale itemsguard was adry-run artifact and is removed; the tool now requires
compile_commands.jsonand an already-built tree.
Tests
tools/test/test_build_with_debinfo.py) for the pureplan-derivation helpers: the
-O->-grewrite,compile_commands.jsonindexing, the command/arguments entry forms, and the
ninja -t commandslink extraction.
--dry-runmode plus a step in.ci/pytorch/build.shthat, after the Linux build, asserts the emitted plancontains a
-gcompile and thelibtorch_pythonrelink. This exercises thereal
compile_commands.jsonandninja -t commandsand fails loudly if afuture build-system change breaks those data sources -- the class of bug
here, which unit tests alone would not catch.
--dry-runonly reads thetree, so it does not dirty the checkout.
Test plan
Validated on a real editable CUDA build of
viable/strict:recompiles
Module.cpp.owith.debug_info, relinkslibtorch_python.so(which then carries
.debug_info), symlinks it intotorch/lib, andimport torchstill works.exits 0, prints the plan, and leaves the git tree clean; the build.sh
-gandlibtorch_pythonplan assertions both pass against that output.-> 9 passed.
🤖 Generated with Claude Code