-
Notifications
You must be signed in to change notification settings - Fork 531
misc: checksum check when downloading artifacts #1761
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @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
Using Gemini Code AssistThe 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
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 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
|
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.
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.
flashinfer/artifacts.py
Outdated
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 |
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.
The get_checksums
function has a few robustness issues that could lead to unhandled exceptions:
- It doesn't ensure that the parent directories for
checksum_path
exist before attempting to download the file. This will causedownload_file
to fail if the kernel path contains subdirectories. - It doesn't check the return value of
download_file
. If the download fails, the subsequentopen()
call will raise aFileNotFoundError
. - The line
sha256, filename = line.strip().split()
will raise aValueError
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
b918359
to
ecd6648
Compare
2d4aafe
to
0f8289d
Compare
flashinfer/artifacts.py
Outdated
with open(checksum_path, "r") as f: | ||
for line in f: | ||
sha256, filename = line.strip().split() | ||
checksums[kernel + filename] = sha256 |
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.
suggest naming it op (or operation) + filename and avoid overloading word "kernel"
flashinfer/artifacts.py
Outdated
), | ||
] | ||
for kernel in [ | ||
kernels = [ |
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.
same renaming suggestion as above
flashinfer/jit/cubin_loader.py
Outdated
actual_sha = m.hexdigest() | ||
if sha256 == actual_sha: | ||
return cubin | ||
if "checksums" in cubin_path: # checksum file isn't checked |
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.
this is for the checksum file itself or something even so it should be check? didn't understand why something isn't checked
flashinfer/artifacts.py
Outdated
) | ||
CUDNN_SDPA: str = "4c623163877c8fef5751c9c7a59940cd2baae02e/fmha/cudnn/" | ||
DEEPGEMM: str = "51d730202c9eef782f06ecc950005331d85c5d4b/deep-gemm/" | ||
CUDNN_SDPA: str = "9ef9e6243df03ab2c3fca1f0398a38cf1011d1e1/fmha/cudnn/" |
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.
to double check iiuc the change is in the trtllm-gen fmha not cudnn, but correct me if i'm wrong
6b356b3
to
b68772e
Compare
📌 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
pre-commit
by runningpip install pre-commit
(or used your preferred method).pre-commit install
.pre-commit run --all-files
and fixed any reported issues.🧪 Tests
unittest
, etc.).Reviewer Notes