Skip to content

Add logger_tqdm for integrated progress tracking#2476

Draft
kylesayrs wants to merge 1 commit intomainfrom
logger-tqdm
Draft

Add logger_tqdm for integrated progress tracking#2476
kylesayrs wants to merge 1 commit intomainfrom
logger-tqdm

Conversation

@kylesayrs
Copy link
Copy Markdown
Collaborator

Summary

  • Adds logger_tqdm class that subclasses tqdm.tqdm to redirect progress bar output through the logging system
  • Uses dynamic stack inspection to properly attribute log messages to calling code rather than internal tqdm frames
  • Ensures progress bars are captured in log files and respect logging configuration

Benefits

  • Progress bars now integrate seamlessly with the loguru logging infrastructure
  • Progress updates appear in log files alongside other log messages
  • Maintains proper caller context information in logs

Implementation Details

  • Overrides display() method to pass all messages through logger.info()
  • Dynamically inspects call stack to skip tqdm and logger module frames
  • Falls back to reasonable default depth if user code frame cannot be found

Test Plan

  • Tested basic usage with simple loops
  • Verified nested function contexts show correct caller information
  • Confirmed progress bars integrate with logging output

🤖 Generated with Claude Code

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>
@github-actions
Copy link
Copy Markdown

👋 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.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 tqdm progress bars directly into the application's logs. By creating a specialized logger_tqdm class, progress updates are no longer separate console outputs but become part of the structured log stream, complete with accurate caller context. This change improves the observability and debugging experience by providing a unified record of application execution, including detailed progress information.

Highlights

  • New logger_tqdm class: Added a logger_tqdm class that subclasses tqdm.tqdm to redirect progress bar output through the logging system.
  • Dynamic Stack Inspection: Implemented dynamic stack inspection to properly attribute log messages to the calling code, skipping internal tqdm and logger frames.
  • Integrated Progress Bars: Ensured progress bars are captured in log files and respect the existing logging configuration, providing seamless integration with the loguru logging infrastructure.

🧠 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
  • src/llmcompressor/logger.py
    • Imported the inspect module for stack inspection and tqdm as tqdm_std.
    • Updated the __all__ export list to include the new logger_tqdm class.
    • Implemented the logger_tqdm class, which overrides the display method to send progress messages through logger.info().
    • Added logic within display to dynamically determine the correct call stack depth, ensuring log messages are attributed to the user's code rather than internal tqdm or logger frames.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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
Copy Markdown
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 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.

Comment on lines +189 to +202
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
Copy link
Copy Markdown
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 for finding the user code frame has a couple of areas for improvement:

  1. Fragile Frame Check: Relying on 'tqdm' in filename is 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.
  2. Potential Memory Leak: The inspect.stack() function can create reference cycles with frame objects, potentially leading to memory leaks. The Python documentation for inspect recommends 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

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 16, 2026

The quality checks have failed. Please run make style and make quality under
the root directory to adddress the lint failures. You will need to install the
dev optional install to get the required linting packages:
https://github.com/vllm-project/llm-compressor/blob/main/CONTRIBUTING.md

@kylesayrs kylesayrs marked this pull request as draft March 16, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant