GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||
GeezerVison is showing github.com — [inductor] Drop the dead frame walk in _find_names by HumphreySun98 · Pull Request #192123 · pytorch/pytorch Conversation
|
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/192123
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (3 Unrelated Failures)As of commit 87a653d with merge base 8f988c9 ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
63fbfce to
9424d9f
Compare
|
Note for anyone who saw the first revision: I force-pushed a correction. The original diff made the stack walk work again on 3.13+ (scanning |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@pytorchbot label "topic: not user facing" |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@claude review this |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Claude finished @jansel's task in 36m 12s —— View job Reviewed — the code change is correct, but the new comment makes a claim the code contradicts, and neither new test covers the actual user-visible bug (the Full reviewPR Review: #192123SummaryDeletes a dead Code Quality
TestingNo test covers the behavior the PR set out to fix. The defect is that
RecommendationRequest Changes The deletion is right and I would take it as-is if the comment were accurate. Blocking items are the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
9424d9f to
0eaa3a7
Compare
|
Rebased onto main (0eaa3a7) — #191866 landing put this into conflict, since that PR touched the exact two lines this one deletes. Resolved by keeping the deletion; the resulting @jansel your review bot run was against the pre-rebase commit, but the diff is unchanged apart from that conflict resolution. This one is 0 failures across 210 checks if you want to take it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # dict so gc.get_referrers below can find obj inside it. On 3.13+ | ||
| # f_locals is a fresh write-through proxy (PEP 667) and this loop | ||
| # is a no-op, so function-local names are not discoverable there. | ||
| _ = frame.f_locals |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This smells like a workaround for a GC bug -- where the point of the code is to materialize f_locals. Why is this workaround no longer needed?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@claude go through the history to find when this workaround was added, do we have a test that checks for what this workaround originally was fixing? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Claude finished @jansel's task in 13m 50s —— View job Short answer: no test ever covered the workaround, and I could not reach the introducing commit from this sandbox.
History: not retrieved. This runner has a 20-commit shallow clone and network egress is blocked, so I deliberately did not guess a SHA. One thing I can confirm locally: the explanatory comment above the walk is not original rationale — it was added three days ago by #191866 ( Tests: verified — nothing covered it, in either directionAt the pre-PR commit
Other So: the frame walk was never pinned by a test, and nothing would have caught the On "why is this workaround no longer needed?"Framing it as no longer needed is the weak version of the argument, and I think that is what makes it smell. The stronger claim available from the code is that for the case it looks like it targets, it never worked — it produced a wrong label rather than a missing one:
The load-bearing evidence that this is safe is that 3.13+ has already been running this way. One precision issue I would fix regardless of the outcome. The new comment (and the commit message) claim the walk can only ever surface Suggested way to de-risk this for review: the I did not change any files. · branch |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
0eaa3a7 to
eb5284b
Compare
|
Good question, and the history answers it in a way I did not expect. I have a full clone, so here is what the bot could not fetch. The walk was introduced in #95355 (01c861a, Feb 2023, "Added utilities to instrument kernel bandwidth numbers" — you approved it), in exactly the form you are describing, as a way to make caller frame locals visible to frame = inspect.currentframe() for frame in iter(lambda: frame.f_back, None): frame.f_locals Note what that original does: It was rewritten in #110823 (192477b, Oct 2023, "Enable flake8-bugbear B020 lint") — B020 fires because the loop variable - for frame in iter(lambda: frame.f_back, None): # type: ignore[union-attr] + while frame is not None: frame.f_locals + frame = frame.f_back That rewrite is where So, on "why is this no longer needed": I would put it as two separate claims.
You are right that there is no test pinning any of this in either direction — I checked, there never was one. I have added the missing one: I also softened the comment — the claim that the walk can only surface Rebased onto main after #191866 landed; 2 files, +49/-10, and the earlier CI run was 210 checks with 0 failures. On the bigger cleanup: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@claude review this again; have the prior comments been addressed? do we now have test coverage for the issue the remove code was fixing? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@claude review this again; have the prior comments been addressed? do we now have test coverage for the issue the remove code was fixing? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the approval. One thing before this can land: the force-push that answered your history question reset the workflow-approval gate, so CI has not run on the current commit ( Could you approve the workflow run (bottom of the PR page), or fire |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
_find_names() resolves the name a CachingAutotuner is bound to so that DebugAutotuner can label kernels in bandwidth-profiling output. It walked the stack reading frame.f_locals purely for the side effect of materializing each frame's locals dict, so that the gc.get_referrers() scan below would also see frame locals. That walk only ever contributed noise. The frames it exposes are _find_names' own frame, which binds the kernel to `obj`, and DebugAutotuner.run's frame, which binds it to `self`; inductor's wrapper codegen binds kernels in a module namespace, and that path is found through gc.get_referrers() without any help. The damage is in the case the walk was supposed to help: when a kernel is held only by frame locals, `possible_names` came back as ['obj', 'self'] instead of empty, so the documented fallback to inductor_meta["kernel_name"] was unreachable and max(possible_names, key=len) labelled the kernel "self". CPython 3.13 already removed the walk's effect: under PEP 667 f_locals on an optimized frame returns a fresh write-through proxy that caches nothing and is not a dict, so it is skipped by the isinstance(referrer, dict) filter. Nothing regressed when that happened, and the unbound case started falling back correctly on 3.13+. This change deletes the walk so every supported interpreter behaves the way 3.13 and 3.14 already do. Test Plan: Added test_find_names_ignores_frame_locals and test_find_names_finds_namespace_binding to test/inductor/test_triton_heuristics.py. The first fails on the current implementation on CPython <= 3.12 (returns ['obj', 'self'] rather than []) and passes on 3.13+; the second pins the namespace lookup the fix must preserve. Both are CPU-only. The probe is a user-defined class rather than object(): object() is untracked by gc, so a dict holding one can itself stay untracked and escape gc.get_referrers. This environment cannot build torch, so the behavior was also checked by running the current and patched implementations against a faithful copy of the call shape (a method calling _find_names(self), with the object either bound in a namespace or unbound) under three interpreters: ``` python 3.12.9 before: namespace-bound -> picks 'triton_poi_fused_add_0'; unbound -> picks 'self' after : namespace-bound -> picks 'triton_poi_fused_add_0'; unbound -> falls back python 3.13.14 / 3.14.6 before: namespace-bound -> picks 'triton_poi_fused_add_0'; unbound -> falls back after : namespace-bound -> picks 'triton_poi_fused_add_0'; unbound -> falls back ``` Lint with the CI-pinned ruff 0.14.4: ``` uvx [email protected] check torch/_inductor/runtime/triton_heuristics.py test/inductor/test_triton_heuristics.py --config=pyproject.toml uvx [email protected] format --check torch/_inductor/runtime/triton_heuristics.py test/inductor/test_triton_heuristics.py --config=pyproject.toml ``` Authored with the assistance of an AI coding assistant (Claude).
eb5284b to
87a653d
Compare
|
Rebased onto latest main (87a653d) — it was 50 commits behind and I would rather it not go stale while it waits. Cherry-picked cleanly, no conflicts; still 2 files, +49/-10, lint and The only thing left is the workflow approval. Because I have force-pushed, the fork-PR gate reset and this currently shows just the two always-on checks, so Happy to hold if you would rather I fold the follow-up you mentioned (dropping |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@pytorchbot merge |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
### Background While addressing your review feedback on pytorch#191866, your review bot pointed out that a comment I had added to `_find_names` describes behavior that stopped being true in CPython 3.13 (PEP 667). That was correct — and checking it showed the *code* under the comment has a bug of its own. pytorch#191866 only corrected the wording; this fixes the function. ### The bug `_find_names()` resolves the name a `CachingAutotuner` is bound to, so `DebugAutotuner` can label kernels in bandwidth-profiling output. It walked the stack reading `frame.f_locals` **purely for the side effect** of materializing each frame's locals dict, so that the `gc.get_referrers()` scan below would also see frame locals: ```python frame = inspect.currentframe() while frame is not None: frame.f_locals # side effect: materialize + cache a real dict frame = frame.f_back ``` That walk only ever contributed noise. The frames it exposes are `_find_names`' own frame, which binds the kernel to `obj`, and `DebugAutotuner.run`'s frame, which binds it to `self`. The real name comes from inductor's wrapper codegen binding kernels in a module namespace, and `gc.get_referrers()` finds that on its own. The damage is in exactly the case the walk was supposed to help. When a kernel is held only by frame locals, `possible_names` came back as `['obj', 'self']` rather than empty, so the fallback below it — and the comment explaining that the AOTI lazy-compile path has no module-level name — was **unreachable**, and `max(possible_names, key=len)` labelled the kernel `"self"`. CPython 3.13 already removed the walk's effect: under [PEP 667](https://peps.python.org/pep-0667/), `f_locals` on an optimized frame returns a fresh write-through `FrameLocalsProxy` that caches nothing and is not a `dict`, so it is skipped by the `isinstance(referrer, dict)` filter. Nothing regressed when that happened, and the unbound case started falling back correctly on 3.13+. This PR deletes the walk so every supported interpreter behaves the way 3.13 and 3.14 already do. ### Test plan Added `test_find_names_ignores_frame_locals` and `test_find_names_finds_namespace_binding` to `test/inductor/test_triton_heuristics.py`. The first fails on the current implementation on CPython <= 3.12 (returns `['obj', 'self']` rather than `[]`) and passes on 3.13+; the second pins the namespace lookup the fix must preserve. Both are CPU-only. The probe is a user-defined class rather than `object()`: `object()` is untracked by gc, so a dict holding one can itself stay untracked and escape `gc.get_referrers` — that made the naive version of this test pass on 3.14 but not on 3.12/3.13. My environment cannot build torch, so I also ran the current and patched implementations against a faithful copy of the call shape (a method calling `_find_names(self)`, with the object either bound in a namespace or unbound) under three interpreters: ``` python 3.12.9 before: namespace-bound -> picks 'triton_poi_fused_add_0'; unbound -> picks 'self' after : namespace-bound -> picks 'triton_poi_fused_add_0'; unbound -> falls back python 3.13.14 / 3.14.6 before: namespace-bound -> picks 'triton_poi_fused_add_0'; unbound -> falls back after : namespace-bound -> picks 'triton_poi_fused_add_0'; unbound -> falls back ``` Lint with the CI-pinned ruff 0.14.4 (`ruff check` and `ruff format --check`) passes on both files. A larger cleanup is possible — dropping `_find_names` entirely and always using `inductor_meta["kernel_name"]` — but that changes kernel labels for every profiled run, so I kept this diff to the defect. Happy to do it as a follow-up if you'd prefer. @jansel — follow-up to the finding your bot raised on pytorch#191866. > Authored with the assistance of an AI coding assistant (Claude). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#192123 Approved by: https://github.com/jansel
### Background While addressing your review feedback on pytorch#191866, your review bot pointed out that a comment I had added to `_find_names` describes behavior that stopped being true in CPython 3.13 (PEP 667). That was correct — and checking it showed the *code* under the comment has a bug of its own. pytorch#191866 only corrected the wording; this fixes the function. ### The bug `_find_names()` resolves the name a `CachingAutotuner` is bound to, so `DebugAutotuner` can label kernels in bandwidth-profiling output. It walked the stack reading `frame.f_locals` **purely for the side effect** of materializing each frame's locals dict, so that the `gc.get_referrers()` scan below would also see frame locals: ```python frame = inspect.currentframe() while frame is not None: frame.f_locals # side effect: materialize + cache a real dict frame = frame.f_back ``` That walk only ever contributed noise. The frames it exposes are `_find_names`' own frame, which binds the kernel to `obj`, and `DebugAutotuner.run`'s frame, which binds it to `self`. The real name comes from inductor's wrapper codegen binding kernels in a module namespace, and `gc.get_referrers()` finds that on its own. The damage is in exactly the case the walk was supposed to help. When a kernel is held only by frame locals, `possible_names` came back as `['obj', 'self']` rather than empty, so the fallback below it — and the comment explaining that the AOTI lazy-compile path has no module-level name — was **unreachable**, and `max(possible_names, key=len)` labelled the kernel `"self"`. CPython 3.13 already removed the walk's effect: under [PEP 667](https://peps.python.org/pep-0667/), `f_locals` on an optimized frame returns a fresh write-through `FrameLocalsProxy` that caches nothing and is not a `dict`, so it is skipped by the `isinstance(referrer, dict)` filter. Nothing regressed when that happened, and the unbound case started falling back correctly on 3.13+. This PR deletes the walk so every supported interpreter behaves the way 3.13 and 3.14 already do. ### Test plan Added `test_find_names_ignores_frame_locals` and `test_find_names_finds_namespace_binding` to `test/inductor/test_triton_heuristics.py`. The first fails on the current implementation on CPython <= 3.12 (returns `['obj', 'self']` rather than `[]`) and passes on 3.13+; the second pins the namespace lookup the fix must preserve. Both are CPU-only. The probe is a user-defined class rather than `object()`: `object()` is untracked by gc, so a dict holding one can itself stay untracked and escape `gc.get_referrers` — that made the naive version of this test pass on 3.14 but not on 3.12/3.13. My environment cannot build torch, so I also ran the current and patched implementations against a faithful copy of the call shape (a method calling `_find_names(self)`, with the object either bound in a namespace or unbound) under three interpreters: ``` python 3.12.9 before: namespace-bound -> picks 'triton_poi_fused_add_0'; unbound -> picks 'self' after : namespace-bound -> picks 'triton_poi_fused_add_0'; unbound -> falls back python 3.13.14 / 3.14.6 before: namespace-bound -> picks 'triton_poi_fused_add_0'; unbound -> falls back after : namespace-bound -> picks 'triton_poi_fused_add_0'; unbound -> falls back ``` Lint with the CI-pinned ruff 0.14.4 (`ruff check` and `ruff format --check`) passes on both files. A larger cleanup is possible — dropping `_find_names` entirely and always using `inductor_meta["kernel_name"]` — but that changes kernel labels for every profiled run, so I kept this diff to the defect. Happy to do it as a follow-up if you'd prefer. @jansel — follow-up to the finding your bot raised on pytorch#191866. > Authored with the assistance of an AI coding assistant (Claude). Pull Request resolved: pytorch#192123 Approved by: https://github.com/jansel
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.