code: def test_rag_token_from_pretrained(self):
      rag_config = self.get_rag_config()
      rag_decoder_tokenizer = BartTokenizer.from_pretrained(
          "facebook/bart-large-cnn"
      )
      rag_question_encoder_tokenizer = (
          DPRQuestionEncoderTokenizer.from_pretrained(
              "facebook/dpr-question_encoder-single-nq-base"
          )
      )
      rag_retriever = RagRetriever(
          rag_config,
          question_encoder_tokenizer=rag_question_encoder_tokenizer,
          generator_tokenizer=rag_decoder_tokenizer,
      )
  
      input_ids = rag_question_encoder_tokenizer(
          "who sings does he love me with reba", return_tensors="pt"
      ).input_ids
      decoder_input_ids = rag_decoder_tokenizer(
          "Linda Davis", return_tensors="pt"
      ).input_ids
  
      input_ids = input_ids.to(torch_device)
      decoder_input_ids = decoder_input_ids.to(torch_device)
  
      with tempfile.TemporaryDirectory() as tmp_dirname:
          rag_token = RagTokenForGeneration.from_pretrained_question_encoder_generator(
              "facebook/dpr-question_encoder-single-nq-base",
              "facebook/bart-large-cnn",
              retriever=rag_retriever,
              config=rag_config,
              question_encoder_max_length=200,
              generator_max_length=200,
          ).to(
              torch_device
          )
          # check that the from pretrained methods work
          rag_token.save_pretrained(tmp_dirname)
          rag_token.from_pretrained(
              tmp_dirname, retriever=rag_retriever
          )
          rag_token.to(torch_device)
  
          self.assertTrue(
              rag_token.question_encoder.config.max_length == 200
          )
          self.assertTrue(rag_token.generator.config.max_length == 200)
  
          with torch.no_grad():
              output = rag_token(
                  input_ids,
                  labels=decoder_input_ids,
              )
  
          loss_pretrained = output.loss
          del rag_token
  
      question_encoder = AutoModel.from_pretrained(
          "facebook/dpr-question_encoder-single-nq-base"
      )
      generator = AutoModelForSeq2SeqLM.from_pretrained(
          "facebook/bart-large-cnn"
      )
      rag_token = RagTokenForGeneration(
          config=rag_config,
          question_encoder=question_encoder,
          generator=generator,
          retriever=rag_retriever,
      )
      rag_token.to(torch_device)
  
      with torch.no_grad():
          output = rag_token(
              input_ids,
              labels=decoder_input_ids,
          )
  
      loss_init = output.loss
  
      self.assertAlmostEqual(
          loss_pretrained.item(), loss_init.item(), places=4
      )
  
imports: import gc
  import json
  import os
  import shutil
  import tempfile
  import unittest
  from unittest.mock import patch
  import numpy
  from transformers import BartTokenizer, T5Tokenizer
  from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
  from transformers.models.dpr.tokenization_dpr import DPRContextEncoderTokenizer, DPRQuestionEncoderTokenizer
  from transformers.models.roberta.tokenization_roberta import VOCAB_FILES_NAMES
  from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, require_torch, require_torch_non_multi_gpu, slow, torch_device
  from transformers.utils import cached_property, is_datasets_available, is_faiss_available, is_torch_available
  from ..bart.test_modeling_bart import BartModelTester
  from ..dpr.test_modeling_dpr import DPRModelTester
  from ..t5.test_modeling_t5 import T5ModelTester
label_desc: Use image node_id 4 for calling the RagModelSaveLoadTests obj's underlying member method code with example usage: obj.test_rag_token_from_pretrained() without return types