-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Only run get_attr_docs
if generating help text
#23723
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
Conversation
Signed-off-by: Harry Mellor <[email protected]>
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.
Code Review
This pull request aims to optimize startup time by avoiding the extraction of docstrings when not generating help text. While the performance improvement is valuable, the current implementation introduces a critical caching bug by making a cached function's behavior dependent on a global variable (sys.argv
). My review provides a detailed explanation of this bug and a robust solution to fix it, ensuring both performance and correctness.
Signed-off-by: Harry Mellor <[email protected]>
Thank you! |
Hi @hmellor . I was wondering how to measure time like this?
|
I added some temporary logs that I did not commit, the code was: cumulative_time = 0
@functools.lru_cache(maxsize=30)
def _compute_kwargs(cls: ConfigType, needs_help: bool) -> dict[str, Any]:
import time
global cumulative_time
start = time.perf_counter()
# Save time only getting attr docs if we're generating help text
cls_docs = get_attr_docs(cls) if NEEDS_HELP else {}
duration = time.perf_counter() - start
cumulative_time += duration
logger.info(f"Computed kwargs for {cls.__name__} in {duration:.4f}s (cumulative: {cumulative_time:.4f}s)")
... |
RTD docs build currently isn't triggering |
Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
Docs look good again |
Perhaps a follow up but could we also extract this during build time? Because now we pay this cost during vllm help when we could avoid it all together. |
Yeah this could be a build time constant. I'm not sure how it would work though (I've never tried to do it before, I'm sure it can be done) |
Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]> Signed-off-by: Xiao Yu <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
The docstrings for config class attributes are only actually needed if we're generating
--help
text or documentation.This saves 235ms on my machine by completely eliminating the cost of extracting the docstrings on start up.