Skip to content
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

[MISC] Rework logger to enable pythonic custom logging configuration to be provided #4273

Merged
merged 9 commits into from
May 2, 2024

Conversation

tdg5
Copy link

@tdg5 tdg5 commented Apr 22, 2024

Rework logger to enable pythonic custom logging configuration to be provided

Moved from #4038 to here

This PR aims to update vllm/logger.py to extend vLLM to give users more ability to inject custom logging configuration in an idiomatic python way via logging.config.dictConfig.

This PR changes existing behavior in a couple of minor ways, but in general aims to keep existing functionality intact such that there will be limited change in behavior if this code is merged. I've added comments to call out changes in behavior with explanations as to why I felt such a change was appropriate. A test was added before rework to ensure consistent behavior, so I'm fairly confidant existing behavior should be conserved.

Checkout examples/logging_configuration.md for some high level coverage of what these changes enable.

I'm open to any thoughts or suggestions y'all might have to offer. Let me know 😁

vllm/logger.py Outdated
_root_logger = logging.getLogger("vllm")
default_log_level = os.getenv("LOG_LEVEL", _root_logger.level)
logger.setLevel(default_log_level)
for handler in _root_logger.handlers:
Copy link
Author

@tdg5 tdg5 Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a change in behavior here! Previously it just gave all loggers the default handler. Now instead it copies them from the root vllm logger.

Again, unless someone is manually adding handlers to the root vllm logger, the new default behavior should match existing behavior.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I have a question here. Do we even need handler + propgate False? If we don't set handler + propgate=True, doesn't it just use the handler from the root logger?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Responded over here: #4273 (comment)

logging_config: Dict = DEFAULT_LOGGING_CONFIG

if VLLM_LOGGING_CONFIG_PATH:
if not path.exists(VLLM_LOGGING_CONFIG_PATH):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the more exceptional route, but we could also silently fail and fallback to default logging config in some of these scenarios.

vllm/logger.py Outdated
logger.propagate = False
return logger

if VLLM_CONFIGURE_LOGGING or VLLM_LOGGING_CONFIG_PATH:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth noting that this logic means that custom logging config can be provided and used even if VLLM_CONFIGURE_LOGGING evaluates to false.

def init_logger(name: str):
# Use the same settings as above for root logger
logger = logging.getLogger(name)
logger.setLevel(os.getenv("LOG_LEVEL", "DEBUG"))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a change in behavior here! Previously, the requested logger's log level would always be configured. Now it is only configured if VLLM_CONFIGURE_LOGGING evaluates to true.

Copy link
Author

@tdg5 tdg5 May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't relevant anymore because descendent loggers are no longer configured, and instead propagate their messages to the root logger that handles logging those messages (or not).

As such, the change in behavior is broader, but should still be fairly consistent since both approaches aimed to mimic the configuration of the root vLLM logger.

@tdg5 tdg5 changed the title Rework logger to enable pythonic custom logging configuration to be provided [MISC] Rework logger to enable pythonic custom logging configuration to be provided Apr 25, 2024
@rkooo567 rkooo567 self-assigned this Apr 30, 2024
Copy link
Collaborator

@rkooo567 rkooo567 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good! I mostly have questions, not blocking comments.

flexibility from:

- vLLM's default logging configuration (least flexible)
- coarse grained custom logging configuration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a simple example or to a link to a relevant subsection here? for coarse grained & fined grained bullet points (the definition is not very straightforward)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried adding some examples of how to use the configs to achieve these states and I think there's now an example for each state. Let me know if that's sufficient. I can definitely add a link related to each option if you think it'd be beneficial. I'm optimistic that the overall scheme is simpler now and it may not be needed.

@@ -0,0 +1,234 @@
# Logging Configuration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love this doc!

vllm/logger.py Outdated
_root_logger = logging.getLogger("vllm")
default_log_level = os.getenv("LOG_LEVEL", _root_logger.level)
logger.setLevel(default_log_level)
for handler in _root_logger.handlers:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I have a question here. Do we even need handler + propgate False? If we don't set handler + propgate=True, doesn't it just use the handler from the root logger?

Copy link
Collaborator

@rkooo567 rkooo567 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM given propagate=True + nit comments are addressed

@tdg5
Copy link
Author

tdg5 commented May 1, 2024

@rkooo567, updates are complete, should you care to re-review at your leisure.

@rkooo567
Copy link
Collaborator

rkooo567 commented May 2, 2024

@simon-mo I think it is good to go!

@simon-mo simon-mo enabled auto-merge (squash) May 2, 2024 00:34
Copy link
Collaborator

@simon-mo simon-mo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stamp

@simon-mo simon-mo merged commit b8afa8b into vllm-project:main May 2, 2024
48 checks passed
robertgshaw2-redhat pushed a commit to neuralmagic/nm-vllm that referenced this pull request May 6, 2024
z103cb pushed a commit to z103cb/opendatahub_vllm that referenced this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants