Skip to content

fix(ttnn): import torch inside _create_golden_function_topk (fixes #55212) - #55213

Merged
bbradelTT merged 2 commits into
tenstorrent:mainfrom
Ranjeet2063:fix/ttnn-topk-golden-import-torch
Sep 4, 2026
Merged

bbradelTT merged 2 commits into
tenstorrent:mainfrom
Ranjeet2063:fix/ttnn-topk-golden-import-torch

Conversation

@Ranjeet2063

Copy link
Copy Markdown
Contributor

Problem & Summary

  • Fixes [ttnn]: ttnn.topk's golden function raises NameError: name 'torch' is not defined #55212: ttnn.get_golden_function(ttnn.topk) raised NameError: name 'torch' is not defined because _create_golden_function_topk() in ttnn/ttnn/operations/reduction.py omitted the import torch statement inside the closure.
  • This caused tests/sweep_framework/sweeps/reduction/topk/topk.py to comment out ttnn.get_golden_function(ttnn.topk) with a workaround comment "topk golden function is not working, missing import torch".

Changes Made

  1. ttnn/ttnn/operations/reduction.py: Added import torch inside _create_golden_function_topk(), matching the convention used by _create_golden_function().
  2. tests/sweep_framework/sweeps/reduction/topk/topk.py: Restored the call to ttnn.get_golden_function(ttnn.topk) now that the golden function resolves cleanly.

Verification

  • Static analysis with pyflakes ttnn/ttnn/operations/reduction.py passes with zero undefined names.

Copilot AI balanced review requested due to automatic review settings September 2, 2026 15:20
@Ranjeet2063
Ranjeet2063 requested a review from a team as a code owner September 2, 2026 15:20

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@minaliuTT minaliuTT added pr-complexity:low Complexity Low: Focused, established pattern with simple validation. pr-priority:p1 P1: Materially blocks/threatens/slows a current goal, release, model, KPI, or shared path. pr-risk:medium Risk Medium: Meaningful but contained impact in a subsystem, workflow, model, or team. labels Sep 2, 2026
@Ranjeet2063

Copy link
Copy Markdown
Contributor Author

Synced branch with latest main.

Verification summary:

@bbradelTT
bbradelTT added this pull request to the merge queue Sep 4, 2026
Merged via the queue into tenstorrent:main with commit 18e22fc Sep 4, 2026
171 of 172 checks passed
vmelnykovTT pushed a commit that referenced this pull request Sep 17, 2026
…5212) (#55213)

### Problem & Summary
- Fixes #55212: `ttnn.get_golden_function(ttnn.topk)` raised `NameError:
name 'torch' is not defined` because `_create_golden_function_topk()` in
`ttnn/ttnn/operations/reduction.py` omitted the `import torch` statement
inside the closure.
- This caused `tests/sweep_framework/sweeps/reduction/topk/topk.py` to
comment out `ttnn.get_golden_function(ttnn.topk)` with a workaround
comment `"topk golden function is not working, missing import torch"`.

### Changes Made
1. **`ttnn/ttnn/operations/reduction.py`**: Added `import torch` inside
`_create_golden_function_topk()`, matching the convention used by
`_create_golden_function()`.
2. **`tests/sweep_framework/sweeps/reduction/topk/topk.py`**: Restored
the call to `ttnn.get_golden_function(ttnn.topk)` now that the golden
function resolves cleanly.

### Verification
- Static analysis with `pyflakes ttnn/ttnn/operations/reduction.py`
passes with zero undefined names.
morhimanshu pushed a commit to morhimanshu/tt-metal that referenced this pull request Oct 1, 2026
…nstorrent#55212) (tenstorrent#55213)

### Problem & Summary
- Fixes tenstorrent#55212: `ttnn.get_golden_function(ttnn.topk)` raised `NameError:
name 'torch' is not defined` because `_create_golden_function_topk()` in
`ttnn/ttnn/operations/reduction.py` omitted the `import torch` statement
inside the closure.
- This caused `tests/sweep_framework/sweeps/reduction/topk/topk.py` to
comment out `ttnn.get_golden_function(ttnn.topk)` with a workaround
comment `"topk golden function is not working, missing import torch"`.

### Changes Made
1. **`ttnn/ttnn/operations/reduction.py`**: Added `import torch` inside
`_create_golden_function_topk()`, matching the convention used by
`_create_golden_function()`.
2. **`tests/sweep_framework/sweeps/reduction/topk/topk.py`**: Restored
the call to `ttnn.get_golden_function(ttnn.topk)` now that the golden
function resolves cleanly.

### Verification
- Static analysis with `pyflakes ttnn/ttnn/operations/reduction.py`
passes with zero undefined names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-complexity:low Complexity Low: Focused, established pattern with simple validation. pr-priority:p1 P1: Materially blocks/threatens/slows a current goal, release, model, KPI, or shared path. pr-risk:medium Risk Medium: Meaningful but contained impact in a subsystem, workflow, model, or team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ttnn]: ttnn.topk's golden function raises NameError: name 'torch' is not defined

4 participants