class_docstr: Test memory efficient FP16 implementation.
class_docstr_tok: ["Test","memory","efficient","FP16","implementation","."]
docstr: Test switching from memory efficient fp16 to safe fp16.
docstr_tok: ["Test","switching","from","memory","efficient","fp16","to","safe","fp16","."]
code: def test_resuming_memeff2safe(self):
      """
      Test switching from memory efficient fp16 to safe fp16.
      """
      with testing_utils.tempdir() as tmpdir:
          model_file = os.path.join(tmpdir, "model")
  
          valid1, test1 = testing_utils.train_model(
              dict(
                  model_file=model_file,
                  task="integration_tests",
                  model="transformer/generator",
                  optimizer="adam",
                  fp16=True,
                  fp16_impl="mem_efficient",
                  learningrate=1e-3,
                  batchsize=32,
                  num_epochs=0.25,
                  n_layers=1,
                  n_heads=1,
                  ffn_size=32,
                  embedding_size=32,
                  warmup_updates=1,
                  lr_scheduler="invsqrt",
                  skip_generation=True,
              )
          )
  
          valid2, test2 = testing_utils.train_model(
              dict(
                  model_file=model_file,
                  task="integration_tests",
                  model="transformer/generator",
                  fp16_impl="safe",
                  num_epochs=0.5,
              )
          )
  
          # make sure the number of updates is being tracked correctly
          self.assertGreater(
              valid2["total_train_updates"],
              valid1["total_train_updates"],
              "Number of updates is not increasing",
          )
  
file_path: ParlAI/tests/test_mem_efficient_fp16.py
imports: import os
  import unittest
  import parlai.utils.testing
label_desc: Use image node_id 4 for calling the TestMemEfficientFP16 obj's underlying member method code with example usage: obj.test_resuming_memeff2safe() without return types