-
Notifications
You must be signed in to change notification settings - Fork 451
[Improvement] Accept chat template string in vLLM models #768
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
[Improvement] Accept chat template string in vLLM models #768
Conversation
Minor improvement following the previous PR (EvolvingLMMs-Lab#652 (comment)). - Add comments and doc - Accept both chat template file path and chat template string
WalkthroughA comprehensive docstring was added to the Changes
Estimated code review effort1 (~4 minutes) Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
lmms_eval/models/vllm.py (1)
33-144: Excellent comprehensive documentation with minor formatting improvements needed.The docstring provides thorough documentation covering all essential aspects of the VLLM class. However, the Python examples could be more Pythonic and better formatted.
Consider these improvements for the examples:
- Python Example 1: (example of passing model specific arguments) - # --------------------- - import subprocess - cmd = [ + Example 1: Passing model-specific arguments + ```python + import subprocess + + cmd = [ "python3", "-m", "lmms_eval", "--model", "vllm", "--model_args", "model_version=meta-llama/Llama-4-Scout-17B-16E-Instruct," "tensor_parallel_size=4," "dtype=bfloat16," "max_model_len=10240," "gpu_memory_utilization=0.9," - 'override_generation_config={"attn_temperature_tuning": true},' # example of passing model specific arguments, JSON string will be parsed automatically + 'override_generation_config={"attn_temperature_tuning": true},' # JSON string will be parsed automatically "enforce_eager=True," "kv_cache_dtype=fp8", "--tasks", - task, # change this to your task + "your_task_name", "--batch_size", "1", "--limit", "10", "--log_samples", "--output_path", "logs", - ] - cmd_result = subprocess.run(cmd, check=False) - # --------------------- + ] + result = subprocess.run(cmd, check=False) + ```
- Load chat template during initialization, supporting both file paths and template strings. - Added error handling for non-existent file paths. - Simplified chat template usage in the chat method.
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.
Bug: Template String Misinterpretation as File Path
The VLLM class's chat_template argument uses a flawed heuristic to distinguish between file paths and template strings. The conditions os.path.sep in chat_template or chat_template.endswith((".jinja", ".jinja2", ".j2")) can cause valid template strings (e.g., those containing path separators or ending with common template extensions) to be incorrectly interpreted as file paths. This results in a FileNotFoundError when the code attempts to open the non-existent "file", making the auto-detection unreliable.
lmms_eval/models/vllm.py#L173-L182
lmms-eval/lmms_eval/models/vllm.py
Lines 173 to 182 in 7b87d91
| # Check if it looks like a file path (contains path separators or has common template extensions) | |
| if os.path.sep in chat_template or chat_template.endswith((".jinja", ".jinja2", ".j2")): | |
| # It appears to be a file path, so it must exist | |
| if not os.path.isfile(chat_template): | |
| raise FileNotFoundError(f"Chat template file not found: {chat_template}") | |
| with open(chat_template, "r") as f: | |
| self.chat_template = f.read() | |
| else: | |
| # Treat as a template string | |
| self.chat_template = chat_template |
Was this report helpful? Give feedback by reacting with 👍 or 👎
Minor improvement following the previous PR (#652 (comment)).
Summary by CodeRabbit
Documentation
Bug Fixes