code: def byt5_tokenize(text: str, max_length: int, pad_token_id: int = 0):
      byte_codes = []
      for char in text:
          # Add 3 to account for special tokens
          byte_codes.append([byte + 3 for byte in char.encode("utf-8")])
  
      tokens = list(chain.from_iterable(byte_codes))
      # Map each token to the character it represents
      char_token_lengths = [len(b) for b in byte_codes]
  
      batched_tokens = []
      attention_mask = []
      for i in range(0, len(tokens), max_length):
          batched_tokens.append(tokens[i : i + max_length])
          attention_mask.append([1] * len(batched_tokens[-1]))
  
      # Pad last item
      if len(batched_tokens[-1]) < max_length:
          batched_tokens[-1] += [pad_token_id] * (
              max_length - len(batched_tokens[-1])
          )
          attention_mask[-1] += [0] * (
              max_length - len(attention_mask[-1])
          )
  
      return {
          "input_ids": batched_tokens,
          "attention_mask": attention_mask,
          "char_token_lengths": char_token_lengths,
      }
  
imports: from transformers import T5Config, T5PreTrainedModel
  import torch
  from torch import nn
  from copy import deepcopy
  from typing import Optional, Tuple, Union, List
  from itertools import chain
  from transformers.modeling_outputs import TokenClassifierOutput
  from transformers.models.t5.modeling_t5 import T5Stack
  from transformers.utils.model_parallel_utils import get_device_map, assert_device_map
label_desc: Use image node_id 1 for calling a global function with example usage: byt5_tokenize(text, max_length, pad_token_id) and returns: dict