-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Cleanup #20
Merged
Cleanup #20
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,7 @@ lint.ignore = [ | |
"N802", | ||
"N812", | ||
"PD901", | ||
"PLR0911", | ||
"PLR0912", | ||
"PLR0913", | ||
"PLR0915", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,17 +31,49 @@ def format_throughput(throughput: float, std: float | None = None, is_max: bool | |
if std is not None: | ||
formatted = f"{formatted} ± {std:.2f}" | ||
|
||
if is_max: | ||
return f"**{formatted}**" | ||
|
||
return formatted | ||
return f"**{formatted}**" if is_max else formatted | ||
|
||
|
||
def format_time(time_ms: float, std: float | None = None) -> str: | ||
"""Format time value with optional standard deviation.""" | ||
return f"{time_ms:.2f} ± {std:.2f}" if std is not None else f"{time_ms:.2f}" | ||
|
||
|
||
def extract_gpu_info(thread_settings: dict[str, Any]) -> str: | ||
"""Extract GPU information from thread settings.""" | ||
if "pytorch" not in thread_settings: | ||
return "Unknown hardware" | ||
|
||
pytorch_settings = thread_settings["pytorch"] | ||
|
||
# Handle the case where pytorch settings are stored as a string | ||
if isinstance(pytorch_settings, str): | ||
# Try to extract GPU info from the string | ||
if "gpu_available': True" in pytorch_settings: | ||
# Extract GPU name if available | ||
if "gpu_name':" in pytorch_settings: | ||
import re | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (code-quality): Use named expression to simplify assignment and conditional [×3] ( |
||
|
||
gpu_name_match = re.search(r"gpu_name': '([^']+)'", pytorch_settings) | ||
if gpu_name_match: | ||
return gpu_name_match.group(1) | ||
# Extract GPU device if name not available | ||
gpu_device_match = re.search(r"gpu_device': ([^,}]+)", pytorch_settings) | ||
if gpu_device_match: | ||
return f"GPU {gpu_device_match.group(1)}" | ||
return "GPU (details unknown)" | ||
return "GPU (details unknown)" | ||
return "CPU (GPU not available)" | ||
# Handle the case where pytorch settings are a dictionary | ||
if pytorch_settings.get("gpu_available", False): | ||
gpu_name = pytorch_settings.get("gpu_name", None) | ||
if gpu_name: | ||
return gpu_name | ||
gpu_device = pytorch_settings.get("gpu_device", "Unknown") | ||
return f"GPU {gpu_device}" | ||
return "CPU (GPU not available)" | ||
|
||
|
||
def get_hardware_info(results: dict[str, dict[str, Any]]) -> dict[str, str]: | ||
"""Extract hardware information from metadata.""" | ||
hardware_info = {} | ||
|
@@ -59,41 +91,7 @@ def get_hardware_info(results: dict[str, dict[str, Any]]) -> dict[str, str]: | |
|
||
# For GPU-based libraries (Kornia, TorchVision, etc.) | ||
elif "pytorch" in thread_settings: | ||
# Handle the case where pytorch settings are stored as a string | ||
pytorch_settings = thread_settings["pytorch"] | ||
if isinstance(pytorch_settings, str): | ||
# Try to extract GPU info from the string | ||
if "gpu_available': True" in pytorch_settings: | ||
# Extract GPU name if available | ||
if "gpu_name':" in pytorch_settings: | ||
import re | ||
|
||
gpu_name_match = re.search(r"gpu_name': '([^']+)'", pytorch_settings) | ||
if gpu_name_match: | ||
gpu_name = gpu_name_match.group(1) | ||
hardware_info[library] = gpu_name | ||
else: | ||
# Extract GPU device if name not available | ||
gpu_device_match = re.search(r"gpu_device': ([^,}]+)", pytorch_settings) | ||
if gpu_device_match: | ||
gpu_device = gpu_device_match.group(1) | ||
hardware_info[library] = f"GPU {gpu_device}" | ||
else: | ||
hardware_info[library] = "GPU (details unknown)" | ||
else: | ||
hardware_info[library] = "GPU (details unknown)" | ||
else: | ||
hardware_info[library] = "CPU (GPU not available)" | ||
# Handle the case where pytorch settings are a dictionary | ||
elif pytorch_settings.get("gpu_available", False): | ||
gpu_name = pytorch_settings.get("gpu_name", None) | ||
if gpu_name: | ||
hardware_info[library] = gpu_name | ||
else: | ||
gpu_device = pytorch_settings.get("gpu_device", "Unknown") | ||
hardware_info[library] = f"GPU {gpu_device}" | ||
else: | ||
hardware_info[library] = "CPU (GPU not available)" | ||
hardware_info[library] = extract_gpu_info(thread_settings) | ||
else: | ||
hardware_info[library] = "Unknown hardware" | ||
# Default hardware info if thread_settings not found | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
issue (complexity): Consider extracting the regex-based GPU name extraction into its own helper function to simplify the nested conditional logic and improve readability through early returns and reduced nesting depth within the
extract_gpu_info
function, while maintaining all existing functionality.Below is a suggestion to break up the nested logic by extracting the regex-based GPU name extraction into its own helper. This helps flatten conditionals while keeping functionality intact. For example:
Actionable Steps:
extract_gpu_name_from_string
that covers the inline regex matches.These steps help isolate complex parts and improve readability while keeping all existing functionality.