code: def test_builder_to_backend_stress(
      self, compute_unit, backend, n_sample, n_class
  ):
      output_name = "random_categorical"
      logits = np.random.rand(2, n_class)
      probs = [self.softmax(logits[0]), self.softmax(logits[1])]
  
      # Test logits input
      input_placeholders = {"x": mb.placeholder(shape=(2, n_class))}
      input_values = {"x": logits}
  
      def build(x):
          return [
              mb.random_categorical(
                  x=x, size=n_sample, mode="logits", name=output_name
              )
          ]
  
      prediction = get_core_ml_prediction(
          build,
          input_placeholders,
          input_values,
          backend=backend,
          compute_unit=compute_unit,
      )
  
      ref0 = np.random.multinomial(n_sample, probs[0])
      ref1 = np.random.multinomial(n_sample, probs[1])
  
      pred0 = prediction[output_name].reshape(2, n_sample)[0]
      pred1 = prediction[output_name].reshape(2, n_sample)[1]
  
      # convert to bincount and validate probabilities
      pred0 = np.bincount(
          np.array(pred0).astype(np.int32), minlength=n_class
      )
      pred1 = np.bincount(
          np.array(pred1).astype(np.int32), minlength=n_class
      )
  
      assert np.allclose(
          np.true_divide(pred0, n_sample), probs[0], atol=1e-2
      )
      assert np.allclose(
          np.true_divide(pred0, n_sample),
          np.true_divide(ref0, n_sample),
          atol=1e-2,
      )
  
      assert np.allclose(
          np.true_divide(pred1, n_sample), probs[1], atol=1e-2
      )
      assert np.allclose(
          np.true_divide(pred1, n_sample),
          np.true_divide(ref1, n_sample),
          atol=1e-2,
      )
  
      # Test probs input
      input_placeholders = {"x": mb.placeholder(shape=(2, n_class))}
      input_values = {"x": np.array(probs)}
  
      def build(x):
          return [
              mb.random_categorical(
                  x=x, size=n_sample, mode="probs", name=output_name
              )
          ]
  
      prediction = get_core_ml_prediction(
          build,
          input_placeholders,
          input_values,
          backend=backend,
          compute_unit=compute_unit,
      )
  
      pred0 = prediction[output_name].reshape(2, n_sample)[0]
      pred1 = prediction[output_name].reshape(2, n_sample)[1]
  
      # convert to bincount and validate probabilities
      pred0 = np.bincount(
          np.array(pred0).astype(np.int32), minlength=n_class
      )
      pred1 = np.bincount(
          np.array(pred1).astype(np.int32), minlength=n_class
      )
  
      assert np.allclose(
          np.true_divide(pred0, n_sample), probs[0], atol=1e-2
      )
      assert np.allclose(
          np.true_divide(pred0, n_sample),
          np.true_divide(ref0, n_sample),
          atol=1e-2,
      )
  
      assert np.allclose(
          np.true_divide(pred1, n_sample), probs[1], atol=1e-2
      )
      assert np.allclose(
          np.true_divide(pred1, n_sample),
          np.true_divide(ref1, n_sample),
          atol=1e-2,
      )
  
imports: import itertools
  import numpy
  import pytest
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import types
  from coremltools.converters.mil.mil.ops.tests.iOS14 import backends
  from coremltools.converters.mil.mil.ops.tests.testing_utils import UNK_SYM, run_compare_builder
  from coremltools.converters.mil.testing_reqs import compute_units
  from coremltools.converters.mil.testing_utils import get_core_ml_prediction
  from coremltools.models.utils import _macos_version
label_desc: Use image node_id 3 for calling the TestRandomCategorical obj's underlying member method code with example usage: obj.test_builder_to_backend_stress(compute_unit, backend, n_sample, n_class) and returns: list, list