Refactor backend switch logic with support for SGLang and OpenAI backends#2286
Draft
Refactor backend switch logic with support for SGLang and OpenAI backends#2286
Conversation
- Refactored change_accelerator function with cleaner separation of concerns - Added helper functions: _is_base_model, _is_chat_model, _extract_generation_kwargs, _update_abbr, _copy_optional_fields - Added conversion functions for each backend: vllm, lmdeploy, sglang, openai - Support for both base models and chat/instruct models - Updated CLI to support all backends (vllm, lmdeploy, sglang, openai) - Improved code maintainability and extensibility Co-authored-by: tonysy <7881589+tonysy@users.noreply.github.com>
- Updated English documentation to include SGLang and OpenAI backends - Updated Chinese documentation to include SGLang and OpenAI backends - Added installation instructions for all backends - Added usage examples for all backends (vllm, lmdeploy, sglang, openai) Co-authored-by: tonysy <7881589+tonysy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor backend switch logic for improved model support
Refactor backend switch logic with support for SGLang and OpenAI backends
Oct 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR refactors the backend switch logic in OpenCompass to provide better support for multiple inference backends with a cleaner, more maintainable architecture. The refactoring expands backend support from 2 to 5 backends, adds explicit support for base and instruct models, and significantly improves code quality.
Problem Statement
The original
change_accelerator()function inopencompass/utils/run.pyhad several limitations:Solution
1. Modular Architecture
Refactored the monolithic function into a clean, modular structure:
Helper Functions:
_is_base_model()- Detects base model types_is_chat_model()- Detects chat/instruct model types_extract_generation_kwargs()- Normalizes generation parameters_update_abbr()- Updates model abbreviations consistently_copy_optional_fields()- Preserves optional configuration fieldsBackend Conversion Functions:
_convert_to_vllm_base()/_convert_to_vllm_chat()- VLLM backend conversion_convert_to_lmdeploy_base()/_convert_to_lmdeploy_chat()- LMDeploy backend conversion_convert_to_sglang()- SGLang backend conversion (NEW)_convert_to_openai()- OpenAI API backend conversion (NEW)2. Extended Backend Support
Now supports 5 backends (up from 2):
3. Explicit Model Type Support
Clear distinction between model types:
HuggingFaceBaseModel,HuggingFace,HuggingFaceCausalLM,HuggingFaceChatGLM3HuggingFacewithChatTemplate4. Enhanced CLI and Documentation
CLI Updates (
opencompass/cli/main.py):Documentation Updates:
docs/en/advanced_guides/accelerator_intro.md)docs/zh_cn/advanced_guides/accelerator_intro.md)Benefits
For Developers
For Users
-aflag for all backendsFor the Project
Technical Details
Generation Parameters Handling
generation_kwargsdirectlygen_configwith proper defaultsConfiguration Preservation
The refactored code properly preserves:
meta_template(for base models and applicable backends)end_str(for vLLM base models)stop_words(for chat models)Code Quality
✅ Linting: All files pass flake8
✅ Syntax: Python syntax validated
✅ Backward Compatibility: No breaking changes
Example Usage
Converting Base Models
Converting Chat/Instruct Models
Files Changed
opencompass/utils/run.py- Core refactoring (290+ lines added, modular structure)opencompass/cli/main.py- CLI updates for new backendsdocs/en/advanced_guides/accelerator_intro.md- English documentationdocs/zh_cn/advanced_guides/accelerator_intro.md- Chinese documentationTotal: 4 files changed, 369 insertions(+), 133 deletions(-)
Migration Guide
No migration required! The changes are fully backward compatible:
-aflag behavior is unchanged forvllmandlmdeploysglang,openai) are available as additional optionsFuture Enhancements
This refactoring establishes a solid foundation for:
Current Version: OpenCompass 0.5.0
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.