Add logger_tqdm for integrated progress tracking#2476
Conversation
Implements a tqdm subclass that redirects all progress bar output through logger.info() instead of writing directly to the console. Uses dynamic stack inspection to properly attribute log messages to the calling code rather than internal tqdm frames. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review. Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed. |
Summary of ChangesHello, 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 introduces a significant enhancement to the logging system by integrating Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
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 introduces a logger_tqdm class, which is a commendable approach to integrate tqdm progress bars with the loguru logging system. The use of stack inspection to correctly attribute log messages is a clever solution. My review includes a suggestion to enhance the robustness and memory safety of this stack inspection logic.
| depth = 0 | ||
| this_file = __file__ | ||
| for frame_info in inspect.stack(): | ||
| depth += 1 | ||
| filename = frame_info.filename | ||
| # Skip frames from tqdm package and this logger.py file | ||
| if 'tqdm' in filename or filename == this_file: | ||
| continue | ||
| # Found user code frame | ||
| depth -= 1 | ||
| break | ||
| else: | ||
| # Fallback if we can't find a good frame | ||
| depth = 3 |
There was a problem hiding this comment.
The current implementation for finding the user code frame has a couple of areas for improvement:
- Fragile Frame Check: Relying on
'tqdm' in filenameis not fully robust. It could incorrectly skip frames from user code if their file path contains "tqdm". Checking the frame's module name is a more reliable method. - Potential Memory Leak: The
inspect.stack()function can create reference cycles with frame objects, potentially leading to memory leaks. The Python documentation forinspectrecommends deleting references to the stack trace once you are done with it to prevent this.
I suggest a refactor that prioritizes checking the module name and ensures the stack trace is properly cleaned up using a try...finally block.
depth = 0
this_file = __file__
this_module_name = __name__
stack = inspect.stack()
try:
for frame_info in stack:
depth += 1
module_name = frame_info.frame.f_globals.get("__name__")
if module_name:
if module_name.startswith("tqdm") or module_name == this_module_name:
continue
elif 'tqdm' in frame_info.filename or frame_info.filename == this_file:
continue
# Found user code frame
depth -= 1
break
else:
# Fallback if we can't find a good frame
depth = 3
finally:
# Per inspect docs, del stack to avoid reference cycles with frame objects
del stack|
The quality checks have failed. Please run |
Summary
logger_tqdmclass that subclassestqdm.tqdmto redirect progress bar output through the logging systemBenefits
Implementation Details
display()method to pass all messages throughlogger.info()Test Plan
🤖 Generated with Claude Code