-
Notifications
You must be signed in to change notification settings - Fork 290
[Refactor] Rename cython output to tilelang_cython and relocate its path
#1086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
👋 Hi! Thank you for contributing to the TileLang project. Please remember to run We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀 |
|
Warning Rate limit exceeded@LeiWang1999 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 54 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughRename Cython wrapper artifact and module to Changes
Sequence Diagram(s)sequenceDiagram
participant Env as tilelang/env.py
participant Py as Python runtime
participant Adapter as adapter.py
participant Module as tilelang_cython_wrapper
Env->>Py: for each lib in TL_LIBS\nif lib not in sys.path: sys.path.insert(0, lib)
Note over Py: sys.path now preferrs TL_LIBS entries
Adapter->>Py: import tilelang_cython_wrapper
alt import succeeds
Py->>Adapter: CythonKernelWrapper loaded
else import fails
Py-->>Adapter: ImportError raised
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tilelang/jit/adapter/cython/adapter.py (1)
24-33: Fallback import logic is sound; consider improving error messaging.The nested try-except correctly implements the fallback from the packaged module to the dev build location. The static analysis hint (TRY203) is a false positive—the structure is appropriate for this use case.
However, the final
raisewill only re-raise the secondImportError(fromtilelang_cython_wrapper), potentially hiding issues with the preferred import path. Consider providing a more informative error message that mentions both import attempts.Optional improvement:
try: # Prefer packaged extension under tilelang/ from tilelang.tilelang_cython_wrapper import CythonKernelWrapper except ImportError: try: # Fallback for dev builds where the module sits at the root from tilelang_cython_wrapper import CythonKernelWrapper except ImportError: - # TODO: tolerance a build without cython backend - raise + raise ImportError( + "Failed to import CythonKernelWrapper. " + "Tried: 'tilelang.tilelang_cython_wrapper' and 'tilelang_cython_wrapper'. " + "Ensure the Cython extension is built and installed." + )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
CMakeLists.txt(1 hunks)tilelang/env.py(1 hunks)tilelang/jit/adapter/cython/adapter.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.14.1)
tilelang/jit/adapter/cython/adapter.py
31-33: Remove exception handler; error is immediately re-raised
(TRY203)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Build wheels for Python 3.8 on ubuntu-24.04-arm with CUDA-12.8
- GitHub Check: Build wheels for Python 3.8 on ubuntu-latest with CUDA-12.1
- GitHub Check: Build wheels for Python 3.8 on macos-latest with Metal
- GitHub Check: Quick Lint
🔇 Additional comments (3)
tilelang/env.py (1)
40-42: LGTM! Import path enhancement supports the refactored Cython module.The loop ensures all library paths in
TL_LIBSare available for imports by prepending them tosys.path. This change directly supports the newtilelang_cython_wrappermodule location and complements the fallback import logic inadapter.py.CMakeLists.txt (2)
161-161: LGTM! Build artifact naming is consistent with the new module structure.The Cython compilation output and module name have been updated to
tilelang_cython_wrapper, aligning with the package structure changes and the import logic inadapter.py.Also applies to: 166-167
175-180: LGTM! Installation path correctly places the extension within the package.Installing the Cython wrapper into the
tilelangdirectory ensures the packaged extension can be imported astilelang.tilelang_cython_wrapper, which matches the preferred import path inadapter.py. The fallback import handles development builds where the module may be at the root level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| try: | ||
| # Load cython_wrapper.api3.so in env.py | ||
| from cython_wrapper import CythonKernelWrapper | ||
| from tilelang_cython_wrapper import CythonKernelWrapper | ||
| except ImportError: | ||
| # TODO: tolerance a build without cython backend | ||
| raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Inconsistent with PR objectives: Missing fallback import mechanism.
The PR description states this change should "prefer importing CythonKernelWrapper from tilelang.tilelang_cython_wrapper, with a fallback to the root-level tilelang_cython_wrapper for development builds and varied build environments." However, the code only attempts a single import from tilelang_cython_wrapper and immediately re-raises on failure.
Consider implementing the fallback mechanism for improved robustness across different build configurations:
try:
- from tilelang_cython_wrapper import CythonKernelWrapper
+ from tilelang.tilelang_cython_wrapper import CythonKernelWrapper
except ImportError:
- raise
+ # Fallback for development builds or varied build environments
+ from tilelang_cython_wrapper import CythonKernelWrapperAlternatively, if the fallback is unnecessary and the description is outdated, remove the redundant try-except block:
-try:
- from tilelang_cython_wrapper import CythonKernelWrapper
-except ImportError:
- raise
+from tilelang_cython_wrapper import CythonKernelWrapperPlease verify whether the fallback mechanism is required for the intended build environments.
🏁 Script executed:
#!/bin/bash
# Verify how tilelang_cython_wrapper is installed and whether it's accessible both ways
# Check CMakeLists.txt for module naming and installation paths
rg -n -A5 -B5 'tilelang_cython_wrapper' --type=cmake
# Check if there are other imports of this module in the codebase
rg -n -C3 'from.*tilelang_cython_wrapper.*import|import.*tilelang_cython_wrapper'
# Check env.py to understand how sys.path is modified
fd -e py -x grep -l 'TL_LIBS' {} \; | head -5 | xargs rg -n -C5 'TL_LIBS.*sys.path|sys.path.*TL_LIBS'Length of output: 2074
</shell_scripts_instructions>
🏁 Script executed:
#!/bin/bash
# Search for sys.path manipulation and environment setup
# Check for setup.py or pyproject.toml
fd -e toml -o -e setup.py | head -10
# Search for sys.path additions anywhere in the codebase
rg -n 'sys\.path' --type=py -B2 -A2
# Check tilelang/__init__.py for any path setup
fd tilelang/__init__.py -x cat {}
# Look for env.py files
fd -n env.py -x cat {}Length of output: 5779
🏁 Script executed:
#!/bin/bash
# Get context around TL_LIBS definition
rg -n 'TL_LIBS' tilelang/env.py -B5 -A10
# Check if adapter.py imports env or if there's a dependency chain
rg -n 'import.*env|from.*env' tilelang/jit/adapter/cython/adapter.py -B2 -A2
# Check what imports adapter.py and if they import env
rg -n 'from.*adapter.*import|import.*adapter' --type=py | head -20
# Get the full context of tilelang/__init__.py
cat tilelang/__init__.py 2>/dev/null || echo "tilelang/__init__.py not found"Length of output: 2204
🏁 Script executed:
#!/bin/bash
# Search with correct git/ prefix
grep -rn 'TL_LIBS' git/tilelang/env.py -B5 -A10 2>/dev/null || echo "env.py search failed"
# Check adapter.py imports
grep -n 'import' git/tilelang/jit/adapter/cython/adapter.py | head -20
# Check if tilelang __init__.py exists and what it imports
cat git/tilelang/__init__.py 2>/dev/null | head -50 || echo "__init__.py not found"
# Check cython adapter __init__.py
cat git/tilelang/jit/adapter/cython/__init__.py
# Search for where CythonKernelAdapter is actually used
grep -rn 'CythonKernelAdapter' git/tilelang --include='*.py' | grep -v test | head -10Length of output: 4956
Inconsistent with PR objectives: Missing fallback import mechanism.
The PR description states this change should "prefer importing CythonKernelWrapper from tilelang.tilelang_cython_wrapper, with a fallback to the root-level tilelang_cython_wrapper for development builds and varied build environments." However, the code only attempts a single import from tilelang_cython_wrapper and immediately re-raises on failure.
Based on the codebase analysis:
- CMakeLists.txt installs the module to
DESTINATION tilelang(resulting intilelang/tilelang_cython_wrapper.so) - Development mode adds the
build/directory tosys.pathvia env.py, making the top-level import work temporarily - Production installations place the module in the
tilelangpackage, requiringtilelang.tilelang_cython_wrapperimport path - Current code lacks fallback and will fail in standard installed environments
Implement the described fallback mechanism:
try:
- from tilelang_cython_wrapper import CythonKernelWrapper
+ from tilelang.tilelang_cython_wrapper import CythonKernelWrapper
except ImportError:
- raise
+ # Fallback for development builds with top-level module in build directory
+ from tilelang_cython_wrapper import CythonKernelWrapper📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| try: | |
| # Load cython_wrapper.api3.so in env.py | |
| from cython_wrapper import CythonKernelWrapper | |
| from tilelang_cython_wrapper import CythonKernelWrapper | |
| except ImportError: | |
| # TODO: tolerance a build without cython backend | |
| raise | |
| try: | |
| from tilelang.tilelang_cython_wrapper import CythonKernelWrapper | |
| except ImportError: | |
| # Fallback for development builds with top-level module in build directory | |
| from tilelang_cython_wrapper import CythonKernelWrapper |
🧰 Tools
🪛 Ruff (0.14.1)
26-27: Remove exception handler; error is immediately re-raised
(TRY203)
🤖 Prompt for AI Agents
In tilelang/jit/adapter/cython/adapter.py around lines 24 to 27, replace the
single top-level import with a two-step import: first try "from
tilelang.tilelang_cython_wrapper import CythonKernelWrapper", and if that raises
ImportError fall back to "from tilelang_cython_wrapper import
CythonKernelWrapper"; if both fail re-raise the ImportError (or raise a new
ImportError with a clear message) so both production-installed
(tilelang.tilelang_cython_wrapper) and development/build-time
(tilelang_cython_wrapper) import layouts are supported.
This pull request updates the build and import structure for the Cython extension in the
tilelangpackage to improve packaging consistency and compatibility. The most important changes include renaming and relocating the Cython extension, updating the CMake build process, and ensuring the correct import paths are set at runtime.Build system and packaging updates:
cython_wrappertotilelang_cython_wrapper, and its output location and installation path have been changed to reside within thetilelangpackage directory for better packaging and import consistency. (CMakeLists.txt)Python import logic improvements:
adapter.pyhas been updated to prefer importingCythonKernelWrapperfromtilelang.tilelang_cython_wrapper, with a fallback to the root-leveltilelang_cython_wrapperfor development builds, improving robustness across different build environments. (tilelang/jit/adapter/cython/adapter.py)env.pyscript now ensures all entries inTL_LIBSare added tosys.path, guaranteeing the Cython extension and other dependencies can be imported regardless of their install location. (tilelang/env.py)Summary by CodeRabbit