-
Notifications
You must be signed in to change notification settings - Fork 267
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
base: main
Are you sure you want to change the base?
Multimodal improve #951
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 @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
-
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 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.
self._gpu_cache = dict() | ||
self._cpu_cache = OrderedDict() |
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 _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()
.
self._gpu_cache = dict() | |
self._cpu_cache = OrderedDict() | |
self._gpu_cache = dict() | |
self._cpu_cache = OrderedDict() | |
self._max_size = 0 |
img_embed = image_cache_manager.get_embed(img["uuid"]) | ||
img_weight.append(img_embed.reshape(img["token_num"], -1)) |
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.
image_cache_manager.get_embed()
can return None
. Handle this case to prevent a potential AttributeError
on img_embed.reshape()
.
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) |
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.
print(self._gpu_cache.keys()) | ||
print(self._cpu_cache.keys()) |
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.
@@ -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_}") |
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.
@@ -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_}") |
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.
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) |
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.