Skip to content
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

Fix loading pretrained-mm-projector errors under Deepspeed Zero3. #1250

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion llava/model/llava_arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from llava.mm_utils import get_anyres_image_grid_shape

from transformers.integrations import is_deepspeed_zero3_enabled

class LlavaMetaModel:

Expand Down Expand Up @@ -94,7 +95,12 @@ def initialize_vision_modules(self, model_args, fsdp=None):
def get_w(weights, keyword):
return {k.split(keyword + '.')[1]: v for k, v in weights.items() if keyword in k}

self.mm_projector.load_state_dict(get_w(mm_projector_weights, 'mm_projector'))
if is_deepspeed_zero3_enabled():
import deepspeed
with deepspeed.zero.GatheredParameters(self.mm_projector.parameters(), modifier_rank=0):
self.mm_projector.load_state_dict(get_w(mm_projector_weights, 'mm_projector'))
else:
self.mm_projector.load_state_dict(get_w(mm_projector_weights, 'mm_projector'))


def unpad_image(tensor, original_size):
Expand Down