Skip to content

Multimodal improve #951

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Multimodal improve #951

wants to merge 8 commits into from

Conversation

shihaobai
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 @shihaobai, 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 enhances the multimodal capabilities of the system by introducing an image cache manager and optimizing the inference process for visual models. It also adds a command-line argument to disable the extra process for multimodal, providing flexibility in deployment configurations.

Highlights

  • Image Cache Management: Introduces an ImageCacheManager class to handle GPU and CPU caching of image embeddings, optimizing memory usage for multimodal models.
  • Multimodal Inference Optimization: Integrates the ImageCacheManager into the inference process, allowing the model to retrieve pre-computed image embeddings from the cache, reducing redundant computations.
  • Conditional Visual Model Initialization: Adds logic to initialize the visual model and image cache only when an extra process for the visual model is disabled, providing flexibility in deployment configurations.
  • Command-Line Argument: Adds a command-line argument --disable_extra_process_for_multimodal to control whether an extra process is used for multimodal processing.
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

This pull request introduces improvements for multimodal models, primarily by adding an option to disable the extra process for visual inference. Key changes include the introduction of an ImageCacheManager and conditional logic for handling visual inference.

Review identified potential AttributeError crashes, code duplication, and debugging print statements. Addressing these issues, especially the AttributeError, is recommended.

Comment on lines +10 to +11
self._gpu_cache = dict()
self._cpu_cache = OrderedDict()

Choose a reason for hiding this comment

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

critical

The _max_size attribute is used in the filter method but is not initialized in the __init__ method, which can lead to an AttributeError if filter() is called before set_max_size().

Suggested change
self._gpu_cache = dict()
self._cpu_cache = OrderedDict()
self._gpu_cache = dict()
self._cpu_cache = OrderedDict()
self._max_size = 0

Comment on lines +69 to +70
img_embed = image_cache_manager.get_embed(img["uuid"])
img_weight.append(img_embed.reshape(img["token_num"], -1))

Choose a reason for hiding this comment

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

critical

image_cache_manager.get_embed() can return None. Handle this case to prevent a potential AttributeError on img_embed.reshape().

Suggested change
img_embed = image_cache_manager.get_embed(img["uuid"])
img_weight.append(img_embed.reshape(img["token_num"], -1))
img_embed = image_cache_manager.get_embed(img["uuid"])
if img_embed is None:
raise ValueError(f"Image embedding for uuid {img['uuid']} not found in cache.")
img_weight.append(img_embed.reshape(img["token_num"], -1))

if req.multimodal_params is not None and get_env_start_args().disable_extra_process_for_multimodal:
for img in req.multimodal_params["images"]:
image_uuid_list.append(img["uuid"])
image_cache_manager.filter(image_uuid_list)

Choose a reason for hiding this comment

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

high

The call to image_cache_manager.filter is inside the loop, leading to redundant processing. Move it outside the loop for better efficiency.

Comment on lines +71 to +72
print(self._gpu_cache.keys())
print(self._cpu_cache.keys())

Choose a reason for hiding this comment

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

medium

These print statements are likely for debugging and should be removed or replaced with proper logging.

@@ -16,6 +16,7 @@ def __init__(self, network_config, mode):
self.tp_world_size_ = get_dp_world_size()
self.network_config_ = network_config
self.mode = mode
print(f"tp_rank_: {self.tp_rank_}, tp_world_size_: {self.tp_world_size_}")

Choose a reason for hiding this comment

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

medium

This print statement should be removed or replaced with a proper logger call.

@@ -21,6 +21,7 @@ class ViTTransformerLayerInfer:
def __init__(self, layer_num, network_config, mode=[]):
self.tp_rank_ = get_current_rank_in_dp()
self.tp_world_size_ = get_dp_world_size()
print(f"tp_rank_: {self.tp_rank_}, tp_world_size_: {self.tp_world_size_}")

Choose a reason for hiding this comment

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

medium

This print statement should be removed or replaced with a proper logger call.

Comment on lines +190 to +195
elif isinstance(img, dict):
uuids.append(img["uuid"])
image_data = read_shm(get_shm_name_data(img["uuid"]))
image_data = Image.open(BytesIO(image_data))
t = self.load_image_func(image_data, max_num=img["extra_params"]["image_patch_max_num"])
img_tensors.append(t)

Choose a reason for hiding this comment

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

medium

The elif block is nearly identical to the preceding if block. Extract the common logic into a helper function to reduce code duplication.

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