Add helpful error messages for fast_generate when fast_inference=False#3820
Conversation
When users load a model with fast_inference=False but then try to use vLLM-style arguments with fast_generate, they previously got confusing errors. This adds a wrapper that detects common mistakes and provides helpful guidance: - Using sampling_params: explains to use HF generate args instead - Using lora_request: explains LoRA weights are already merged - Passing text strings: shows how to tokenize input first Changes: - Add make_fast_generate_wrapper to _utils.py - Apply wrapper in llama.py when fast_inference=False - Apply wrapper in vision.py when fast_inference=False
for more information, see https://pre-commit.ci
Summary of ChangesHello @danielhanchen, 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 enhances the user experience by preventing confusing errors when 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. 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 helpful error messages for fast_generate when fast_inference=False, which will significantly improve user experience by guiding them away from common vLLM-style API misuses. The implementation is clean, adding a wrapper function that correctly identifies invalid arguments and provides clear, actionable error messages. The changes are consistently applied across llama.py and vision.py. I have one minor suggestion to improve code conciseness.
| first_arg = args[0] | ||
| is_string_input = False | ||
|
|
||
| if isinstance(first_arg, str): | ||
| is_string_input = True | ||
| elif isinstance(first_arg, (list, tuple)) and len(first_arg) > 0: | ||
| if isinstance(first_arg[0], str): |
There was a problem hiding this comment.
This logic to detect string input can be simplified into a single boolean expression for better readability and conciseness. The current implementation is correct, but a more Pythonic way would be to combine the checks using boolean short-circuiting.
is_string_input = isinstance(first_arg, str) or (
isinstance(first_arg, (list, tuple)) and first_arg and isinstance(first_arg[0], str)
)…apper-helpful-errors Add helpful error messages for fast_generate when fast_inference=False
Summary
When users load a model with
fast_inference=Falsebut then try to use vLLM-style arguments withfast_generate, they previously got confusing errors. This adds a wrapper that detects common mistakes and provides helpful guidance.Error cases handled:
sampling_params: explains to use HuggingFace generate arguments insteadlora_request: explains LoRA weights are already merged into the modelChanges
make_fast_generate_wrapperfunction to_utils.pyllama.pywhenfast_inference=Falsevision.pywhenfast_inference=FalseExample error messages
When using sampling_params:
When passing string input:
Test plan