Skip to content

[None][fix] Generate CUTLASS kernel instantiations without installing cutlass_library#16215

Open
lucifer1004 wants to merge 1 commit into
NVIDIA:mainfrom
lucifer1004:fix/cutlass-user-site
Open

[None][fix] Generate CUTLASS kernel instantiations without installing cutlass_library#16215
lucifer1004 wants to merge 1 commit into
NVIDIA:mainfrom
lucifer1004:fix/cutlass-user-site

Conversation

@lucifer1004

@lucifer1004 lucifer1004 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

The cutlass_kernels CMake step made cutlass_library importable for the kernel-instantiation generator by running setup_library.py develop --user at configure time. Under externally managed Python environments (conda/pixi/uv, which commonly set PYTHONNOUSERSITE=1) this is self-defeating — the install writes to the user site that the interpreter then refuses to read, and the generator fails with ModuleNotFoundError: cutlass_library. It also mutates the user's home site-packages (~/.local easy-install path entries) as a side effect of building one checkout, leaking state into every other Python environment of that user.

This change drops the develop-install entirely and runs the generator with PYTHONPATH pointing at the vendored CUTLASS python directory. Same generation output, no installation, no mutation outside the build tree.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Build & Tooling
    • Improved CUTLASS kernel generation setup by loading Python tooling directly from the source tree.
    • Removed the requirement to install CUTLASS Python components into the local environment during configuration.
    • Kernel generation now uses an explicitly configured Python import path for more reliable builds.

… cutlass_library

The kernel-instantiation setup step ran 'setup_library.py develop
--user', writing an egg-link and easy-install.pth entries into the
invoking user's ~/.local site-packages. That location is shared across
every checkout the user builds, so successive builds of different
checkouts silently repoint each other's cutlass_library; and when the
interpreter runs with user site disabled (PYTHONNOUSERSITE=1 — the
default posture of externally managed conda/pixi/uv environments — or
a virtualenv), the install lands somewhere the very same interpreter
refuses to import from, and generate_kernels.py fails with
ModuleNotFoundError. Simply dropping --user is not viable either: a
non-root build against an unwritable system python would then fail.

cutlass_library is a pure-python package that imports straight from
the CUTLASS source tree, and this generation step is its only
consumer, so no install is needed at all: run generate_kernels.py with
PYTHONPATH pointing at the in-tree package. This works identically for
root container builds, non-root bare-metal builds, virtualenvs, and
externally managed environments, and stops mutating global user state
from a configure step.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

CUTLASS kernel generation no longer installs the Python package during CMake configuration. The generation command now sets PYTHONPATH to the CUTLASS source-tree Python directory and documents this import behavior.

Changes

CUTLASS kernel generation

Layer / File(s) Summary
Use CUTLASS directly from the source tree
cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt
Removes the setup_library.py develop --user step and configures generate_kernels.py to import CUTLASS through an explicit source-tree PYTHONPATH.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is specific, concise, and accurately reflects the main change to CUTLASS kernel instantiation generation.
Description check ✅ Passed It explains the problem and fix clearly, but omits the template's Test Coverage and PR Checklist sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt (1)

46-46: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

cmake -E env "PYTHONPATH=..." replaces, not prepends, the existing PYTHONPATH.

This sets PYTHONPATH to only the CUTLASS source-tree dir, discarding any PYTHONPATH the invoking environment already had. If the generation step (or a transitive import in cutlass_library) relies on other entries, those are dropped. Consider preserving them, e.g. --modify PYTHONPATH=path_list_prepend:${cutlass_source_dir}/python (CMake ≥ 3.22) or expanding $ENV{PYTHONPATH}.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt` at line 46, Preserve
the caller’s existing PYTHONPATH in the CMake command invoking the CUTLASS
generation step. Update the environment setup around the relevant custom command
to prepend ${cutlass_source_dir}/python using CMake’s path-list modification
support, or explicitly retain $ENV{PYTHONPATH} for compatibility with older
CMake versions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt`:
- Line 46: Preserve the caller’s existing PYTHONPATH in the CMake command
invoking the CUTLASS generation step. Update the environment setup around the
relevant custom command to prepend ${cutlass_source_dir}/python using CMake’s
path-list modification support, or explicitly retain $ENV{PYTHONPATH} for
compatibility with older CMake versions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: dc07a87c-963e-4dfb-8f8d-736597b7ce87

📥 Commits

Reviewing files that changed from the base of the PR and between 6929451 and 41750d1.

📒 Files selected for processing (1)
  • cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt

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