Skip to content
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
19 changes: 8 additions & 11 deletions tests/layoutlmv2/test_tokenization_layoutlmv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@
_is_punctuation,
_is_whitespace,
)
from transformers.testing_utils import (
is_pt_tf_cross_test,
require_pandas,
require_scatter,
require_tokenizers,
require_torch,
slow,
)
from transformers.testing_utils import is_pt_tf_cross_test, require_pandas, require_tokenizers, require_torch, slow

from ..test_tokenization_common import (
SMALL_TRAINING_CORPUS,
Expand Down Expand Up @@ -1219,7 +1212,6 @@ def test_offsets_mapping(self):

@require_torch
@slow
@require_scatter
def test_torch_encode_plus_sent_to_model(self):
import torch

Expand Down Expand Up @@ -1254,10 +1246,15 @@ def test_torch_encode_plus_sent_to_model(self):
words, boxes = self.get_words_and_boxes()
encoded_sequence = tokenizer.encode_plus(words, boxes=boxes, return_tensors="pt")
batch_encoded_sequence = tokenizer.batch_encode_plus(
[words, words], [boxes, boxes], return_tensors="pt"
[words, words], boxes=[boxes, boxes], return_tensors="pt"
)
# This should not fail

# We add dummy image keys (as LayoutLMv2 actually also requires a feature extractor
# to prepare the image input)
encoded_sequence["image"] = torch.randn(1, 3, 224, 224)
batch_encoded_sequence["image"] = torch.randn(2, 3, 224, 224)

# This should not fail
with torch.no_grad(): # saves some time
model(**encoded_sequence)
model(**batch_encoded_sequence)
Expand Down