code: def fuzz_linearizer(lin: Linearizer):
      random.seed(42)
      np.random.seed(42)
      print_tree(lin.ast)
      print(lin.colored_shape())
      rawbufs = bufs_from_lin(lin)
  
      seen_uops = {}
      ground_truth = None
      while 1:
          if len(seen_uops) >= 20:
              break  # enough for this kernel
          actions = get_linearizer_actions(lin, include_0=False)
          if not actions:
              break
          lin = random.choice(list(actions.values()))
          if lin.applied_opts:
              print(f"applied action: {lin.applied_opts[-1]}")
  
          # stop if kernel uops repeat
          tuops = tuplize_uops(lin.linearize().uops)
          if tuops in seen_uops:
              break
          seen_uops[tuops] = tuple(lin.applied_opts)
  
          print(lin.colored_shape())
          # get a new output buffer
          rawbufs[0] = type(rawbufs[0])(
              Device.DEFAULT, rawbufs[0].size, rawbufs[0].dtype
          )
          var_vals = {
              v: random.randint(v.min, v.max) for v in lin.ast.vars()
          }
          if (msg := run_linearizer(lin, rawbufs, var_vals)) != "PASS":
              print(f"{lin.applied_opts=}")
              return msg
  
          result = rawbufs[0].toCPU()
          if ground_truth is None:
              ground_truth = result
          else:
              try:
                  np.testing.assert_allclose(
                      result, ground_truth, rtol=1e-2, atol=1e-2
                  )
              except AssertionError:
                  print(lin.ast)
                  traceback.print_exc()
                  print(f"{lin.applied_opts=}")
                  return "NOT_ALLCLOSE"
      return "PASS"
  
file_path: tinygrad/test/external/fuzz_linearizer.py
imports: import random, traceback
  from typing import List, Tuple
  import numpy
  from collections import Counter
  from extra.optimization.helpers import load_worlds, ast_str_to_lin
  from tinygrad.codegen.linearizer import Linearizer
  from tinygrad.features.search import get_linearizer_actions, bufs_from_lin
  from tinygrad.graph import print_tree
  from tinygrad.helpers import getenv
  from tinygrad.device import Device, Compiled, Interpreted
  from tinygrad.codegen.linearizer import UOp
label_desc: Use image node_id 3 for calling a global function with example usage: fuzz_linearizer(lin) and returns: str, msg, str