code: def test_fused_gradnorm(self, monkeypatch):
      if not required_torch_version(min_version=1.8):
          pytest.skip(
              "DeepSpeed MoE tests need torch 1.8 or higher to run correctly"
          )
  
      config_dict = {
          "train_batch_size": 2,
          "steps_per_print": 1,
          "fp16": {"enabled": True},
      }
      hidden_dim = 10
  
      def mock_unscale_and_clip_grads(
          grads_groups_flat, total_norm, apply_scale=True
      ):
          torch_norm_tensor = get_accelerator().FloatTensor(
              [total_norm]
          )
          all_gather_results = [
              torch.zeros_like(torch_norm_tensor)
              for _ in range(dist.get_world_size())
          ]
          dist.all_gather(all_gather_results, torch_norm_tensor)
          assert len(set([x.item() for x in all_gather_results])) == 1
          return 1.0
  
      # initialize MoE
      model = SimpleMoEModel(hidden_dim, ep_size=2)
      # optimizer = torch.optim.AdamW(params=model.parameters())
      optimizer = FusedAdam(params=model.parameters())
      engine, optimizer, _, _ = deepspeed.initialize(
          config=config_dict,
          model=model,
          optimizer=optimizer,
          dist_init_required=False,
      )
      monkeypatch.setattr(
          optimizer,
          "unscale_and_clip_grads",
          mock_unscale_and_clip_grads,
      )
      data_loader = sequence_dataloader(
          model=engine,
          total_samples=50,
          hidden_dim=hidden_dim,
          device=engine.device,
      )
      for n, batch in enumerate(data_loader):
          loss = engine(batch[0], batch[1])
          engine.backward(loss)
          engine.step()
  
imports: import torch
  import deepspeed.comm
  import deepspeed
  import pytest
  from deepspeed.ops.adam import FusedAdam
  from unit.common import DistributedTest
  from unit.simple_model import SimpleModel, SimpleOptimizer, random_dataloader, SimpleMoEModel, sequence_dataloader
  from deepspeed.runtime.utils import required_torch_version
  from deepspeed.accelerator import get_accelerator
  from deepspeed.ops.op_builder import CPUAdamBuilder
label_desc: Use image node_id 2 for calling the TestFP16OptimizerForMoE obj's underlying member method code with example usage: obj.test_fused_gradnorm(monkeypatch) and returns: int