Skip to content

Conversation

yiliu30
Copy link
Owner

@yiliu30 yiliu30 commented Sep 25, 2025

Signed-off-by: yiliu30 [email protected]

Signed-off-by: yiliu30 <[email protected]>
Copy link
Contributor

Summary of Changes

Hello @yiliu30, 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 enhances the parse_metadata.py example script by introducing more detailed tensor analysis capabilities. It now captures the minimum and maximum values of tensors and specifically tracks and summarizes torch.float8_e4m3fn tensors, providing a clearer overview of their presence and patterns within .safetensors files. This improves the utility of the script for model inspection and analysis, particularly for models utilizing lower-precision data types.

Highlights

  • Tensor Value Extraction: The script now extracts and records the minimum and maximum values for each tensor found within .safetensors files.
  • FP8 Tensor Identification and Summary: Added functionality to specifically identify torch.float8_e4m3fn (FP8) tensors. After processing, it provides a summarized list of these FP8 tensors, generalizing their names by replacing specific layer indices with wildcards (e.g., .0. becomes .*.).
  • CSV Output Enhancement: The generated CSV file now includes two new columns, 'min' and 'max', to store the extracted minimum and maximum values for each tensor.
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 updates the parse_metadata.py script to extract and include the minimum and maximum values of tensors in the output CSV. It also adds logic to identify and print a generalized list of FP8 tensor names. My review focuses on improving the efficiency and robustness of the new code. I've suggested using regular expressions for more efficient string manipulation and refining the error handling to be more explicit and readable.

Comment on lines +26 to +31
tensor_min, tensor_max = "N/A", "N/A"
try:
tensor_min, tensor_max = tensor.min().item(), tensor.max().item()
except:
pass
tensor_min, tensor_max = str(tensor_min), str(tensor_max)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This block for getting min/max values can be simplified. Also, using a bare except is discouraged as it can catch system-level exceptions like KeyboardInterrupt. It's better to handle the success case and the exception case more explicitly to improve readability and robustness. This suggestion refactors the logic to be cleaner and uses except Exception:.

Suggested change
tensor_min, tensor_max = "N/A", "N/A"
try:
tensor_min, tensor_max = tensor.min().item(), tensor.max().item()
except:
pass
tensor_min, tensor_max = str(tensor_min), str(tensor_max)
try:
tensor_min = str(tensor.min().item())
tensor_max = str(tensor.max().item())
except Exception:
tensor_min, tensor_max = "N/A", "N/A"

Comment on lines +51 to +56
filtered_fp8_tensors = set()
for name in fp8_tensors_name:
filtered_name = name
for idx in range(200):
filtered_name = filtered_name.replace(f".{idx}.", ".*.")
filtered_fp8_tensors.add(filtered_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The current implementation with a nested loop to replace layer indices is inefficient as it iterates 200 times for each tensor name. A more efficient and robust approach is to use a regular expression. This can be made even more concise and Pythonic using a set comprehension. This also removes the hardcoded limit of 200 for layer indices.

Note: you will need to add import re at the top of the file.

Suggested change
filtered_fp8_tensors = set()
for name in fp8_tensors_name:
filtered_name = name
for idx in range(200):
filtered_name = filtered_name.replace(f".{idx}.", ".*.")
filtered_fp8_tensors.add(filtered_name)
filtered_fp8_tensors = {re.sub(r'\.\d+\.', '.*.', name) for name in fp8_tensors_name}

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