-
-
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
Conversation
Reviewer's Guide by SourceryThis pull request refactors and cleans up code related to GPU information extraction and speedup plot generation. It introduces a new function for extracting GPU information, removes redundant code, improves error handling for empty DataFrames, and adds a pylint ignore rule. Sequence diagram for extracting GPU informationsequenceDiagram
participant compare_video_results
participant thread_settings
compare_video_results->>thread_settings: extract_gpu_info(thread_settings)
alt pytorch in thread_settings
thread_settings->>compare_video_results: pytorch_settings
alt pytorch_settings is string
thread_settings->>compare_video_results: Extract GPU info from string
else pytorch_settings is dictionary
thread_settings->>compare_video_results: Extract GPU info from dictionary
end
compare_video_results-->>compare_video_results: Return GPU information
else
compare_video_results-->>compare_video_results: Return "Unknown hardware"
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @ternaus - I've reviewed your changes - here's some feedback:
Overall Comments:
- The new
extract_gpu_info
function improves code reuse and readability. - Consider adding a default return value to
extract_gpu_info
in case none of the conditions are met.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
||
|
||
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: |
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:
def extract_gpu_name_from_string(pytorch_settings: str) -> str | None:
import re
gpu_name_match = re.search(r"gpu_name': '([^']+)'", pytorch_settings)
if gpu_name_match:
return gpu_name_match.group(1)
gpu_device_match = re.search(r"gpu_device': ([^,}]+)", pytorch_settings)
if gpu_device_match:
return f"GPU {gpu_device_match.group(1)}"
return None
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 string format with early returns
if isinstance(pytorch_settings, str):
if "gpu_available': True" in pytorch_settings:
info = extract_gpu_name_from_string(pytorch_settings)
return info if info else "GPU (details unknown)"
return "CPU (GPU not available)"
# Handle dictionary format
if pytorch_settings.get("gpu_available", False):
gpu_name = pytorch_settings.get("gpu_name")
if gpu_name:
return gpu_name
gpu_device = pytorch_settings.get("gpu_device", "Unknown")
return f"GPU {gpu_device}"
return "CPU (GPU not available)"
Actionable Steps:
- Extract Regex Logic: Create a helper like
extract_gpu_name_from_string
that covers the inline regex matches. - Use Early Returns: Flatten the conditional flow by returning early when possible.
- Keep Functionality: Ensure that all branches remain intact while reducing nesting.
These steps help isolate complex parts and improve readability while keeping all existing functionality.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
issue (code-quality): Use named expression to simplify assignment and conditional [×3] (use-named-expression
)
No description provided.