-
Notifications
You must be signed in to change notification settings - Fork 63
fix: fix timeout error in vllmwrapper #143
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @ChenZiHong-Gavin, 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 significantly enhances the reliability of the Highlights
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.
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 timeout mechanism for vLLM generation calls using asyncio.wait_for, which is a good improvement to prevent requests from hanging. The implementation correctly handles timeouts and other exceptions by aborting the vLLM request. My review focuses on improving code maintainability by reducing duplication. I've identified repeated exception handling logic and a larger block of duplicated code for running the generator, and I've provided suggestions for refactoring. I also suggest adding type hints to the new helper method for better code clarity.
| except asyncio.TimeoutError: | ||
| await self.engine.abort(request_id) | ||
| raise | ||
| except asyncio.CancelledError: | ||
| await self.engine.abort(request_id) | ||
| raise | ||
| except Exception as e: | ||
| await self.engine.abort(request_id) | ||
| raise |
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.
Similar to the generate_answer method, this exception handling logic is duplicated. This can be simplified by catching (Exception, asyncio.CancelledError) in a single block.
More importantly, the entire try...except block for running the generator with a timeout is a duplicate of the one in generate_answer. This violates the DRY (Don't Repeat Yourself) principle. To improve maintainability, consider extracting this logic into a private helper method.
| except asyncio.TimeoutError: | |
| await self.engine.abort(request_id) | |
| raise | |
| except asyncio.CancelledError: | |
| await self.engine.abort(request_id) | |
| raise | |
| except Exception as e: | |
| await self.engine.abort(request_id) | |
| raise | |
| except (Exception, asyncio.CancelledError): | |
| await self.engine.abort(request_id) | |
| raise |
| lines.append(prompt) | ||
| return "\n".join(lines) | ||
|
|
||
| async def _consume_generator(self, generator): |
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.
For better code clarity and maintainability, it's good practice to add type hints to method signatures. Since the specific vLLM types are not imported at the module level, using typing.Any is a reasonable approach here.
| async def _consume_generator(self, generator): | |
| async def _consume_generator(self, generator: Any) -> Any: |
| except asyncio.TimeoutError: | ||
| await self.engine.abort(request_id) | ||
| raise | ||
| except asyncio.CancelledError: | ||
| await self.engine.abort(request_id) | ||
| raise | ||
| except Exception as e: | ||
| await self.engine.abort(request_id) | ||
| raise |
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.
The exception handling for TimeoutError, CancelledError, and Exception contains duplicated code (await self.engine.abort(request_id)). You can combine these into a single except block to make the code more concise and maintainable. asyncio.TimeoutError inherits from Exception, while asyncio.CancelledError inherits from BaseException, so catching (Exception, asyncio.CancelledError) covers all intended cases.
| except asyncio.TimeoutError: | |
| await self.engine.abort(request_id) | |
| raise | |
| except asyncio.CancelledError: | |
| await self.engine.abort(request_id) | |
| raise | |
| except Exception as e: | |
| await self.engine.abort(request_id) | |
| raise | |
| except (Exception, asyncio.CancelledError): | |
| await self.engine.abort(request_id) | |
| raise |
No description provided.