Skip to content

Commit

Permalink
Bug Fix for issue huggingface#34294 (huggingface#34295)
Browse files Browse the repository at this point in the history
Update SiglipVisionEmbeddings.forward to cast input to correct dtype before embedding it.
  • Loading branch information
fpgaminer authored and BernardZach committed Dec 6, 2024
1 parent efe275e commit 9ddcedd
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/transformers/models/siglip/modeling_siglip.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ def interpolate_pos_encoding(self, embeddings: torch.Tensor, height: int, width:

def forward(self, pixel_values: torch.FloatTensor, interpolate_pos_encoding=False) -> torch.Tensor:
_, _, height, width = pixel_values.shape
patch_embeds = self.patch_embedding(pixel_values) # shape = [*, width, grid, grid]
target_dtype = self.patch_embedding.weight.dtype
patch_embeds = self.patch_embedding(pixel_values.to(dtype=target_dtype)) # shape = [*, width, grid, grid]
embeddings = patch_embeds.flatten(2).transpose(1, 2)

if interpolate_pos_encoding:
Expand Down

0 comments on commit 9ddcedd

Please sign in to comment.