Skip to content

Conversation

@sgjzfzzf
Copy link
Contributor

@sgjzfzzf sgjzfzzf commented Jan 16, 2026

The previous implementation of topk will report an warning as

[datetime]  [TileLang:tilelang.env:WARNING]: Loading tilelang libs from dev root: <prefix>/tilelang/build
[datetime]   [TileLang:tilelang.language.v2.builder:WARNING]: Immutable value `pos` is re-bound. If you want to modify its value, please use T.alloc_var to make it a variable!
Stack (most recent call last):
  File "<prefix>/tilelang/examples/deepseek_v32/topk_selector.py", line 274, in <module>
    test_topk_selector()
  File "<prefix>/tilelang/examples/deepseek_v32/topk_selector.py", line 194, in test_topk_selector
    indexes = tl_topk(input, starts, ends, topk)
  File "<prefix>/tilelang/examples/deepseek_v32/topk_selector.py", line 180, in tl_topk
    kernel = tl_topk_impl(topk)
  File "<prefix>/tilelang/tilelang/jit/__init__.py", line 414, in __call__
    kernel = self.compile(*args, **kwargs, **tune_params)
  File "<prefix>/tilelang/tilelang/jit/__init__.py", line 348, in compile
    func = self.get_tir(*args, **kwargs)
  File "<prefix>/tilelang/tilelang/jit/__init__.py", line 296, in get_tir
    tir = self.func(*args, **kwargs)
  File "<prefix>/tilelang/examples/deepseek_v32/topk_selector.py", line 36, in tl_topk_impl
    def tl_topk_kernel(
  File "<prefix>/tilelang/tilelang/language/v2/builder.py", line 1006, in prim_func
    return impl(func) if func is not None else impl
  File "<prefix>/tilelang/tilelang/language/v2/builder.py", line 996, in impl
    ir_gen.gen(builder)(**annot)
  File "<prefix>/tilelang/examples/deepseek_v32/topk_selector.py", line 110, in tl_topk_kernel
    pos = T.atomic_add(s_num_input[0], 1, return_prev=True)
x  [TileLang:tilelang.language.v2.builder:WARNING]: Immutable value `pos` is re-bound. If you want to modify its value, please use T.alloc_var to make it a variable!
Stack (most recent call last):
  File "<prefix>/tilelang/examples/deepseek_v32/topk_selector.py", line 274, in <module>
    test_topk_selector()
  File "<prefix>/tilelang/examples/deepseek_v32/topk_selector.py", line 194, in test_topk_selector
    indexes = tl_topk(input, starts, ends, topk)
  File "<prefix>/tilelang/examples/deepseek_v32/topk_selector.py", line 180, in tl_topk
    kernel = tl_topk_impl(topk)
  File "<prefix>/tilelang/tilelang/jit/__init__.py", line 414, in __call__
    kernel = self.compile(*args, **kwargs, **tune_params)
  File "<prefix>/tilelang/tilelang/jit/__init__.py", line 348, in compile
    func = self.get_tir(*args, **kwargs)
  File "<prefix>/tilelang/tilelang/jit/__init__.py", line 296, in get_tir
    tir = self.func(*args, **kwargs)
  File "<prefix>/tilelang/examples/deepseek_v32/topk_selector.py", line 36, in tl_topk_impl
    def tl_topk_kernel(
  File "<prefix>/tilelang/tilelang/language/v2/builder.py", line 1006, in prim_func
    return impl(func) if func is not None else impl
  File "<prefix>/tilelang/tilelang/language/v2/builder.py", line 996, in impl
    ir_gen.gen(builder)(**annot)
  File "<prefix>/tilelang/examples/deepseek_v32/topk_selector.py", line 171, in tl_topk_kernel
    pos = T.atomic_add(s_num_input[r_idx ^ 1], 1, return_prev=True)

This PR allocates pos as a variable to avoid this warning.

Summary by CodeRabbit

  • Refactor
    • Minor internal code cleanup: added an explicit local declaration with no behavioral or public API changes; no user-facing impact.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions
Copy link

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run pre-commit run --all-files in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 16, 2026

📝 Walkthrough

Walkthrough

Introduces an explicit local integer allocation pos (via T.alloc_var(T.int32)) in tl_topk_kernel, declared before the l_new_topk initialization; no other functional changes.

Changes

Cohort / File(s) Summary
Variable Declaration
examples/deepseek_v32/topk_selector.py
Added explicit local allocation for pos (T.alloc_var(T.int32)) placed before l_new_topk initialization; no other code logic altered

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 I hopped in to tidy the spot,
A tiny nest where pos can plot,
Declared with care, no longer stray,
Now variables rest in order, yay! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing a warning in the deepseek_v32 topk_selector.py file.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@LeiWang1999 LeiWang1999 merged commit f808358 into tile-ai:main Jan 18, 2026
6 checks passed
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