-
Notifications
You must be signed in to change notification settings - Fork 906
Add support for Keye-VL-1_5-8B #5815
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
Conversation
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.
Summary of Changes
Hello @hellopahe, 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 introduces a significant new feature by integrating the Keye-VL-1_5-8B
model into the system. This allows users to leverage this advanced multimodal model for various tasks. The changes encompass updates across documentation, model registration, and utility functions to ensure a smooth and robust integration, enabling the platform to support a wider range of cutting-edge models.
Highlights
- New Model Support: Added comprehensive support for the
Keye-VL-1_5-8B
multimodal large language model, expanding the platform's capabilities. - Documentation Updates: Updated both Chinese and English documentation to include the newly supported
Keye-VL-1_5-8B
model and its associated command-line parameters. - Robust Utility Patching: Improved the
patch_qwen_vl_utils
function to be more resilient, gracefully handling cases where specific attributes or video reader backends might not be present in thevision_process
module. - Core System Integration: Integrated the new model by defining its type, registering its architecture, and associating it with the appropriate template within the system's core model and template management modules.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
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 .gemini/
folder in the base of the repository. Detailed instructions can be found here.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request adds support for the Keye-VL-1_5-8B model. The changes are mostly correct and well-structured, including updates to model constants, architecture registration, and documentation. However, I've identified a critical bug in patch_qwen_vl_utils
where a dictionary is not being populated, and a couple of issues in mllm.py
related to code duplication and an incorrect model architecture reference. Addressing these points will improve the correctness and maintainability of the code.
swift/llm/model/model/qwen.py
Outdated
return _read_video_decord(ele) | ||
|
||
vision_process.VIDEO_READER_BACKENDS['decord'] = _new_read_video_decord | ||
setattr(vision_process, key.upper(), get_env_args(key, type_func, default_value)) |
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.
The res
dictionary is not being populated within the loop. This will cause patch_qwen_vl_utils
to return an empty dictionary, and consequently, processor.global_vars
will be empty. This appears to be a bug.
The previous implementation correctly populated the res
dictionary. I suggest restoring that logic.
setattr(vision_process, key.upper(), get_env_args(key, type_func, default_value)) | |
val = get_env_args(key, type_func, default_value) | |
setattr(vision_process, key.upper(), val) | |
res[key] = val |
swift/llm/template/template/kwai.py
Outdated
|
||
# Register the Keye VL template | ||
register_template(KeyeTemplateMeta(MLLMTemplateType.keye_vl, template_cls=KeyeVLTemplate)) | ||
register_template(KeyeTemplateMeta(MLLMTemplateType.keye_vl_1_5, template_cls=KeyeVLTemplate)) |
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.
If it's the same template, you can reuse/share it — there's no need to register another one.
swift/llm/model/model_arch.py
Outdated
vision_tower='visual', | ||
)) | ||
|
||
register_model_arch( |
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.
If it's the same model_arch, you can reuse/share it — there's no need to register another one.
hello! please run the following commands: 😊 pip install pre-commit
pre-commit run --all-files |
Please refer to the script here and write a test case.😊 https://github.com/modelscope/ms-swift/blob/main/tests/test_align/test_template/test_vision.py |
You can run this file to automatically update the documentation for supported models and datasets: https://github.com/modelscope/ms-swift/blob/main/scripts/utils/run_model_info.py |
/gemini review |
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.
Code Review
This pull request adds support for the Keye-VL-1_5-8B
model. The changes include adding the model type, registering the model, updating documentation, and adding a test case. The changes are well-structured and correct. The refactoring of patch_qwen_vl_utils
for improved robustness is a good enhancement. I have one suggestion to refactor the new test case to reduce code duplication and improve maintainability.
def test_keye_vl_1_5(): | ||
pt_engine = PtEngine('Kwai-Keye/Keye-VL-1_5-8B') | ||
messages = [{'role': 'user', 'content': '<image><image>What is the difference between the two images?'}] | ||
images = [ | ||
'http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/cat.png', | ||
'http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/animal.png' | ||
] | ||
pt_engine.default_template.template_backend = 'swift' | ||
response = _infer_model(pt_engine, messages=messages, images=images) | ||
pt_engine.default_template.template_backend = 'jinja' | ||
response2 = _infer_model(pt_engine, messages=messages, images=images) | ||
assert response == response2 |
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.
This test function is very similar to test_keye_vl
. To improve maintainability and reduce code duplication, you could use pytest.mark.parametrize
to combine them into a single test function. This would also make it easier to add more keye_vl
models in the future.
For example, you could replace both test_keye_vl
and test_keye_vl_1_5
with a single parameterized test:
import pytest
@pytest.mark.parametrize('model_id', [
'Kwai-Keye/Keye-VL-8B-Preview',
'Kwai-Keye/Keye-VL-1_5-8B',
])
def test_keye_vl_models(model_id):
pt_engine = PtEngine(model_id)
messages = [{'role': 'user', 'content': '<image><image>What is the difference between the two images?'}]
images = [
'http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/cat.png',
'http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/animal.png'
]
pt_engine.default_template.template_backend = 'swift'
response = _infer_model(pt_engine, messages=messages, images=images)
pt_engine.default_template.template_backend = 'jinja'
response2 = _infer_model(pt_engine, messages=messages, images=images)
assert response == response2
You may need to add import pytest
at the top of the file.
PR type
PR information
Experiment results
tested with
issue #5788
cc @hjh0119