pytorch - ✅(Solved) Fix `TEST_DEVICE_BIAS` linter scope should be expanded [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#177970Fetched 2026-04-08 01:07:47
View on GitHub
Comments
0
Participants
1
Timeline
25
Reactions
0
Participants
Timeline (top)
subscribed ×13labeled ×5mentioned ×3added_to_project_v2 ×2

PR fix notes

PR #176766: Extend scope of TEST_DEVICE_BIAS linter

Description (problem / solution / changelog)

Stack from ghstack (oldest at bottom):

  • -> #176766

Changed files

  • .lintrunner.toml (modified, +7/-0)
  • tools/linter/adapters/test_device_bias_linter.py (modified, +178/-147)
  • tools/linter/allowlists/test_device_bias.txt (added, +2552/-0)
RAW_BUFFERClick to expand / collapse

Placeholder issue to track as I fill in more details

There is an existing linter that lints any functions decorated with @requires_gpu for hardcoding of cuda or device.

We should expand the scope of this to prevent newly added tests from hardcoding 'cuda' instead of device unless some criteria are met (e.g. perhaps file or directory has cuda in name). There should also be an escape hatch (e.g. #noqa ...).

Some extremely drafty work here https://github.com/pytorch/pytorch/pull/176766

cc @seemethere @malfet @pytorch/pytorch-dev-infra @mruberry

extent analysis

Fix Plan

To expand the scope of the existing linter, we will modify the test_device_bias_linter.py to check for hardcoded 'cuda' strings unless specific criteria are met.

Steps

  • Update the test_device_bias_linter.py to include a check for 'cuda' strings
  • Add an escape hatch using # noqa comments
  • Modify the linter to ignore files or directories with 'cuda' in their name

Example Code

import re

# ...

def _check_cuda_hardcoding(node):
    # Check if node contains hardcoded 'cuda' string
    if re.search(r'\bcuda\b', node.s):
        # Check if file or directory has 'cuda' in name
        if 'cuda' not in node.file.name and 'cuda' not in node.file.dirname:
            # Check for escape hatch
            if not _has_noqa_comment(node):
                yield Error(node, "Hardcoded 'cuda' string found")

def _has_noqa_comment(node):
    # Check if node has a # noqa comment
    for comment in node.comments:
        if '# noqa' in comment.s:
            return True
    return False

Verification

To verify the fix, run the updated linter on the PyTorch codebase and check for errors related to hardcoded 'cuda' strings.

Extra Tips

  • Make sure to test the updated linter thoroughly to avoid false positives or negatives.
  • Consider adding more specific criteria for ignoring files or directories with 'cuda' in their name.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING