code: def test_padding(self, max_length=50):
      for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
          with self.subTest(
              f"{tokenizer.__class__.__name__} ({pretrained_name})"
          ):
              tokenizer_r = self.rust_tokenizer_class.from_pretrained(
                  pretrained_name, **kwargs
              )
              tokenizer_p = self.tokenizer_class.from_pretrained(
                  pretrained_name, **kwargs
              )
  
              self.assertEqual(
                  tokenizer_p.pad_token_id, tokenizer_r.pad_token_id
              )
              pad_token_id = tokenizer_p.pad_token_id
  
              # Encode - Simple input
              words, boxes = self.get_words_and_boxes()
              input_r = tokenizer_r.encode(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  pad_to_max_length=True,
              )
              input_p = tokenizer_p.encode(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  pad_to_max_length=True,
              )
              self.assert_padded_input_match(
                  input_r, input_p, max_length, pad_token_id
              )
              input_r = tokenizer_r.encode(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  padding="max_length",
              )
              input_p = tokenizer_p.encode(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  padding="max_length",
              )
              self.assert_padded_input_match(
                  input_r, input_p, max_length, pad_token_id
              )
  
              input_r = tokenizer_r.encode(
                  words, boxes=boxes, padding="longest"
              )
              input_p = tokenizer_p.encode(
                  words, boxes=boxes, padding=True
              )
              self.assert_padded_input_match(
                  input_r, input_p, len(input_r), pad_token_id
              )
  
              # Encode - Pair input
              (
                  question,
                  words,
                  boxes,
              ) = self.get_question_words_and_boxes()
              input_r = tokenizer_r.encode(
                  question,
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  pad_to_max_length=True,
              )
              input_p = tokenizer_p.encode(
                  question,
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  pad_to_max_length=True,
              )
              self.assert_padded_input_match(
                  input_r, input_p, max_length, pad_token_id
              )
              input_r = tokenizer_r.encode(
                  question,
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  padding="max_length",
              )
              input_p = tokenizer_p.encode(
                  question,
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  padding="max_length",
              )
              self.assert_padded_input_match(
                  input_r, input_p, max_length, pad_token_id
              )
              input_r = tokenizer_r.encode(
                  question, words, boxes=boxes, padding=True
              )
              input_p = tokenizer_p.encode(
                  question, words, boxes=boxes, padding="longest"
              )
              self.assert_padded_input_match(
                  input_r, input_p, len(input_r), pad_token_id
              )
  
              # Encode_plus - Simple input
              words, boxes = self.get_words_and_boxes()
              input_r = tokenizer_r.encode_plus(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  pad_to_max_length=True,
              )
              input_p = tokenizer_p.encode_plus(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  pad_to_max_length=True,
              )
              self.assert_padded_input_match(
                  input_r["input_ids"],
                  input_p["input_ids"],
                  max_length,
                  pad_token_id,
              )
              self.assertSequenceEqual(
                  input_r["attention_mask"], input_p["attention_mask"]
              )
              input_r = tokenizer_r.encode_plus(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  padding="max_length",
              )
              input_p = tokenizer_p.encode_plus(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  padding="max_length",
              )
              self.assert_padded_input_match(
                  input_r["input_ids"],
                  input_p["input_ids"],
                  max_length,
                  pad_token_id,
              )
              self.assertSequenceEqual(
                  input_r["attention_mask"], input_p["attention_mask"]
              )
  
              input_r = tokenizer_r.encode_plus(
                  words, boxes=boxes, padding="longest"
              )
              input_p = tokenizer_p.encode_plus(
                  words, boxes=boxes, padding=True
              )
              self.assert_padded_input_match(
                  input_r["input_ids"],
                  input_p["input_ids"],
                  len(input_r["input_ids"]),
                  pad_token_id,
              )
  
              self.assertSequenceEqual(
                  input_r["attention_mask"], input_p["attention_mask"]
              )
  
              # Encode_plus - Pair input
              (
                  question,
                  words,
                  boxes,
              ) = self.get_question_words_and_boxes()
              input_r = tokenizer_r.encode_plus(
                  question,
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  pad_to_max_length=True,
              )
              input_p = tokenizer_p.encode_plus(
                  question,
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  pad_to_max_length=True,
              )
              self.assert_padded_input_match(
                  input_r["input_ids"],
                  input_p["input_ids"],
                  max_length,
                  pad_token_id,
              )
              self.assertSequenceEqual(
                  input_r["attention_mask"], input_p["attention_mask"]
              )
              input_r = tokenizer_r.encode_plus(
                  question,
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  padding="max_length",
              )
              input_p = tokenizer_p.encode_plus(
                  question,
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  padding="max_length",
              )
              self.assert_padded_input_match(
                  input_r["input_ids"],
                  input_p["input_ids"],
                  max_length,
                  pad_token_id,
              )
              self.assertSequenceEqual(
                  input_r["attention_mask"], input_p["attention_mask"]
              )
              input_r = tokenizer_r.encode_plus(
                  question, words, boxes=boxes, padding="longest"
              )
              input_p = tokenizer_p.encode_plus(
                  question, words, boxes=boxes, padding=True
              )
              self.assert_padded_input_match(
                  input_r["input_ids"],
                  input_p["input_ids"],
                  len(input_r["input_ids"]),
                  pad_token_id,
              )
              self.assertSequenceEqual(
                  input_r["attention_mask"], input_p["attention_mask"]
              )
  
              # Batch_encode_plus - Simple input
              words, boxes = self.get_words_and_boxes_batch()
  
              input_r = tokenizer_r.batch_encode_plus(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  pad_to_max_length=True,
              )
              input_p = tokenizer_p.batch_encode_plus(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  pad_to_max_length=True,
              )
              self.assert_batch_padded_input_match(
                  input_r, input_p, max_length, pad_token_id
              )
  
              input_r = tokenizer_r.batch_encode_plus(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  padding="max_length",
              )
              input_p = tokenizer_p.batch_encode_plus(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  padding="max_length",
              )
              self.assert_batch_padded_input_match(
                  input_r, input_p, max_length, pad_token_id
              )
  
              input_r = tokenizer_r.batch_encode_plus(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  padding="longest",
              )
              input_p = tokenizer_p.batch_encode_plus(
                  words,
                  boxes=boxes,
                  max_length=max_length,
                  padding=True,
              )
              self.assert_batch_padded_input_match(
                  input_r,
                  input_p,
                  len(input_r["input_ids"][0]),
                  pad_token_id,
              )
  
              input_r = tokenizer_r.batch_encode_plus(
                  words, boxes=boxes, padding="longest"
              )
              input_p = tokenizer_p.batch_encode_plus(
                  words, boxes=boxes, padding=True
              )
              self.assert_batch_padded_input_match(
                  input_r,
                  input_p,
                  len(input_r["input_ids"][0]),
                  pad_token_id,
              )
  
              # Batch_encode_plus - Pair input
              (
                  questions,
                  words,
                  boxes,
              ) = self.get_question_words_and_boxes_batch()
  
              input_r = tokenizer_r.batch_encode_plus(
                  list(zip(questions, words)),
                  is_pair=True,
                  boxes=boxes,
                  max_length=max_length,
                  truncation=True,
                  padding="max_length",
              )
              input_p = tokenizer_p.batch_encode_plus(
                  list(zip(questions, words)),
                  is_pair=True,
                  boxes=boxes,
                  max_length=max_length,
                  truncation=True,
                  padding="max_length",
              )
              self.assert_batch_padded_input_match(
                  input_r, input_p, max_length, pad_token_id
              )
  
              input_r = tokenizer_r.batch_encode_plus(
                  list(zip(questions, words)),
                  is_pair=True,
                  boxes=boxes,
                  padding=True,
              )
              input_p = tokenizer_p.batch_encode_plus(
                  list(zip(questions, words)),
                  is_pair=True,
                  boxes=boxes,
                  padding="longest",
              )
              self.assert_batch_padded_input_match(
                  input_r,
                  input_p,
                  len(input_r["input_ids"][0]),
                  pad_token_id,
              )
  
              # Using pad on single examples after tokenization
              words, boxes = self.get_words_and_boxes()
              input_r = tokenizer_r.encode_plus(words, boxes=boxes)
              input_r = tokenizer_r.pad(input_r)
  
              input_p = tokenizer_r.encode_plus(words, boxes=boxes)
              input_p = tokenizer_r.pad(input_p)
  
              self.assert_padded_input_match(
                  input_r["input_ids"],
                  input_p["input_ids"],
                  len(input_r["input_ids"]),
                  pad_token_id,
              )
  
              # Using pad on single examples after tokenization
              input_r = tokenizer_r.encode_plus(words, boxes=boxes)
              input_r = tokenizer_r.pad(
                  input_r, max_length=max_length, padding="max_length"
              )
  
              input_p = tokenizer_r.encode_plus(words, boxes=boxes)
              input_p = tokenizer_r.pad(
                  input_p, max_length=max_length, padding="max_length"
              )
  
              self.assert_padded_input_match(
                  input_r["input_ids"],
                  input_p["input_ids"],
                  max_length,
                  pad_token_id,
              )
  
              # Using pad after tokenization
              words, boxes = self.get_words_and_boxes_batch()
              input_r = tokenizer_r.batch_encode_plus(
                  words,
                  boxes=boxes,
              )
              input_r = tokenizer_r.pad(input_r)
  
              input_p = tokenizer_r.batch_encode_plus(
                  words,
                  boxes=boxes,
              )
              input_p = tokenizer_r.pad(input_p)
  
              self.assert_batch_padded_input_match(
                  input_r,
                  input_p,
                  len(input_r["input_ids"][0]),
                  pad_token_id,
              )
  
              # Using pad after tokenization
              words, boxes = self.get_words_and_boxes_batch()
              input_r = tokenizer_r.batch_encode_plus(
                  words,
                  boxes=boxes,
              )
              input_r = tokenizer_r.pad(
                  input_r, max_length=max_length, padding="max_length"
              )
  
              input_p = tokenizer_r.batch_encode_plus(
                  words,
                  boxes=boxes,
              )
              input_p = tokenizer_r.pad(
                  input_p, max_length=max_length, padding="max_length"
              )
  
              self.assert_batch_padded_input_match(
                  input_r, input_p, max_length, pad_token_id
              )
  
imports: import inspect
  import shutil
  import tempfile
  import unittest
  from typing import List
  from transformers import AddedToken, LayoutXLMTokenizerFast, SpecialTokensMixin, is_tf_available, is_torch_available, logging
  from transformers.models.layoutxlm.tokenization_layoutxlm import LayoutXLMTokenizer
  from transformers.testing_utils import get_tests_dir, is_pt_tf_cross_test, require_pandas, require_scatter, require_sentencepiece, require_tokenizers, require_torch, slow
  from ...test_tokenization_common import SMALL_TRAINING_CORPUS, TokenizerTesterMixin, filter_non_english, merge_model_tokenizer_mappings
label_desc: Use image node_id 18 for calling the LayoutXLMTokenizationTest obj's underlying member method code with example usage: obj.test_padding(max_length) without return types