Skip to content

lint_duplicate_definitions: a decorated def _ binds nothing - #18360

Merged
danielhanchen merged 1 commit into
mainfrom
ci/dup-defs-allow-decorated-underscore
Nov 18, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/dup-defs-allow-decorated-underscore

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

The whole-tree "Duplicate definitions" step in Lint CI fails on main:

duplicate definitions (1):
  unsloth/kernels/dequant_cache.py:740: _ is defined twice (def at line 721, def here)

Every PR's source lint job inherits this (for example the staging runs for #17742 and #18108, both on current main).

Cause

#18285 registers fake (meta) kernels for its two custom ops with the idiom the torch.library docs use:

@torch.library.register_fake("unsloth::nf4_cached_matmul", lib = _LIB)
def _(X, W, ...): ...

@torch.library.register_fake("unsloth::nf4_cached_addmm_", lib = _LIB)
def _(out, X, W, ...): ...

That code is correct. The decorator keeps a reference to each function, and the name _ is never read back, so neither copy is dead. lint_duplicate_definitions.py exists to catch a second copy that silently replaces the first, which is not what happens here. The lint is too broad for this case.

Fix

In scripts/lint_duplicate_definitions.py, a def _ that has at least one decorator binds nothing. This covers register_fake, singledispatch's @f.register def _, and similar registration hooks. The exemption is deliberately narrow:

  • An undecorated def _ defined twice is still a finding.
  • Any other decorated name defined twice is still a finding.

Two self-test cases pin both sides. The docstring's list of carve-outs documents it.

Verification

  • --self-test: 65 cases pass. With the exemption removed, the new decorated _ case fails (self-test FAILED (1 case(s))).
  • Whole tree (unsloth unsloth_cli studio scripts tests cli.py unsloth-cli.py): clean: 6105 file(s) checked. On main the only finding was the one above, so the exemption hides nothing else.
  • tests/test_lint_duplicate_definitions.py: 12 passed. ruff is clean.

#18285 registers two torch.library fake kernels in dequant_cache.py with
the documented @torch.library.register_fake(...) def _(...) idiom. The
whole-tree duplicate-definitions gate in Lint CI reads that as merge
damage and fails on main. The decorator keeps the function and the name
_ is never read back, so neither copy is dead code; exempt a decorated
def _, keep an undecorated duplicate _ a finding, and add both as
self-test cases.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 369a874cfd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-18T16:44:19.717640Z
We couldn’t complete this review. Comment @codex review to try again.
369a874 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen
danielhanchen merged commit 5e677bd into main Nov 18, 2026
@danielhanchen
danielhanchen deleted the ci/dup-defs-allow-decorated-underscore branch November 18, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant