class_docstr: Tests for ops in horovod.mxnet. This tests MXNet 2.x specifically.
class_docstr_tok: ["Tests","for","ops","in","horovod.mxnet",".","This","tests","MXNet","2.x","specifically","."]
docstr: Test that the deferred initialized parameters are broadcasted.
docstr_tok: ["Test","that","the","deferred","initialized","parameters","are","broadcasted","."]
code: def test_horovod_broadcast_deferred_init_parameters(self):
      """Test that the deferred initialized parameters are broadcasted."""
      hvd.init()
      root_rank = 0
      rank = hvd.rank()
  
      # This test does not apply if there is only one worker.
      if hvd.size() == 1:
          self.skipTest("Only one worker available")
  
      mx.np.random.seed(rank)
      layer = mx.gluon.nn.Conv2D(10, 2)
      layer.initialize()
      hvd.broadcast_parameters(
          layer.collect_params(), root_rank=root_rank
      )
  
      x = mx.np.ones((5, 4, 10, 10))
      layer(x)
      tensors = [
          p.data() for _, p in sorted(layer.collect_params().items())
      ]
      root_tensors = []
      for tensor in tensors:
          root_tensors.append(
              hvd.broadcast(tensor, root_rank=root_rank)
          )
  
      for tensor, root_tensor in zip(tensors, root_tensors):
          assert same(
              tensor.asnumpy(), root_tensor.asnumpy()
          ), "horovod did not broadcast deferred initialized parameter correctly"
  
file_path: horovod/test/parallel/test_mxnet2.py
imports: import os
  import sys
  import itertools
  import unittest
  from packaging import version
  import pytest
  import numpy
  from base_test_mxnet import *
label_desc: Use image node_id 1 for calling the MX2Tests obj's underlying member method code with example usage: obj.test_horovod_broadcast_deferred_init_parameters() without return types