Unverified Commit fa322474 authored by Manuel's avatar Manuel Committed by GitHub
Browse files

apply torch int div to layoutlmv2 (#15457)

* apply torch int div

* black linting fixup

* update path to torch_int_div

* clarify imports
parent 344b9fb0
...@@ -32,7 +32,7 @@ from ...modeling_outputs import ( ...@@ -32,7 +32,7 @@ from ...modeling_outputs import (
TokenClassifierOutput, TokenClassifierOutput,
) )
from ...modeling_utils import PreTrainedModel 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 ( from ...utils import (
add_start_docstrings, add_start_docstrings,
add_start_docstrings_to_model_forward, add_start_docstrings_to_model_forward,
...@@ -770,25 +770,25 @@ class LayoutLMv2Model(LayoutLMv2PreTrainedModel): ...@@ -770,25 +770,25 @@ class LayoutLMv2Model(LayoutLMv2PreTrainedModel):
return embeddings return embeddings
def _calc_visual_bbox(self, image_feature_pool_shape, bbox, device, final_shape): def _calc_visual_bbox(self, image_feature_pool_shape, bbox, device, final_shape):
visual_bbox_x = ( visual_bbox_x = torch_int_div(
torch.arange( torch.arange(
0, 0,
1000 * (image_feature_pool_shape[1] + 1), 1000 * (image_feature_pool_shape[1] + 1),
1000, 1000,
device=device, device=device,
dtype=bbox.dtype, 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( torch.arange(
0, 0,
1000 * (self.config.image_feature_pool_shape[0] + 1), 1000 * (self.config.image_feature_pool_shape[0] + 1),
1000, 1000,
device=device, device=device,
dtype=bbox.dtype, dtype=bbox.dtype,
) ),
// self.config.image_feature_pool_shape[0] self.config.image_feature_pool_shape[0],
) )
visual_bbox = torch.stack( visual_bbox = torch.stack(
[ [
......
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