Skip to content

Commit

Permalink
Blip: fix offloading and MP tests (#35239)
Browse files Browse the repository at this point in the history
* fix device map

* fix offloading + model parallel test
  • Loading branch information
zucchini-nlp authored Dec 16, 2024
1 parent 66531a1 commit 1491028
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/transformers/models/blip/modeling_blip.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ class BlipPreTrainedModel(PreTrainedModel):
config_class = BlipConfig
base_model_prefix = "blip"
supports_gradient_checkpointing = True
_no_split_modules = ["BlipEncoderLayer"]
_no_split_modules = ["BlipEncoderLayer", "BlipTextEmbeddings"]
_skip_keys_device_placement = ["past_key_value"]

def _init_weights(self, module):
"""Initialize the weights"""
Expand Down Expand Up @@ -1010,7 +1011,8 @@ def forward(
text_embeds = text_embeds / text_embeds.norm(p=2, dim=-1, keepdim=True)

# cosine similarity as logits
logit_scale = self.logit_scale.exp()
logit_scale = self.logit_scale.exp().to(device=text_embeds.device)
image_embeds = image_embeds.to(device=text_embeds.device, dtype=text_embeds.dtype)
logits_per_text = torch.matmul(text_embeds, image_embeds.t()) * logit_scale
logits_per_image = logits_per_text.t()

Expand Down
1 change: 0 additions & 1 deletion src/transformers/models/blip/modeling_blip_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def forward(
position_ids = self.position_ids[:, past_key_values_length : seq_length + past_key_values_length]

if inputs_embeds is None:
input_ids = input_ids.to(self.word_embeddings.weight.device)
inputs_embeds = self.word_embeddings(input_ids)

embeddings = inputs_embeds
Expand Down

0 comments on commit 1491028

Please sign in to comment.