Skip to content

Add git submodule update to build_backend.py#3190

Merged
aleozlx merged 2 commits intoflashinfer-ai:mainfrom
kahyunnam:knam/cccl-submodules-update-fix
Apr 30, 2026
Merged

Add git submodule update to build_backend.py#3190
aleozlx merged 2 commits intoflashinfer-ai:mainfrom
kahyunnam:knam/cccl-submodules-update-fix

Conversation

@kahyunnam
Copy link
Copy Markdown
Member

@kahyunnam kahyunnam commented Apr 27, 2026

📌 Description

Follow up to #3158. This adds git submodule update --init --recursive in the jit-cache build_backend.py before AOT compilation begins, ensuring all submodules are populated.

🔍 Related Issues

#3159

🚀 Pull Request Checklist

Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.

✅ Pre-commit Checks

  • I have installed pre-commit by running pip install pre-commit (or used your preferred method).
  • I have installed the hooks with pre-commit install.
  • I have run the hooks manually with pre-commit run --all-files and fixed any reported issues.

If you are unsure about how to set up pre-commit, see the pre-commit documentation.

🧪 Tests

  • Tests have been added or updated as needed.
  • All tests are passing (unittest, etc.).

Reviewer Notes

Summary by CodeRabbit

  • Chores
    • Improved Git submodule handling in the build system to enhance reliability during JIT cache compilation.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

📝 Walkthrough

Walkthrough

The PR modifies the JIT cache compilation process in flashinfer-jit-cache/build_backend.py to explicitly initialize and upgrade Git submodules using git submodule update --init --recursive with strict error checking. It also reorders the computation of project_root and updates the dynamic path loading of the main build_backend.py.

Changes

Cohort / File(s) Summary
Git Submodule Initialization
flashinfer-jit-cache/build_backend.py
Added explicit git submodule update --init --recursive execution with check=True to ensure submodules are initialized/upgraded before JIT cache compilation. Reordered project_root computation earlier in _compile_jit_cache and updated the dynamic module loading path to use the pre-computed project_root variable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

v0.6.10

Suggested reviewers

  • yzh119
  • sricketts
  • yongwww
  • cyx-6
  • bkryu
  • saltyminty

Poem

🐰 A rabbit hops through git submodules deep,
With --init --recursive, a promise to keep,
No broken dependencies, no missing code,
Just smooth compilation down the build road!
Check=True guards the way,
Build success, hip-hip-hooray! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Description check ✅ Passed The pull request description is complete with all required template sections filled out, including a clear description of changes, related issues, and a fully completed checklist.
Title check ✅ Passed The title accurately describes the main change: explicitly adding git submodule update initialization to build_backend.py before AOT compilation.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@kahyunnam kahyunnam changed the title add git submodule update Add git submodule update to build_backend.py Apr 27, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies flashinfer-jit-cache/build_backend.py to automatically initialize and update git submodules during the JIT cache compilation process. The review feedback highlights that running git commands unconditionally may cause build failures in environments where the source is not a git repository (such as source distributions) or where the git executable is missing. It is recommended to check for the existence of the .git directory and implement error handling for the subprocess call.

Comment on lines +85 to +92
# Ensure 3rdparty submodules are populated (may be empty in CI Docker images)
import subprocess

subprocess.run(
["git", "submodule", "update", "--init", "--recursive"],
cwd=str(project_root),
check=True,
)
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.

high

Running git submodule update unconditionally will cause the build to fail when the source is not a git repository (e.g., when installing from a source distribution or a zip archive). It is important to check for the existence of the .git directory before executing git commands. Additionally, wrapping the call in a try-except block ensures that the build doesn't crash if the git executable is missing from the environment.

Suggested change
# Ensure 3rdparty submodules are populated (may be empty in CI Docker images)
import subprocess
subprocess.run(
["git", "submodule", "update", "--init", "--recursive"],
cwd=str(project_root),
check=True,
)
# Ensure 3rdparty submodules are populated (may be empty in CI Docker images)
if (project_root / ".git").exists():
import subprocess
try:
subprocess.run(
["git", "submodule", "update", "--init", "--recursive"],
cwd=str(project_root),
check=True,
)
except (subprocess.CalledProcessError, FileNotFoundError) as e:
print(f"Warning: Failed to update git submodules: {e}")

Copy link
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@flashinfer-jit-cache/build_backend.py`:
- Around line 85-92: The unconditional subprocess.run(["git", ...]) call should
be guarded and should not rely on a PATH-only "git" executable; reuse the
repository existence check already used earlier (the same test that determines
if this source is a git checkout) to skip the submodule update for non-git/sdist
sources, and resolve the git binary with shutil.which before invoking
subprocess.run to avoid Ruff S607; specifically, replace the direct call to
subprocess.run with logic that (1) checks the existing is-git-repo condition or
project_root/.git presence and returns/skip if false, (2) locates the git
executable via shutil.which("git") (or raises/logs a clear error if not found),
and (3) calls subprocess.run using the absolute git path variable instead of the
literal "git" string for the subprocess invocation that updates submodules
(refer to the subprocess.run invocation and the project_root variable in
build_backend.py).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1503a1e2-691b-4bbe-a8fc-e82ec9b5fb56

📥 Commits

Reviewing files that changed from the base of the PR and between f7acd25 and 0512c41.

📒 Files selected for processing (1)
  • flashinfer-jit-cache/build_backend.py

Comment on lines +85 to +92
# Ensure 3rdparty submodules are populated (may be empty in CI Docker images)
import subprocess

subprocess.run(
["git", "submodule", "update", "--init", "--recursive"],
cwd=str(project_root),
check=True,
)
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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "1) Verify current code uses PATH-only git invocation"
rg -n 'subprocess\.run\(\s*\["git",\s*"submodule"' flashinfer-jit-cache/build_backend.py -n -C2 || true

echo
echo "2) Demonstrate git submodule fails outside a git repo"
tmpdir="$(mktemp -d)"
if git -C "$tmpdir" submodule update --init --recursive >"$tmpdir/out.log" 2>&1; then
  echo "Unexpected: command succeeded outside a git repo"
  exit 1
else
  echo "Expected failure:"
  sed -n '1,3p' "$tmpdir/out.log"
fi

Repository: flashinfer-ai/flashinfer

Length of output: 263


🏁 Script executed:

cat -n flashinfer-jit-cache/build_backend.py | sed -n '80,95p'

Repository: flashinfer-ai/flashinfer

Length of output: 801


🏁 Script executed:

# Check where _compile_jit_cache is called
rg -n '_compile_jit_cache' flashinfer-jit-cache/ --type py -B2 -A2

# Check if there are any other references to git in the build
echo "---"
echo "Other git references in build files:"
rg -n 'git' flashinfer-jit-cache/build_backend.py --type py

Repository: flashinfer-ai/flashinfer

Length of output: 1547


🏁 Script executed:

# Check how get_git_version handles non-git scenarios
rg -n 'def get_git_version' --type py -A10

# Check if 3rdparty is included in sdist
ls -la flashinfer-jit-cache/3rdparty/ 2>/dev/null | head -20 || echo "3rdparty dir check failed"

# Check the actual directory structure
find flashinfer-jit-cache -maxdepth 2 -type d -name "3rdparty" -o -name ".gitmodules"

Repository: flashinfer-ai/flashinfer

Length of output: 540


🏁 Script executed:

# Read full get_git_version function
cat build_utils.py | sed -n '24,50p'

# Check .gitmodules
if [ -f .gitmodules ]; then
  echo ".gitmodules exists:"
  cat .gitmodules
else
  echo "No .gitmodules found"
fi

# Check 3rdparty structure
ls -la 3rdparty/ 2>/dev/null | head -20 || echo "3rdparty not found at root"

Repository: flashinfer-ai/flashinfer

Length of output: 1254


Guard submodule update for non-git sources and avoid PATH-only executable lookup.

At lines 88–92, git submodule update ... is unconditional and uses a partial executable path ("git"). This will fail:

  • In sdist builds (non-git checkouts)
  • When git is not in PATH (flagged by Ruff S607)

The codebase already detects git repo existence at lines 57–59. Apply the same pattern here:

Suggested fix
 def _compile_jit_cache(output_dir: Path, verbose: bool = True):
     """Compile AOT modules using flashinfer.aot functions directly."""
     # Get the project root directory
     project_root = Path(__file__).parent.parent
 
     # Ensure 3rdparty submodules are populated (may be empty in CI Docker images)
+    import shutil
     import subprocess
 
-    subprocess.run(
-        ["git", "submodule", "update", "--init", "--recursive"],
-        cwd=str(project_root),
-        check=True,
-    )
+    git_dir = project_root / ".git"
+    if git_dir.exists():
+        git_bin = shutil.which("git")
+        if git_bin is None:
+            raise RuntimeError("git is required to initialize submodules in a git checkout")
+        subprocess.run(
+            [git_bin, "submodule", "update", "--init", "--recursive"],
+            cwd=str(project_root),
+            check=True,
+        )
+    else:
+        required = [
+            project_root / "3rdparty" / "cutlass",
+            project_root / "3rdparty" / "spdlog",
+            project_root / "3rdparty" / "cccl",
+        ]
+        missing = [str(p) for p in required if not p.exists()]
+        if missing:
+            raise RuntimeError(
+                "Missing required 3rdparty dependencies outside git checkout: "
+                + ", ".join(missing)
+            )
🧰 Tools
🪛 Ruff (0.15.12)

[error] 89-89: Starting a process with a partial executable path

(S607)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@flashinfer-jit-cache/build_backend.py` around lines 85 - 92, The
unconditional subprocess.run(["git", ...]) call should be guarded and should not
rely on a PATH-only "git" executable; reuse the repository existence check
already used earlier (the same test that determines if this source is a git
checkout) to skip the submodule update for non-git/sdist sources, and resolve
the git binary with shutil.which before invoking subprocess.run to avoid Ruff
S607; specifically, replace the direct call to subprocess.run with logic that
(1) checks the existing is-git-repo condition or project_root/.git presence and
returns/skip if false, (2) locates the git executable via shutil.which("git")
(or raises/logs a clear error if not found), and (3) calls subprocess.run using
the absolute git path variable instead of the literal "git" string for the
subprocess invocation that updates submodules (refer to the subprocess.run
invocation and the project_root variable in build_backend.py).

Copy link
Copy Markdown
Collaborator

@aleozlx aleozlx left a comment

Choose a reason for hiding this comment

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

lgtm

@aleozlx aleozlx linked an issue Apr 28, 2026 that may be closed by this pull request
@aleozlx aleozlx added the run-ci label Apr 28, 2026
@aleozlx
Copy link
Copy Markdown
Collaborator

aleozlx commented Apr 28, 2026

/bot run

@aleozlx aleozlx added the v0.6.10 release blocker label for 0.6.10 label Apr 28, 2026
@flashinfer-bot
Copy link
Copy Markdown
Collaborator

GitLab MR !616 has been created, and the CI pipeline #49728788 is currently running. I'll report back once the pipeline job completes.

@aleozlx
Copy link
Copy Markdown
Collaborator

aleozlx commented Apr 30, 2026

bot run looks clean

@aleozlx aleozlx enabled auto-merge (squash) April 30, 2026 20:49
@aleozlx aleozlx merged commit b4b6e6f into flashinfer-ai:main Apr 30, 2026
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci v0.6.10 release blocker label for 0.6.10

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]build-flashinfer-jit-cache failed with cuda::fast_mod_div errors

3 participants