code: def load_and_prepare_xsum(
      model_name, data_metric_config, _, **kwargs
  ):
      # Prepare model
      model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
      tokenizer = AutoTokenizer.from_pretrained(model_name)
  
      # Load dataset and metric
      dataset = load_dataset(*data_metric_config["dataset"])
      metric = load(*data_metric_config["metric"])
  
      if model_name in [
          "t5-small",
          "t5-base",
          "t5-large",
          "t5-3b",
          "t5-11b",
      ]:
          prefix = "summarize: "
      else:
          prefix = ""
  
      max_input_length = kwargs.get("max_input_length", 128)
      max_target_length = kwargs.get("max_input_length", 64)
  
      training_args = kwargs.get("training_args", None)
      label_pad_token_id = tokenizer.pad_token_id
      data_collator = _get_data_collator(
          data_metric_config,
          tokenizer,
          model,
          training_args=training_args,
          label_pad_token_id=label_pad_token_id,
      )
  
      def preprocess_function(examples):
          inputs = [prefix + doc for doc in examples["document"]]
          model_inputs = tokenizer(
              inputs, max_length=max_input_length, truncation=True
          )
  
          # Setup the tokenizer for targets
          with tokenizer.as_target_tokenizer():
              labels = tokenizer(
                  examples["summary"],
                  max_length=max_target_length,
                  truncation=True,
              )
  
          model_inputs["labels"] = labels["input_ids"]
          return model_inputs
  
      encoded_dataset = dataset.map(preprocess_function, batched=True)
      train_dataset = encoded_dataset["train"]
      valid_dataset = encoded_dataset["validation"]
      test_dataset = encoded_dataset["test"]
  
      max_train_samples = kwargs.get("max_train_samples", None)
      max_valid_samples = kwargs.get("max_valid_samples", None)
      max_test_samples = kwargs.get("max_test_samples", None)
  
      if max_train_samples:
          train_dataset = train_dataset.select(range(max_train_samples))
      if max_valid_samples:
          valid_dataset = valid_dataset.select(range(max_valid_samples))
      if max_test_samples:
          test_dataset = test_dataset.select(range(max_test_samples))
  
      def compute_metrics(eval_pred):
          predictions, labels = eval_pred
          if isinstance(predictions, tuple):
              predictions = predictions[0]
          decoded_preds = tokenizer.batch_decode(
              predictions, skip_special_tokens=True
          )
          # Replace -100 in the labels as we can't decode them.
          labels = np.where(
              labels != -100, labels, tokenizer.pad_token_id
          )
          decoded_labels = tokenizer.batch_decode(
              labels, skip_special_tokens=True
          )
  
          # Rouge expects a newline after each sentence
          decoded_preds = [
              "\n".join(nltk.sent_tokenize(pred.strip()))
              for pred in decoded_preds
          ]
          decoded_labels = [
              "\n".join(nltk.sent_tokenize(label.strip()))
              for label in decoded_labels
          ]
  
          result = metric.compute(
              predictions=decoded_preds,
              references=decoded_labels,
              use_stemmer=True,
          )
  
          # Add mean generated length
          prediction_lens = [
              np.count_nonzero(pred != tokenizer.pad_token_id)
              for pred in predictions
          ]
          result["gen_len"] = np.mean(prediction_lens)
  
          return {k: round(v, 4) for k, v in result.items()}
  
      return {
          "model": model,
          "tokenizer": tokenizer,
          "data_collator": data_collator,
          "train_dataset": train_dataset,
          "eval_dataset": valid_dataset,
          "test_dataset": test_dataset,
          "compute_metrics": compute_metrics,
      }
  
imports: import gc
  import os
  import random
  import tempfile
  import unittest
  from itertools import chain
  from typing import List, Optional
  from unittest.mock import Mock, patch
  import nltk
  import numpy
  from datasets import load_dataset
  from evaluate import load
  from transformers import AutoModelForCausalLM, AutoModelForSeq2SeqLM, AutoModelForSequenceClassification, AutoModelForTokenClassification, AutoTokenizer, DataCollatorForSeq2Seq, DataCollatorWithPadding, default_data_collator, is_torch_available
  from transformers.testing_utils import mockenv_context, require_deepspeed, require_torch, slow
  from transformers.training_args import OptimizerNames
  import onnxruntime
  from parameterized import parameterized
  from optimum.onnxruntime import ORTSeq2SeqTrainer, ORTSeq2SeqTrainingArguments, ORTTrainer, ORTTrainingArguments
  from optimum.onnxruntime.training_args import ORTOptimizerNames
label_desc: Use image node_id 10 for calling a global function with example usage: load_and_prepare_xsum(model_name, data_metric_config, _) and returns: dict, model_inputs, unknown