Skip to content

Commit

Permalink
apply torch int div to layoutlmv2 (#15457)
Browse files Browse the repository at this point in the history
* apply torch int div

* black linting fixup

* update path to torch_int_div

* clarify imports
  • Loading branch information
ManuelFay authored Apr 26, 2022
1 parent 344b9fb commit fa32247
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/transformers/models/layoutlmv2/modeling_layoutlmv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
TokenClassifierOutput,
)
from ...modeling_utils import PreTrainedModel
from ...pytorch_utils import apply_chunking_to_forward
from ...pytorch_utils import apply_chunking_to_forward, torch_int_div
from ...utils import (
add_start_docstrings,
add_start_docstrings_to_model_forward,
Expand Down Expand Up @@ -770,25 +770,25 @@ def _calc_img_embeddings(self, image, bbox, position_ids):
return embeddings

def _calc_visual_bbox(self, image_feature_pool_shape, bbox, device, final_shape):
visual_bbox_x = (
visual_bbox_x = torch_int_div(
torch.arange(
0,
1000 * (image_feature_pool_shape[1] + 1),
1000,
device=device,
dtype=bbox.dtype,
)
// self.config.image_feature_pool_shape[1]
),
self.config.image_feature_pool_shape[1],
)
visual_bbox_y = (
visual_bbox_y = torch_int_div(
torch.arange(
0,
1000 * (self.config.image_feature_pool_shape[0] + 1),
1000,
device=device,
dtype=bbox.dtype,
)
// self.config.image_feature_pool_shape[0]
),
self.config.image_feature_pool_shape[0],
)
visual_bbox = torch.stack(
[
Expand Down

0 comments on commit fa32247

Please sign in to comment.