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

add bbox input validation #26294

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Changes from all commits
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
15 changes: 8 additions & 7 deletions src/transformers/models/bros/modeling_bros.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,9 @@ def forward(
else:
raise ValueError("You have to specify either input_ids or inputs_embeds")

if bbox is None:
raise ValueError("You have to specify bbox")

batch_size, seq_length = input_shape
device = input_ids.device if input_ids is not None else inputs_embeds.device

Expand Down Expand Up @@ -924,13 +927,11 @@ def forward(
past_key_values_length=past_key_values_length,
)

bbox_position_embeddings = None
if bbox is not None:
# if bbox has 2 points (4 float tensors) per token, convert it to 4 points (8 float tensors) per token
if bbox.shape[-1] == 4:
bbox = bbox[:, :, [0, 1, 2, 1, 2, 3, 0, 3]]
scaled_bbox = bbox * self.config.bbox_scale
bbox_position_embeddings = self.bbox_embeddings(scaled_bbox)
# if bbox has 2 points (4 float tensors) per token, convert it to 4 points (8 float tensors) per token
if bbox.shape[-1] == 4:
bbox = bbox[:, :, [0, 1, 2, 1, 2, 3, 0, 3]]
scaled_bbox = bbox * self.config.bbox_scale
bbox_position_embeddings = self.bbox_embeddings(scaled_bbox)

encoder_outputs = self.encoder(
embedding_output,
Expand Down