Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/transformers/models/idefics2/modeling_idefics2.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ def forward(self, pixel_values: torch.FloatTensor, patch_attention_mask: torch.B
position_ids = torch.full(size=(batch_size, max_nb_patches_h * max_nb_patches_w), fill_value=0)

for batch_idx, p_attn_mask in enumerate(patch_attention_mask):
nb_patches_h = p_attn_mask[:, 0].sum()
nb_patches_w = p_attn_mask[0].sum()
nb_patches_h = p_attn_mask[:, 0].sum().item()
nb_patches_w = p_attn_mask[0].sum().item()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move all computation to 'cuda' then and avoid ''item()"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

h_indices = torch.arange(nb_patches_h, device=pixel_values.device, dtype=pixel_values.dtype)
w_indices = torch.arange(nb_patches_w, device=pixel_values.device, dtype=pixel_values.dtype)
h_indices = torch.arange(nb_patches_h, dtype=pixel_values.dtype)
w_indices = torch.arange(nb_patches_w, dtype=pixel_values.dtype)
Comment thread
zucchini-nlp marked this conversation as resolved.
Outdated
Comment thread
zucchini-nlp marked this conversation as resolved.
Outdated

fractional_coords_h = h_indices / nb_patches_h * (1 - 1e-6)
fractional_coords_w = w_indices / nb_patches_w * (1 - 1e-6)
Expand Down
8 changes: 4 additions & 4 deletions src/transformers/models/idefics3/modeling_idefics3.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ def forward(self, pixel_values: torch.FloatTensor, patch_attention_mask: torch.B
position_ids = torch.full(size=(batch_size, max_nb_patches_h * max_nb_patches_w), fill_value=0)

for batch_idx, p_attn_mask in enumerate(patch_attention_mask):
nb_patches_h = p_attn_mask[:, 0].sum()
nb_patches_w = p_attn_mask[0].sum()
nb_patches_h = p_attn_mask[:, 0].sum().item()
nb_patches_w = p_attn_mask[0].sum().item()

h_indices = torch.arange(nb_patches_h, device=pixel_values.device, dtype=pixel_values.dtype)
w_indices = torch.arange(nb_patches_w, device=pixel_values.device, dtype=pixel_values.dtype)
h_indices = torch.arange(nb_patches_h, dtype=pixel_values.dtype)
w_indices = torch.arange(nb_patches_w, dtype=pixel_values.dtype)
Comment thread
qgallouedec marked this conversation as resolved.
Outdated
Comment thread
qgallouedec marked this conversation as resolved.
Outdated

fractional_coords_h = h_indices / nb_patches_h * (1 - 1e-6)
fractional_coords_w = w_indices / nb_patches_w * (1 - 1e-6)
Expand Down
8 changes: 4 additions & 4 deletions src/transformers/models/smolvlm/modeling_smolvlm.py

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_export_smolvlm_vision_encoder does not seem to have been triggered

Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ def forward(self, pixel_values: torch.FloatTensor, patch_attention_mask: torch.B
position_ids = torch.full(size=(batch_size, max_nb_patches_h * max_nb_patches_w), fill_value=0)

for batch_idx, p_attn_mask in enumerate(patch_attention_mask):
nb_patches_h = p_attn_mask[:, 0].sum()
nb_patches_w = p_attn_mask[0].sum()
nb_patches_h = p_attn_mask[:, 0].sum().item()
nb_patches_w = p_attn_mask[0].sum().item()

h_indices = torch.arange(nb_patches_h, device=pixel_values.device, dtype=pixel_values.dtype)
w_indices = torch.arange(nb_patches_w, device=pixel_values.device, dtype=pixel_values.dtype)
h_indices = torch.arange(nb_patches_h, dtype=pixel_values.dtype)
w_indices = torch.arange(nb_patches_w, dtype=pixel_values.dtype)
Comment thread
qgallouedec marked this conversation as resolved.
Outdated
Comment thread
qgallouedec marked this conversation as resolved.
Outdated

fractional_coords_h = h_indices / nb_patches_h * (1 - 1e-6)
fractional_coords_w = w_indices / nb_patches_w * (1 - 1e-6)
Expand Down
Loading