Add cpplint and ruff linter to pre-commit and fix lint violations#2853
Add cpplint and ruff linter to pre-commit and fix lint violations#2853pstjohn wants to merge 2 commits intoNVIDIA:mainfrom
Conversation
Replace pylint with ruff for Python linting in pre-commit config and CI scripts. Keep black as the formatter. Fix all 14 ruff lint violations: - F841: Remove unused variables - F811: Remove unused import shadowed by local definition - F821: Remove erroneous `del` of variables used later (bug fix) - E721: Use `is`/`is not` for type comparisons - PLR1714: Merge duplicate comparisons - PLW0406: Add noqa for intentional self-imports Also adds cpplint to pre-commit Signed-off-by: Peter St. John <pstjohn@nvidia.com>
Greptile SummaryThis PR replaces pylint with ruff for Python linting, adds cpplint as a pre-commit hook, deletes Confidence Score: 5/5Safe to merge — all lint fixes are semantically equivalent transformations with no behavioral changes. All PLR1714, E721, F841, F811, and F821 fixes have been verified as logically equivalent. No P0/P1 issues found. The one remaining comment (stale pylint disable in grouped_linear.py) is a P2 cleanup item that doesn't affect runtime behavior. transformer_engine/pytorch/ops/basic/grouped_linear.py has a lingering stale comment; otherwise no files require special attention.
|
| Filename | Overview |
|---|---|
| .pre-commit-config.yaml | Adds ruff (Python lint) and cpplint (C++/CUDA lint) hooks; existing black formatter and clang-format hooks untouched. The cpplint exclude pattern aligns with CI; the --root flag omission (noted in a prior thread) only affects error-message path formatting. |
| pyproject.toml | Adds comprehensive ruff configuration mirroring the disabled pylint rules; per-file ignores for known re-export patterns (fp8.py, export.py, etc.) are appropriate. |
| transformer_engine/pytorch/distributed.py | Removes the shadowed import of _get_module_fsdp_state from torch.distributed.fsdp._common_utils; the local definition at line 1957 (used at line 2091) correctly takes precedence. |
| transformer_engine/pytorch/attention/dot_product_attention/context_parallel.py | Two PLR1714 fixes merge duplicate window_size equality comparisons into in-membership tests; both are semantically equivalent to the originals. |
| transformer_engine/pytorch/ops/basic/grouped_linear.py | E721 fix replaces type(weight.data) != weight_tensor_type with is not; the now-inert # pylint: disable=unidiomatic-typecheck comment was not removed. |
| transformer_engine/debug/pytorch/debug_quantization.py | PLR1714 fix merges two == API_CALL_MODIFY comparisons into a single in check; semantically equivalent. Several # pylint: disable= comments remain but are now inert. |
| transformer_engine/pytorch/ops/fused/forward_linear_bias_activation.py | F841 fix replaces the dead activation_op = None assignment with a pass comment; no behavioral change. |
| transformer_engine/debug/features/_test_dummy_feature.py | PLW0406 suppressed with # noqa: PLW0406 for the intentional self-import pattern; both noqa and legacy pylint comments coexist harmlessly. |
| transformer_engine/debug/features/api.py | E721 fix replaces type(ret) == torch.Tensor with is; the inline # pylint: disable=unidiomatic-typecheck was removed along with the refactored expression. |
| transformer_engine/debug/init.py | F841 fix removes unused as e from bare except ImportError clause; no behavioral change. |
| qa/L0_pytorch_lint/test.sh | Replaces pylint with ruff and adds cpplint; pins both to the same versions used in the pre-commit hook. |
| qa/L0_jax_lint/test.sh | Mirrors L0_pytorch_lint changes; installs same cpplint/ruff versions and replaces the pylint invocation with ruff. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Developer commits code] --> B[pre-commit hooks]
B --> C[black\nPython formatter]
B --> D[ruff\nPython linter]
B --> E[cpplint\nC++/CUDA linter]
B --> F[clang-format\nC++ formatter]
B --> G[vermin\nPython version check]
D --> D1["select: E, F, W, PL\nignore: E402, E501, PLR*, PLW*..."]
E --> E1["files: transformer_engine/common|jax|pytorch\nexclude: build_tools/build/"]
B --> H{All checks pass?}
H -- Yes --> I[CI: qa/L0_pytorch_lint/test.sh\nqa/L0_jax_lint/test.sh]
H -- No --> J[Block commit / auto-fix]
I --> I1[cpplint + ruff\npinned to same versions\nas pre-commit]
Reviews (2): Last reviewed commit: "addressing greptile review" | Re-trigger Greptile
Signed-off-by: Peter St. John <pstjohn@nvidia.com>
timmoon10
left a comment
There was a problem hiding this comment.
LGTM, although is there a reason to prefer Ruff over Pylint? Speed?
ksivaman
left a comment
There was a problem hiding this comment.
We should remove all the pylint: disable comments
Yeah pretty much. If we're running it as a pre-commit check it's nice if it's fast. But I'm happy to check the pylint version speed that wouldn't require any changes 🤷 |
Replace pylint with ruff for Python linting in pre-commit config and CI scripts. Keep black as the formatter. Fix all 14 ruff lint violations:
delof variables used later (bug fix)is/is notfor type comparisonsAlso adds cpplint to pre-commit