Skip to content

Conversation

@tongyuantongyu
Copy link
Member

@tongyuantongyu tongyuantongyu commented Sep 19, 2025

Description

  • Use shutil instead of subprocesses to move files around.
  • Don't change file modification time for unchanged files when generating fmha kernels.
  • Update some help string.

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 19, 2025

📝 Walkthrough

Walkthrough

Refactors FMHA CUDA generation in scripts/build_wheel.py: adds shutil-based cleanup, content-aware file moves, output tracking and pruning, uses cwd for build execution, removes os.chdir, adjusts trigger conditions, updates warning messages, and ensures idempotent synchronization of generated headers and .cu files.

Changes

Cohort / File(s) Summary
FMHA build workflow hardening
scripts/build_wheel.py
- Import shutil for filesystem ops
- Replace rm -rf with shutil.rmtree(..., ignore_errors=True)
- Remove os.chdir; run builds with cwd in build_run
- Add move_if_updated(src,dst) for content-aware moves
- Track generated files; prune stale files in fmha_v2_cu_dir
- Trigger generation when fmha_v2_cu_dir missing (via get_binding_type_from_cache), plus existing clean/generate flags
- Ensure setup.py runs with cwd=fmha_v2_dir
- Update user warnings and container image reference

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as Caller
  participant B as get_binding_type_from_cache
  participant G as generate_fmha_cu
  participant R as build_run (cwd=fmha_v2_dir)
  participant FS as Filesystem

  U->>B: Request binding type
  alt fmha_v2_cu_dir missing OR clean/generate_fmha
    B->>G: generate_fmha_cu()
    G->>FS: shutil.rmtree(temp/build dirs, ignore_errors=True)
    G->>R: invoke setup.py build_ext (cwd set)
    R-->>G: build artifacts (generated/*.cu, fmha_cubin.h)
    loop For each generated file
      G->>FS: move_if_updated(src, dst)
      note right of FS: Copy only if content differs
    end
    G->>FS: Prune extraneous files in fmha_v2_cu_dir not in generated set
  else
    B-->>U: Use cache
  end
  B-->>U: Return binding type
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "[None][chore] cleanup build script" is concise, follows the repository's title template, and accurately reflects the primary change set (a cleanup of the build script, notably edits to scripts/build_wheel.py to use shutil, avoid os.chdir, and make FMHA generation more deterministic).
Description Check ✅ Passed The PR description largely follows the repository template: it includes a clear "Description" that explains what and why the changes were made and it includes the PR checklist, but the "Test Coverage" section is left empty and the template title in the body was not populated (the PR metadata shows "[None][chore] cleanup build script"). Because the core change rationale is present and coherent but validation details and an explicit formatted title in the description body are missing, the description is mostly complete but requires a few small additions before review.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
scripts/build_wheel.py (4)

2-2: Update SPDX year to 2025.

Coding guideline requires current year in headers. Please bump 2024 → 2025.

-# SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

20-20: Unify shutil import style.

Both import shutil and from shutil import ... are used. Pick one style for consistency; suggest module-qualified (shutil.copy, shutil.copytree, shutil.rmtree) everywhere.

Also applies to: 30-30


275-287: Ensure destination directory exists before moving.

move_if_updated can fail if dst’s parent directory doesn’t exist (e.g., fresh checkouts). Create it defensively.

 def move_if_updated(src, dst):
+    dst = Path(dst)
+    dst.parent.mkdir(parents=True, exist_ok=True)
-    with open(src, "rb") as f:
+    with open(src, "rb") as f:
         new_content = f.read()
-    try:
-        with open(dst, "rb") as f:
+    try:
+        with open(dst, "rb") as f:
         old_content = f.read()
     except FileNotFoundError:
         old_content = None
 
-    if old_content != new_content:
-        shutil.move(src, dst)
+    if old_content != new_content:
+        shutil.move(src, dst)

Optional: use filecmp.cmp(src, dst, shallow=False) to avoid loading whole files into memory for large artifacts.


289-292: Create cubin output directory before first move.

Ensure cubin_dir exists to avoid FileNotFoundError on first run.

 cubin_dir = project_dir / "cpp/tensorrt_llm/kernels/contextFusedMultiHeadAttention/cubin"
+cubin_dir.mkdir(parents=True, exist_ok=True)
 move_if_updated(fmha_v2_dir / "generated/fmha_cubin.h",
                 cubin_dir / "fmha_cubin.h")
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 451475e and cf7b103.

📒 Files selected for processing (1)
  • scripts/build_wheel.py (5 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Use only spaces, no tabs; indent with 4 spaces.

Files:

  • scripts/build_wheel.py
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.

Files:

  • scripts/build_wheel.py
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).

Files:

  • scripts/build_wheel.py
🪛 Ruff (0.12.2)
scripts/build_wheel.py

300-300: Loop control variable dirs not used within loop body

Rename unused dirs to _dirs

(B007)

⏰ 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). (1)
  • GitHub Check: Pre-commit Check
🔇 Additional comments (4)
scripts/build_wheel.py (4)

270-274: LGTM: safer cleanup + cwd for build.

Replacing shell rm -rf with shutil.rmtree(..., ignore_errors=True) and using cwd=fmha_v2_dir is an improvement.


631-633: LGTM: broader trigger for FMHA generation.

Regenerating when the output dir is missing makes the build more robust.

If CI caches fmha_v2_cu_dir, confirm this doesn’t mask needed regeneration when env toggles (e.g., ENABLE_SM*) change.


156-160: LGTM: clearer NVIDIA PyTorch container guidance.

Updated warning text improves UX.


191-194: LGTM: image reference update.

Switching to jenkins/current_image_tags.properties is appropriate.

Signed-off-by: Yuan Tong <13075180+tongyuantongyu@users.noreply.github.com>
@tongyuantongyu tongyuantongyu force-pushed the ytong/build-wheel-cleanup branch from cf7b103 to 76de255 Compare September 19, 2025 08:19
@tongyuantongyu
Copy link
Member Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19431 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19431 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #14601 completed with status: 'FAILURE'

@tongyuantongyu
Copy link
Member Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19474 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19474 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #14643 completed with status: 'SUCCESS'

Copy link
Collaborator

@joyang-nv joyang-nv left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning up this. Yuan!

@joyang-nv joyang-nv merged commit 51bef1b into NVIDIA:main Sep 24, 2025
5 checks passed
@tongyuantongyu tongyuantongyu deleted the ytong/build-wheel-cleanup branch October 8, 2025 07:56
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.

4 participants