Skip to content

[FIX] Derive constexpr names from JITFunction to fix string annotations#330

Open
mark14wu wants to merge 6 commits intomainfrom
fix/constexpr-positional-arg-test
Open

[FIX] Derive constexpr names from JITFunction to fix string annotations#330
mark14wu wants to merge 6 commits intomainfrom
fix/constexpr-positional-arg-test

Conversation

@mark14wu
Copy link
Copy Markdown
Collaborator

@mark14wu mark14wu commented Mar 16, 2026

Summary

  • On Python 3.14+ the AST rewriter double-quotes string annotations (e.g. 'tl.constexpr' becomes "'tl.constexpr'"), causing GridExecutor.constexprs to be empty. This makes constexpr parameters go through _implicit_cvt, turning them into tensors, which then causes tl.arange to raise ValueError: arange's arguments must be of type tl.constexpr.
  • Fix: derive constexpr names from the original JITFunction.params (passed via jit_fn kwarg) instead of relying on self.constexprs from the rewritten function.
  • Add e2e test with string-annotated "tl.constexpr" passed as a positional argument.

Test plan

  • test_constexpr_string_annotation_positional_arg passes with fix, fails without
  • All 29 existing sanitizer e2e tests pass

Verify the sanitizer correctly handles tl.constexpr parameters passed
as positional (non-keyword) arguments to a kernel using tl.arange.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 16, 2026

Sanitizer Performance Benchmark

Benchmark main (min) PR (min) Change
gemm 0.185s 0.183s -1.1%
gemm_oob 0.191s 0.191s -0.0%
indirect_load 0.291s 0.295s +1.4%
nested_loop 0.375s 0.374s -0.3%
block_pointer_loop_advance 0.189s 0.182s -3.6%
liger_jsd 0.150s 0.150s -0.2%
flaggems_layernorm 0.461s 0.458s -0.5%
swiglu 0.185s 0.184s -0.4%
cross_entropy 0.174s 0.173s -0.5%
fused_linear_jsd 0.228s 0.226s -1.1%
Total 2.427s 2.415s -0.5%

Iterations: 1 warmup + 20 measured

On Python 3.14+ the AST rewriter double-quotes string annotations
(e.g. 'tl.constexpr' becomes "'tl.constexpr'"), causing
GridExecutor.constexprs to be empty. This makes constexpr parameters
go through _implicit_cvt, turning them into tensors, which then
causes tl.arange to raise ValueError.

Fix: derive constexpr names from the original JITFunction.params
(passed via jit_fn kwarg) instead of relying on self.constexprs
from the rewritten function.
@mark14wu mark14wu changed the title [TEST] Add e2e test for constexpr positional argument [FIX] Derive constexpr names from JITFunction to fix string annotations Mar 16, 2026
# reliable annotation info. The rewritten function's __annotations__
# can be corrupted on Python 3.14+ (string annotations get
# double-quoted), making self.constexprs unreliable.
if jit_fn is not None and hasattr(jit_fn, "params"):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just keep the code in the if path? That is, only checking jit_fn.params

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For backward compatibility?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — removed the fallback. jit_fn is always passed through kwargs from trace.py:run, so the else branch was dead code. Simplified to just {p.name for p in jit_fn.params if p.is_constexpr}.

Always derive constexpr names from jit_fn.params since jit_fn is
always available in this code path. Addresses review feedback.
jit_fn is None for nested JIT calls and some Autotune paths.
Fall back to self.constexprs when jit_fn is unavailable.
@mark14wu
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ 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".

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.

2 participants