Skip to content

Conversation

jimmyzho
Copy link
Contributor

@jimmyzho jimmyzho commented Sep 23, 2025

📌 Description

checks the sha256 hash when downloading cubins from artifactory, using the generated checksum.txt in each cubin directory.

🔍 Related Issues

🚀 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

Copy link
Contributor

Summary of Changes

Hello @Quackens, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the robustness of artifact downloading by implementing SHA256 checksum verification. By checking the integrity of cubin files against provided checksums, the system ensures that downloaded assets are authentic and untampered, which is crucial for reliable software builds and deployments.

Highlights

  • Checksum Verification: Introduced SHA256 checksum verification for cubin artifacts downloaded from Artifactory, enhancing data integrity and security.
  • Artifact Path Updates: Updated ArtifactPath and MetaInfoHash constants, reflecting new versions or locations of the cubin artifacts.
  • Checksum Retrieval Logic: Added a new get_checksums function to parse checksum.txt files associated with cubin directories.
  • Download Process Integration: Modified the download_artifacts function to utilize the newly retrieved checksums during the download process, ensuring files are validated upon retrieval.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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 introduces a checksum verification mechanism for downloaded artifacts, which is a great improvement for data integrity. The implementation involves fetching checksum files, parsing them, and then using the checksums during the artifact download process. My review focuses on improving the robustness of this new mechanism. I've identified a couple of critical issues where failures in downloading or parsing checksums, or a mismatch between available artifacts and their checksums, could lead to unhandled exceptions and crash the application. The suggested changes will ensure these scenarios are handled gracefully by raising informative errors, making the system more reliable.

Comment on lines 97 to 107
def get_checksums(kernels):
checksums = {}
for kernel in kernels:
uri = FLASHINFER_CUBINS_REPOSITORY + "/" + (kernel + "checksums.txt")
checksum_path = FLASHINFER_CUBIN_DIR / (kernel + "checksums.txt")
download_file(uri, checksum_path)
with open(checksum_path, "r") as f:
for line in f:
sha256, filename = line.strip().split()
checksums[kernel + filename] = sha256
return checksums
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The get_checksums function has a few robustness issues that could lead to unhandled exceptions:

  1. It doesn't ensure that the parent directories for checksum_path exist before attempting to download the file. This will cause download_file to fail if the kernel path contains subdirectories.
  2. It doesn't check the return value of download_file. If the download fails, the subsequent open() call will raise a FileNotFoundError.
  3. The line sha256, filename = line.strip().split() will raise a ValueError if a line in the checksum file is empty or malformed (e.g., doesn't contain exactly two space-separated values).

I suggest replacing the function with a more robust version that addresses these points by creating directories, checking for download success, and safely parsing each line.

def get_checksums(kernels):
    checksums = {}
    for kernel in kernels:
        checksum_filename = kernel + "checksums.txt"
        uri = FLASHINFER_CUBINS_REPOSITORY + "/" + checksum_filename
        checksum_path = FLASHINFER_CUBIN_DIR / checksum_filename
        checksum_path.parent.mkdir(parents=True, exist_ok=True)
        if not download_file(uri, checksum_path):
            raise RuntimeError(f"Failed to download checksum file: {uri}")

        with open(checksum_path, "r") as f:
            for line in f:
                parts = line.strip().split()
                if len(parts) == 2:
                    sha256, filename = parts
                    checksums[kernel + filename] = sha256
                elif line.strip():
                    logger.warning(
                        f"Skipping malformed line in {checksum_path}: '{line.strip()}'"
                    )
    return checksums

@jimmyzho jimmyzho changed the title feat: checksum check when downloading artifacts misc: checksum check when downloading artifacts Sep 24, 2025
@jimmyzho jimmyzho closed this Sep 25, 2025
@jimmyzho jimmyzho reopened this Sep 25, 2025
with open(checksum_path, "r") as f:
for line in f:
sha256, filename = line.strip().split()
checksums[kernel + filename] = sha256
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggest naming it op (or operation) + filename and avoid overloading word "kernel"

),
]
for kernel in [
kernels = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

same renaming suggestion as above

actual_sha = m.hexdigest()
if sha256 == actual_sha:
return cubin
if "checksums" in cubin_path: # checksum file isn't checked
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is for the checksum file itself or something even so it should be check? didn't understand why something isn't checked

)
CUDNN_SDPA: str = "4c623163877c8fef5751c9c7a59940cd2baae02e/fmha/cudnn/"
DEEPGEMM: str = "51d730202c9eef782f06ecc950005331d85c5d4b/deep-gemm/"
CUDNN_SDPA: str = "9ef9e6243df03ab2c3fca1f0398a38cf1011d1e1/fmha/cudnn/"
Copy link
Collaborator

Choose a reason for hiding this comment

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

to double check iiuc the change is in the trtllm-gen fmha not cudnn, but correct me if i'm wrong

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