docstr: Test exporting a BART model to TorchScript for GPU and then testing it on sample
  data.
docstr_tok: ["Test","exporting","a","BART","model","to","TorchScript","for","GPU","and","then","testing","it","on","sample","data","."]
code: def test_gpu_torchscript_bart_agent(self):
      """
      Test exporting a BART model to TorchScript for GPU and then testing it on sample
      data.
      """
  
      from parlai.scripts.torchscript import TorchScript
  
      test_phrase = "Don't have a cow, man!"  # From test_bart.py
  
      with testing_utils.tempdir() as tmpdir:
          scripted_model_file = os.path.join(
              tmpdir, "scripted_model.pt"
          )
  
          # Export the BART model for GPU
          export_opt = TorchScript.setup_args().parse_kwargs(
              model="bart",
              scripted_model_file=scripted_model_file,
              no_cuda=False,
          )
          TorchScript(export_opt).run()
  
          # Test the scripted GPU BART model
          scripted_opt = ParlaiParser(True, True).parse_kwargs(
              model="parlai.torchscript.agents:TorchScriptAgent",
              model_file=scripted_model_file,
          )
          bart = create_agent(scripted_opt)
          bart.observe({"text": test_phrase, "episode_done": True})
          act = bart.act()
          self.assertEqual(act["text"], test_phrase)
  
file_path: ParlAI/tests/nightly/gpu/test_torchscript.py
imports: import os
  import regex
  import unittest
  import parlai.utils.testing
  from parlai.agents.repeat_label.repeat_label import RepeatLabelAgent
  from parlai.core.agents import create_agent
  from parlai.core.params import ParlaiParser
  from parlai.core.worlds import create_task
  from parlai.utils.bpe import Gpt2BpeHelper
label_desc: Use image node_id 6 for calling the TestTorchScript obj's underlying member method code with example usage: obj.test_gpu_torchscript_bart_agent() without return types