code: def helper_linearizer_opt(r: Tensor, opts=[], apply_tc=False):
      wanna_output = None
      realized_ast, real_bufs = helper_realized_ast(r)
  
      def check_opt(opts, create_k, to_prg):
          k = create_k()
          if apply_tc:
              k.apply_tensor_cores(1, opts)
          else:
              for opt in opts:
                  k.apply_opt(opt)
          prg = to_prg(k)
          real_bufs[0].copyin(
              np.zeros(
                  (real_bufs[0].size,), dtype=real_bufs[0].dtype.np
              ).data
          )  # Zero to check that all values are filled
          prg.exec(real_bufs)
          np.testing.assert_allclose(
              wanna_output,
              np.frombuffer(
                  real_bufs[0].as_buffer(), real_bufs[0].dtype.np
              ),
              atol=1e-4,
              rtol=1e-4,
          )
  
      # Get baseline, which is not optimized at all.
      k = Linearizer(realized_ast)
      prg = Device[Device.DEFAULT].to_program(k)
      prg.exec(real_bufs)
      wanna_output = np.frombuffer(
          real_bufs[0].as_buffer(), real_bufs[0].dtype.np
      ).copy()
  
      # Check correctness of handcoded optimiztions.
      k = Linearizer(realized_ast)
      k.hand_coded_optimizations()
      prg = Device[Device.DEFAULT].to_program(k)
      real_bufs[0].copyin(
          np.zeros(
              (real_bufs[0].size,), dtype=real_bufs[0].dtype.np
          ).data
      )  # Zero to check that all values are filled
      prg.exec(real_bufs)
      np.testing.assert_allclose(
          wanna_output,
          np.frombuffer(
              real_bufs[0].as_buffer(), real_bufs[0].dtype.np
          ),
          atol=1e-4,
          rtol=1e-4,
      )
      for x in opts:  # Check custom transformations if any.
          check_opt(
              x,
              lambda: Linearizer(realized_ast),
              Device[Device.DEFAULT].to_program,
          )
  
imports: import numpy
  import unittest, os
  from tinygrad.codegen.kernel import Opt, OptOps, tensor_cores
  from tinygrad.codegen.linearizer import Linearizer, UOp, UOps, expand_node
  from tinygrad.device import Compiled, Device, Buffer
  from tinygrad.ops import BufferOps, MemBuffer, ConstBuffer, LazyOp, LoadOps, TernaryOps
  from tinygrad.shape.shapetracker import ShapeTracker
  from tinygrad.shape.view import View
  from tinygrad.shape.symbolic import MulNode, SumNode, Variable, NumNode, Node, create_rednode
  from tinygrad.tensor import Tensor
  from tinygrad.jit import CacheCollector
  from tinygrad.realize import run_schedule
  from tinygrad.helpers import prod
  from tinygrad.dtype import dtypes
label_desc: Use image node_id 2 for calling a global function with example usage: helper_linearizer_opt(r, opts, apply_tc) without return types