code: def test_fast_memonger(self, input_dim, output_dim, batch_size, do):
      m = model_helper.ModelHelper()
      fc1 = brew.fc(
          m, "data", "fc1", dim_in=input_dim, dim_out=output_dim
      )
      fc2 = brew.fc(
          m, fc1, "fc2", dim_in=output_dim, dim_out=output_dim
      )
      fc3 = brew.fc(
          m, fc2, "fc3", dim_in=output_dim, dim_out=output_dim
      )
  
      fc3.Relu([], fc3).Softmax([], "pred").LabelCrossEntropy(
          ["label"], ["xent"]
      ).AveragedLoss([], "loss")
      input_to_grad = m.AddGradientOperators(["loss"])
      m.net.Proto().device_option.CopyFrom(do)
      m.param_init_net.Proto().device_option.CopyFrom(do)
      static_blobs = [
          o for op in m.param_init_net.Proto().op for o in op.output
      ] + ["data", "label", "loss", input_to_grad["fc1_w"]]
  
      optimized_net = memonger.optimize_inference_fast(
          m.Proto(), static_blobs
      )
      data = np.random.randn(batch_size, input_dim).astype(np.float32)
      label = np.random.randint(
          low=0, high=output_dim, size=(batch_size,)
      ).astype(np.int32)
      workspace.RunNetOnce(m.param_init_net)
      workspace.FeedBlob("data", data, device_option=do)
      workspace.FeedBlob("label", label, device_option=do)
      workspace.RunNetOnce(m.net)
      loss = workspace.FetchBlob("loss")
      grad = workspace.FetchBlob(str(input_to_grad["fc1_w"]))
      workspace.RunNetOnce(optimized_net)
      optimized_loss = workspace.FetchBlob("loss")
      optimized_grad = workspace.FetchBlob(str(input_to_grad["fc1_w"]))
      np.testing.assert_almost_equal(loss, optimized_loss)
      np.testing.assert_almost_equal(grad, optimized_grad)
  
      self.assertLess(
          count_blobs(optimized_net), count_blobs(m.Proto())
      )
  
imports: import numpy
  from caffe2.python import workspace, memonger, core, model_helper, brew
  from caffe2.proto import caffe2_pb2
  import caffe2.python.hypothesis_test_util
  import hypothesis.strategies
  from hypothesis import given, settings
  import unittest
label_desc: Use image node_id 2 for calling the MemongerTest obj's underlying member method code with example usage: obj.test_fast_memonger(input_dim, output_dim, batch_size, do) without return types