Skip to content

[AsyncEngine Refactor 2/N] Remove deprecates from chat template - #4252

Merged
lvhan028 merged 4 commits into
InternLM:mainfrom
lvhan028:refactor-chat-template
Jan 5, 2026
Merged

lvhan028 merged 4 commits into
InternLM:mainfrom
lvhan028:refactor-chat-template

Conversation

@lvhan028

@lvhan028 lvhan028 commented Jan 4, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Removes deprecated chat templates as part of the AsyncEngine refactor series.

Modification

  • Replace best_match_model with get_chat_template cleaner chat template
  • Remove deprecated and obsolete chat template name constants
  • Remove the lmdeploy list CLI command for listing chat templates

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 removes deprecated chat template functionality as part of the AsyncEngine refactor series. The main changes consolidate chat template handling by replacing the best_match_model function with a new get_chat_template function and removing deprecated template names and the CLI list command.

  • Replaced best_match_model() with get_chat_template() for cleaner chat template resolution
  • Removed deprecated and obsolete chat template name constants
  • Removed the lmdeploy list CLI command for listing chat templates

Reviewed changes

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

Show a summary per file
File Description
lmdeploy/model.py Removed deprecated chat template name constants and replaced best_match_model() with get_chat_template() function that provides a cleaner API for template resolution
lmdeploy/serve/async_engine.py Updated to use get_chat_template() and simplified parameter type hints for backend config methods
lmdeploy/cli/cli.py Removed the list subcommand and its parser that was used to display supported chat template names
tests/test_lmdeploy/test_model.py Removed tests for deprecated best_match_model() function and simplified remaining tests to directly use template names
tests/test_lmdeploy/test_vl/test_hf_chat_template.py Simplified to directly use 'hf' chat template instead of calling best_match_model()
tests/test_lmdeploy/test_vl/test_nonhf_chat_template.py Simplified to directly use 'hf' chat template instead of calling best_match_model()

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

Comment thread lmdeploy/serve/async_engine.py Resolved
Comment thread lmdeploy/serve/async_engine.py Resolved
Comment thread lmdeploy/cli/cli.py Resolved

@RunningLeon RunningLeon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@lvhan028
lvhan028 merged commit 0674241 into InternLM:main Jan 5, 2026
oliveagle pushed a commit to oliveagle/lmdeploy that referenced this pull request May 22, 2026
…rnLM#4252)

* Remove deprecates from chat template

* fix typo

* update chat_template doc
lvhan028 pushed a commit that referenced this pull request Jun 26, 2026
…te names (#4690)

* [Bugfix] Fix ImportError in get_chat_template for builtin chat-template names (#4533)

`get_chat_template` (lmdeploy/cli/utils.py) imported
`DEPRECATED_CHAT_TEMPLATE_NAMES` and `REMOVED_CHAT_TEMPLATE_NAMES` from
`lmdeploy.model`, but those lists were removed in #4252 ([AsyncEngine Refactor
2/N] Remove deprecates from chat template). That refactor cleaned up model.py,
cli.py, async_engine.py and the tests, but left the import (and its two guard
blocks) dangling in cli/utils.py.

As a result, passing any builtin chat-template name that is not a file path
(e.g. `--chat-template internlm2`) to `lmdeploy serve api_server` or
`lmdeploy chat` crashed with:

    ImportError: cannot import name 'DEPRECATED_CHAT_TEMPLATE_NAMES' from 'lmdeploy.model'

before reaching the registry validation. Omitting `--chat-template`, or passing
a `.json` file path, returns early, which is why it went unnoticed.

Complete the refactor: drop the dead import and the removed-/deprecated-name
guards, keep the `MODELS` registry check, and remove the now-unused module
logger. Add regression tests in tests/test_lmdeploy/test_utils.py covering a
builtin name, an unregistered name, and the None case.

Co-authored-by: Claude <[email protected]>

* [Bugfix] Address Copilot review: widen type hints and use pytest.raises

- get_chat_template: annotate chat_template/model_path as `str | None`
  (both accept None in CLI flows and tests) and update docstring arg types.
- test_get_chat_template_unregistered_name: replace manual try/except +
  boolean flag with pytest.raises(AssertionError) for clarity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants