code: def test_green_red_not_use_extraneous_cast(target_precision):
      """Conv. is a green listed operation, while softmax is red.
  
      Conv. also by default accumulates to fp32 but outputs fp16.
  
      We want to avoid a situation where we have extraneous casts.
      E.g. because softmax wants to operate on FP32 we might have
  
      conv (FP32) -> cast (FP16) -> cast (FP32) -> softmax (FP32)
  
      To get around this internally when we cast in the pass we cache
      the output nodes and the reverse of the cast back to the original
      node. For example casting the `conv (FP32)` to FP16 would produce:
  
      `conv (FP32) -> cast (FP16)`
  
      As the outputs. Now anytime we try to cast the `conv (FP32)` node
      to FP16 it would return the cached result instead of a new cast node:
  
      `conv (FP32) -> cast (FP16)`
  
      Furthermore, if we try to cast the `cast (FP16)` node back to FP32 it
      would just return
  
      `conv (FP32)`.
  
      This test makes sure this behavior occurs.
      """
      data_shape = (1, 3, 32, 32)
      weight_shape = (5, 3, 3, 3)
      data = relay.var("data", shape=data_shape, dtype="float32")
      weight = relay.var("weight", shape=weight_shape, dtype="float32")
      conv = relay.nn.conv2d(
          data,
          weight,
          strides=(1, 1),
          padding=(1, 1),
          out_dtype="float32",
      )
      result = relay.nn.softmax(conv)
      mod = tvm.IRModule.from_expr(result)
  
      mod_params = {
          "data": np.random.uniform(-1, 1, size=data_shape).astype(
              "float32"
          ),
          "weight": np.random.uniform(-1, 1, size=weight_shape).astype(
              "float32"
          ),
      }
      amp_mod = verify_mixed_precision_output_close(
          mod,
          mod_params,
          mixed_precision_dtype=target_precision,
          atol=0.01,
          rtol=1e-3,
      )
  
      # Construct expected structure
      conv = relay.cast(
          relay.nn.conv2d(
              relay.cast(data, target_precision),
              relay.cast(weight, target_precision),
              strides=(1, 1),
              padding=(1, 1),
              out_dtype=target_precision,
          ),
          "float32",
      )
      result = relay.nn.softmax(conv)
      expected_mod = tvm.IRModule.from_expr(result)
      expected_mod = InferType()(expected_mod)
  
      assert tvm.ir.structural_equal(expected_mod, amp_mod)
  
imports: from typing import Any, Dict, List
  import numpy
  import pytest
  import tvm
  from tvm import relay
  from tvm.relay.testing import lstm
  from tvm.relay.transform import InferType, ToMixedPrecision, mixed_precision
label_desc: Use image node_id 12 for calling a global function with example usage: test_green_red_not_use_extraneous_cast(target_precision) without return types