Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(
# get pair-wise relative position index for each token inside the window
coords_h = torch.arange(self.window_size[0])
coords_w = torch.arange(self.window_size[1])
coords = torch.stack(torch.meshgrid([coords_h, coords_w])) # 2, Wh, Ww
coords = torch.stack(torch.meshgrid([coords_h, coords_w], indexing="ij")) # 2, Wh, Ww
coords_flatten = torch.flatten(coords, 1) # 2, Wh*Ww
relative_coords = coords_flatten[:, :, None] - coords_flatten[:, None, :] # 2, Wh*Ww, Wh*Ww
relative_coords = relative_coords.permute(1, 2, 0).contiguous() # Wh*Ww, Wh*Ww, 2
Expand Down Expand Up @@ -445,7 +445,7 @@ def forward(self, x, H, W):
for blk in self.blocks:
blk.H, blk.W = H, W
if self.use_checkpoint:
x = checkpoint.checkpoint(blk, x, attn_mask)
x = checkpoint.checkpoint(blk, x, attn_mask, use_reentrant=True)
else:
x = blk(x, attn_mask)
if self.downsample is not None:
Expand Down
2 changes: 1 addition & 1 deletion groundingdino/models/GroundingDINO/bertwarper.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def forward(
# We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
# ourselves in which case we just need to make it broadcastable to all heads.
extended_attention_mask: torch.Tensor = self.get_extended_attention_mask(
attention_mask, input_shape, device
attention_mask, input_shape
)

# If a 2D or 3D attention mask is provided for the cross-attention
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ at::Tensor ms_deform_attn_cuda_forward(
for (int n = 0; n < batch/im2col_step_; ++n)
{
auto columns = output_n.select(0, n);
AT_DISPATCH_FLOATING_TYPES(value.type(), "ms_deform_attn_forward_cuda", ([&] {
AT_DISPATCH_FLOATING_TYPES(value.scalar_type(), "ms_deform_attn_forward_cuda", ([&] {
ms_deformable_im2col_cuda(at::cuda::getCurrentCUDAStream(),
value.data<scalar_t>() + n * im2col_step_ * per_value_size,
spatial_shapes.data<int64_t>(),
Expand Down Expand Up @@ -132,7 +132,7 @@ std::vector<at::Tensor> ms_deform_attn_cuda_backward(
for (int n = 0; n < batch/im2col_step_; ++n)
{
auto grad_output_g = grad_output_n.select(0, n);
AT_DISPATCH_FLOATING_TYPES(value.type(), "ms_deform_attn_backward_cuda", ([&] {
AT_DISPATCH_FLOATING_TYPES(value.scalar_type(), "ms_deform_attn_backward_cuda", ([&] {
ms_deformable_col2im_cuda(at::cuda::getCurrentCUDAStream(),
grad_output_g.data<scalar_t>(),
value.data<scalar_t>() + n * im2col_step_ * per_value_size,
Expand Down
5 changes: 4 additions & 1 deletion groundingdino/models/GroundingDINO/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ def get_reference_points(spatial_shapes, valid_ratios, device):
ref_y, ref_x = torch.meshgrid(
torch.linspace(0.5, H_ - 0.5, H_, dtype=torch.float32, device=device),
torch.linspace(0.5, W_ - 0.5, W_, dtype=torch.float32, device=device),
indexing="ij",
)
ref_y = ref_y.reshape(-1)[None] / (valid_ratios[:, None, lvl, 1] * H_)
ref_x = ref_x.reshape(-1)[None] / (valid_ratios[:, None, lvl, 0] * W_)
Expand Down Expand Up @@ -554,6 +555,7 @@ def forward(
memory_text,
key_padding_mask,
text_attention_mask,
use_reentrant=True,
)
else:
output, memory_text = self.fusion_layers[layer_id](
Expand Down Expand Up @@ -581,6 +583,7 @@ def forward(
spatial_shapes,
level_start_index,
key_padding_mask,
use_reentrant=True,
)
else:
output = layer(
Expand Down Expand Up @@ -859,7 +862,7 @@ def with_pos_embed(tensor, pos):
return tensor if pos is None else tensor + pos

def forward_ffn(self, tgt):
with torch.cuda.amp.autocast(enabled=False):
with torch.amp.autocast(device_type='cuda', dtype=torch.float16, enabled=False, cache_enabled=True):
tgt2 = self.linear2(self.dropout3(self.activation(self.linear1(tgt))))
tgt = tgt + self.dropout4(tgt2)
tgt = self.norm3(tgt)
Expand Down
1 change: 1 addition & 0 deletions groundingdino/models/GroundingDINO/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def gen_encoder_output_proposals(
grid_y, grid_x = torch.meshgrid(
torch.linspace(0, H_ - 1, H_, dtype=torch.float32, device=memory.device),
torch.linspace(0, W_ - 1, W_, dtype=torch.float32, device=memory.device),
indexing="ij",
)
grid = torch.cat([grid_x.unsqueeze(-1), grid_y.unsqueeze(-1)], -1) # H_, W_, 2

Expand Down
2 changes: 1 addition & 1 deletion groundingdino/util/box_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def masks_to_boxes(masks):

y = torch.arange(0, h, dtype=torch.float)
x = torch.arange(0, w, dtype=torch.float)
y, x = torch.meshgrid(y, x)
y, x = torch.meshgrid(y, x, indexing="ij")

x_mask = masks * x.unsqueeze(0)
x_max = x_mask.flatten(1).max(-1)[0]
Expand Down