Skip to content

Conversation

@lvhan028
Copy link
Collaborator

Motivation

gemma2 chat template cannot accept system role

Modification

model.py

Copilot AI review requested due to automatic review settings January 19, 2026 06:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to fix the gemma2 chat template to support models that forbid system roles in messages. The changes modify the HFChatTemplate class to gracefully handle such models by falling back to direct message processing when system role injection fails.

Changes:

  • Modified __init__ to only verify user role support instead of storing role instruction attributes
  • Updated messages2prompt to use try-except fallback when models reject system roles
  • Changed _role_instruction to return additional values (messages and prompt)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
lmdeploy/model.py Modified HFChatTemplate class to handle models that don't accept system roles with fallback logic
tests/test_lmdeploy/test_model.py Added test for gemma-2 and gemma-3 models to verify chat template compatibility

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants