-
Notifications
You must be signed in to change notification settings - Fork 66
llava_onevision #386
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
llava_onevision #386
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.
Hello @chengtao-lv, 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!
Summary of Changes
Hello! Gemini here, providing a summary of this pull request to help everyone get up to speed quickly.
This pull request, titled "llava_onevision", introduces support for a new model variant, likely related to a "OneVision" version of LLaVA, into the llmc framework. The core changes involve adding a new Python file that implements this model and its evaluation wrapper, integrating it into the model registry, and making minor adjustments in other related modules for compatibility and robustness.
Highlights
- New Model Implementation: A new model class
Llava_OneVisionis added, inheriting fromLlama, specifically designed to integrate a LLaVA 'OneVision' variant. This includes logic for loading the multimodal model, handling its configuration, and extracting vision-related components. - Evaluation Integration: An evaluation wrapper class
Llava_OneVision_Evalis introduced, inheriting fromlmms_eval.models.llava_onevision.Llava_OneVision. This class sets up the model for evaluation using thelmms_evalframework, including handling device placement and distributed training setup viaaccelerate. - Model Registry Update: The new
Llava_OneVisionmodel and its evaluation wrapper are registered in thellmc.utils.registry_factory.MODEL_REGISTRY, making them available for use within the framework. - Robust Import Handling: A
try...exceptblock is added around the import ofQwen2VLVisionBlockin the token reduction module (tome.py) to gracefully handle cases where the requiredtransformersversion might not be installed, logging an informative message instead of crashing. - Sparsification Config Fix: A minor correction is made in the base sparsification logic (
base_blockwise_sparsification.py) to correctly access the 'n_prune_layers' key within the 'weight' section of the sparsity configuration.
Changelog
Click here to see the changelog
- llmc/compression/sparsification/base_blockwise_sparsification.py
- Corrected access to 'n_prune_layers' key within the 'weight' sparsity configuration (line 43).
- llmc/compression/token_reduction/tome.py
- Added
loguru.loggerimport (line 7). - Wrapped
Qwen2VLVisionBlockimport in atry...except ModuleNotFoundErrorblock for graceful failure if the class is not available (lines 10-15).
- Added
- llmc/models/init.py
- Imported the new
Llava_OneVisionmodel (line 14).
- Imported the new
- llmc/models/llava_onevision.py
- Added a new file implementing the
Llava_OneVisionmodel andLlava_OneVision_Evalevaluation wrapper. - Implemented model loading using
load_pretrained_modelfromllava.model.builder. - Configured model parameters including attention implementation based on PyTorch version.
- Integrated with
lmms_evalfor evaluation setup. - Handled distributed training setup using
accelerate.
- Added a new file implementing the
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 is currently in preview and 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 to provide feedback.
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.
A new model arrives,
Vision and text now thrives,
Code flows with grace,
In this digital space,
Through diffs, the engineer strives.
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 introduces support for the Llava_OneVision model, including its definition and evaluation setup. The changes also incorporate a logical correction in base_blockwise_sparsification.py and robust import handling in tome.py. The new model implementation in llava_onevision.py is the main focus. Overall, the additions are clear, but there are opportunities to enhance flexibility, reduce potential side effects, and improve documentation, as detailed in the specific comments.
Summary of Findings
- Hardcoded Configuration Values: The
Llava_OneVisionclass inllava_onevision.pyhardcodesmodel_nameandoverwrite_configvalues. This might limit its flexibility for different LLaVA model variants. Consider making these configurable or deriving them dynamically. - Side Effects on Input Objects: The
Llava_OneVision_Evalclass inllava_onevision.pymodifies its inputllmc_modelby deleting attributes. This side effect can be surprising and may lead to issues if thellmc_modelinstance is used elsewhere. It's generally better to avoid modifying input objects unless explicitly documented and necessary. - Missing Docstrings: The new classes and their primary methods in
llava_onevision.pylack docstrings, which are important for understanding and maintaining the code. Adding them is recommended for improved clarity. - Improved Configuration Access in Sparsification: The change in
llmc/compression/sparsification/base_blockwise_sparsification.pycorrectly refines hown_prune_layersis accessed from the sparsity configuration, making it more consistent and robust. - Robust Optional Dependency Handling: The try-except block added in
llmc/compression/token_reduction/tome.pyforQwen2VLVisionBlockimport is a good practice for handling optional dependencies gracefully.
Merge Readiness
While the core functionality for Llava_OneVision is well-implemented, there are a few areas identified with medium severity that could be improved for better flexibility, clarity, and maintainability, particularly regarding hardcoded configurations, side effects on input objects, and missing docstrings. I recommend addressing these points before merging. As an AI, I am not authorized to approve pull requests; please ensure further review and approval from the team.
| model_name = 'llava_qwen' | ||
|
|
||
| overwrite_config = {} | ||
| overwrite_config['mm_spatial_pool_stride'] = 2 | ||
| overwrite_config['mm_spatial_pool_mode'] = 'bilinear' |
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 model_name is hardcoded to 'llava_qwen' (line 56) and overwrite_config (lines 58-60) also contains hardcoded values (e.g., mm_spatial_pool_stride = 2). Could these fixed values limit the flexibility of Llava_OneVision if it needs to support other LLaVA variants or configurations derived from self.model_path? Perhaps these could be made configurable or dynamically determined?
| del llmc_model.tokenizer | ||
| del llmc_model.image_processor | ||
| del llmc_model.max_length |
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.
Deleting attributes (tokenizer, image_processor, max_length) from the passed llmc_model instance (lines 171-173) introduces a side effect by modifying the input object. This can be unexpected for the caller and might lead to issues if llmc_model is used elsewhere after this call. Is this modification strictly necessary? If these components are needed by Llava_OneVision_Eval, could they be accessed via llmc_model when required, or if copies are made, could the original llmc_model be left unchanged?
|
|
||
|
|
||
| @MODEL_REGISTRY | ||
| class Llava_OneVision(Llama): |
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.
|
|
||
|
|
||
| @MODEL_REGISTRY | ||
| class Llava_OneVision_Eval(LLaVA_OV): |
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.
No description provided.