Unverified Commit 1fff6746 authored by Victor SANH's avatar Victor SANH Committed by GitHub
Browse files

Fix position ids logic instantiation of idefics vision part (#1064)

Problem and fix is described here:
https://huggingface.co/HuggingFaceM4/idefics-9b/discussions/9



---------
Co-authored-by: default avatarNicolas Patry <patry.nicolas@protonmail.com>
parent ae623b8d
...@@ -88,12 +88,10 @@ class IdeficsVisionEmbeddings(nn.Module): ...@@ -88,12 +88,10 @@ class IdeficsVisionEmbeddings(nn.Module):
self.num_patches = (self.image_size // self.patch_size) ** 2 self.num_patches = (self.image_size // self.patch_size) ** 2
self.num_positions = self.num_patches + 1 self.num_positions = self.num_patches + 1
# self.position_embedding = nn.Embedding(self.num_positions, self.embed_dim)
self.position_embedding = TensorParallelEmbedding( self.position_embedding = TensorParallelEmbedding(
prefix="model.vision_model.embeddings.position_embedding", weights=weights prefix="model.vision_model.embeddings.position_embedding", weights=weights
) )
# self.register_buffer("position_ids", torch.arange(self.num_positions).expand((1, -1)), persistent=False) self.position_ids = torch.arange(self.num_positions).expand((1, -1)).to(device=weights.device)
self.position_ids = weights.get_tensor(f"{prefix}.position_ids")
def forward(self, pixel_values: torch.FloatTensor) -> torch.Tensor: def forward(self, pixel_values: torch.FloatTensor) -> torch.Tensor:
batch_size = pixel_values.shape[0] batch_size = pixel_values.shape[0]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment