Skip to content

support DART for llava #403

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

Merged
merged 1 commit into from
Jul 10, 2025
Merged

support DART for llava #403

merged 1 commit into from
Jul 10, 2025

Conversation

zhangbilang
Copy link
Collaborator

No description provided.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 @SmudgedWings, 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 the DART token reduction method to the Llava model, allowing for sparsification and potentially improving inference efficiency. It includes a configuration file for specifying DART parameters and integrates the method into the model's forward pass using hooks. Additionally, it improves image token handling in other token reduction methods.

Highlights

  • DART Token Reduction Method: Introduced the DART (Drop Add Recover Tokens) token reduction method for the Llava model, enabling sparsification by selectively pruning less important tokens.
  • Configuration File: Added a configuration file (dart.yml) to specify the parameters for the DART method, such as pruning location, reduction ratio, and pivot tokens.
  • Integration with Llava: Integrated DART into the Llava model by registering reduction modules and adding hooks to the forward pass to enable token pruning during inference.
  • Image Token Handling: Enhanced image token handling in FastV and PyramidDrop by incorporating IMAGE_TOKEN_INDEX from llava.constants.
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.

Footnotes

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces support for the DART token reduction method for Llava models. This includes a new configuration file, the DART implementation, and its integration into the existing framework. The changes also refactor how IMAGE_TOKEN_INDEX is handled in other token reduction methods (FastV, PyramidDrop) for better consistency by centralizing it in the model's pruning configuration.

) - set(image_indices)

valid_indices_list = list(valid_indices)
for item in list(indices_set):

Choose a reason for hiding this comment

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

high

The list valid_indices_list can become empty inside this loop. If it does, valid_vectors on line 225 will be an empty tensor, and cos_sim.topk(...) on line 231 will raise an error. Please add a check at the beginning of the loop to handle this case, for example by breaking out of the loop if valid_indices_list is empty.

valid_vectors,
dim=-1
)
top_k_indices = cos_sim.topk(TOKEN_TOPK).indices

Choose a reason for hiding this comment

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

high

The topk method will raise an error if TOKEN_TOPK is greater than the number of elements in cos_sim. The number of elements in cos_sim depends on len(valid_indices_list), which can be smaller than TOKEN_TOPK. You should ensure that the value passed to topk is not larger than the number of elements in the tensor.

Suggested change
top_k_indices = cos_sim.topk(TOKEN_TOPK).indices
top_k_indices = cos_sim.topk(min(TOKEN_TOPK, cos_sim.shape[0])).indices

reduction_ratio: 0.778
max_num_trunction: 128
pivot_image_token: 4
pivot_text_token : 4

Choose a reason for hiding this comment

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

medium

There is an extra space before the colon. Please remove it for consistency.

        pivot_text_token: 4

@zhangbilang zhangbilang merged commit c70c7f6 into ModelTC:main Jul 10, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants