class_docstr: A class for run tutel helloworld example with different arguments
class_docstr_tok: ["A","class","for","run","tutel","helloworld","example","with","different","arguments"]
code: def run(
      self,
      nproc_per_node=1,
      helloworld_file="helloworld",
      top=2,
      dtype="float32",
      num_local_experts="2",
      hidden_size=2048,
      show_step_time=True,
      batch_size=16,
      is_round=True,
      a2a_ffn_overlap_degree=1,
      num_steps=100,
      use_model_parallel=False,
      device="cuda",
  ):
      # Disable NCCL SHM because it's capacity is limited in Azure pipeline
      new_env = os.environ.copy()
      new_env["NCCL_SHM_DISABLE"] = "1"
      """Run helloworld example"""
      if helloworld_file == "helloworld":
          command = (
              "python3 -m torch.distributed.run --nproc_per_node="
              + str(nproc_per_node)
              + " tutel/examples/helloworld.py --top "
              + str(top)
              + " --dtype "
              + dtype
              + " --num_local_experts "
              + str(num_local_experts)
              + " --hidden_size "
              + str(hidden_size)
              + " --batch_size "
              + str(batch_size)
              + " --a2a_ffn_overlap_degree "
              + str(a2a_ffn_overlap_degree)
              + " --num_steps "
              + str(num_steps)
              + " --device "
              + str(device)
              + " --num_tokens 1024"
          )
          if use_model_parallel:
              command += " --parallel_type model"
          else:
              command += " --parallel_type data"
      else:
          raise Exception(
              "Unhandled helloworld_file: %s" % helloworld_file
          )
  
      p = subprocess.Popen(
          command,
          shell=True,
          stdout=subprocess.PIPE,
          stderr=subprocess.PIPE,
          env=new_env,
      )
      losses = []
      while p.poll() is None:
          line = p.stdout.readline().decode("utf8").split()
          for i in range(len(line) - 1):
              if line[i] == "loss":
                  if is_round:
                      if dtype == "float32":
                          losses.append(
                              round(float(line[i + 2][:-1]), 3)
                          )
                      else:
                          losses.append(
                              round(float(line[i + 2][:-1]), 1)
                          )
                  else:
                      losses.append(line[i + 2][:-1])
                  break
              if show_step_time and line[0] == "[Summary]":
                  print("step time:", line[5])
      p.stdout.close()
      assert len(losses) > 0, (
          "No valid loss result found for this unit test: %s" % command
      )
      return losses
  
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 1 for calling the HelloworldCaller obj's underlying member method code with example usage: obj.run(nproc_per_node, helloworld_file, top, dtype, num_local_experts, hidden_size, show_step_time, batch_size, is_round, a2a_ffn_overlap_degree, num_steps, use_model_parallel, device) and returns: losses