class_docstr: A class for tutel test cases.
class_docstr_tok: ["A","class","for","tutel","test","cases","."]
code: def test_a2a_algos(self):
      def get_loss_and_step_time(args):
          with contextlib.redirect_stdout(io.StringIO()) as f:
              loss = self.tutelCaller.run(**args)
          step_time = float(f.getvalue().strip().split()[-1])
          return loss, step_time
  
      for nproc_per_node, dtype, num_local_experts in itertools.product(
          [1, 2],
          ["float32", "float16"],
          [1, 2],
      ):
          test_case = {
              "nproc_per_node": nproc_per_node,
              "helloworld_file": "helloworld",
              "top": 2,
              "dtype": dtype,
              "num_local_experts": num_local_experts,
              "show_step_time": True,
              "num_steps": 50,
          }
          with self.subTest(
              msg="Testing a2a algo with setting", test_case=test_case
          ):
              (
                  loss_expected,
                  step_time_expected,
              ) = get_loss_and_step_time(test_case)
              for algo in ["LINEAR", "2D"]:
                  with patch.dict(
                      "os.environ",
                      {
                          "TUTEL_ALLTOALL_ALGO": algo,
                          "LOCAL_SIZE": str(nproc_per_node),
                      },
                  ):
                      loss, step_time = get_loss_and_step_time(
                          test_case
                      )
                      self.assertEqual(loss, loss_expected)
                      print(
                          "\nsubcase(ndevs=%s, dtype=%s, local_experts=%s, algo=%s): step_time = %s (LINEAR = %s)"
                          % (
                              nproc_per_node,
                              dtype,
                              num_local_experts,
                              algo,
                              step_time,
                              step_time_expected,
                          )
                      )
                      self.assertTrue(
                          math.isclose(
                              step_time,
                              step_time_expected,
                              rel_tol=0.01,
                              abs_tol=0.01,
                          )
                      )
  
imports: import contextlib
  import io
  import itertools
  import json
  import math
  import os
  import subprocess
  import unittest
  from unittest.mock import patch
label_desc: Use image node_id 14 for calling the TutelTestCase obj's underlying member method code with example usage: obj.test_a2a_algos() and returns: loss,  step_time