Conversation
Signed-off-by: yiliu30 <yi4.liu@intel.com>
Summary of ChangesHello @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 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.
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.
| 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) |
There was a problem hiding this comment.
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:.
| 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" |
| 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) |
There was a problem hiding this comment.
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.
| 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} |
Signed-off-by: yiliu30 <yi4.liu@intel.com>
Signed-off-by: yiliu30 yi4.liu@intel.com