code: def create_schedule(
      outs: List[LazyBuffer], seen: Optional[Set[LazyBuffer]] = None
  ) -> List[ScheduleItem]:
      if seen is None:
          seen = set()
  
      # start by just realizing the buffers passed in
      realizes: Set[LazyBuffer] = set(
          [x.base for x in outs if not x.base.realized]
      )
      allbufs: Dict[LazyBuffer, None] = {}
      simple_pads: Set[LazyBuffer] = set()
      children: DefaultDict[
          LazyBuffer, Dict[LazyBuffer, None]
      ] = defaultdict(dict)
      for out in outs:
          _recurse_lb(
              out.base,
              realizes,
              allbufs,
              simple_pads,
              children,
              scheduled=True,
          )
  
      # check if we have to realize pads
      for p in simple_pads:
          if not _is_padding_okay(p, realizes):
              realizes.add(p)
  
      # find all reduces, and pair them to a elementwise op. if they can't be cleanly paired, force realize the reduce (or a contig child)
      reduce_for_op: Dict[LazyBuffer, LazyBuffer] = {}
      for r in allbufs.keys():
          if r != r.base or r.op not in ReduceOps or r in realizes:
              continue
  
          # follow the reduce down
          child_set: Dict[LazyBuffer, ShapeTracker] = {r: r.st}
          realized_children: Dict[LazyBuffer, ShapeTracker] = {}
          forced_realize = False
          can_chase = True
          while not forced_realize and len(child_set):
              next_child_set = {}
              for tr, st in child_set.items():
                  if tr in realizes:
                      realized_children[tr] = st
                      # can only have one output buffer
                      # can only reduce contiguous
                      # max one reduceop per kernel
                      if (
                          len(realized_children) > 1
                          or not st.contiguous
                          or st.size != r.st.size
                          or (
                              tr in reduce_for_op
                              and reduce_for_op[tr] != r
                          )
                      ):
                          can_chase = (
                              tr not in reduce_for_op
                              or reduce_for_op[tr] == r
                          )
                          forced_realize = True
                          break
                      continue
                  for tr_next in children[tr].keys():
                      if not tr_next.realized:
                          # max one reduceop per kernel
                          if tr_next.op in ReduceOps:
                              forced_realize = True
                              break
                          st_childs = dedup(
                              [s for s in tr_next.srcs if s.base == tr]
                          )
                          if len(st_childs) > 1:
                              forced_realize = True
                              break
                          next_child_set[tr_next] = st + st_childs[0].st
              child_set = next_child_set
          if forced_realize:
              tr = r
              if can_chase:
                  # can chase this down to contiguous children
                  st = tr.st
                  while len(children[tr]) == 1:
                      tr_next = next(iter(children[tr].keys()))
                      st_childs = dedup(
                          [s for s in tr_next.srcs if s.base == tr]
                      )
                      if len(st_childs) > 1:
                          break
                      if st.size != st_childs[0].st.size:
                          break
                      st = st + st_childs[0].st
                      if not st.contiguous or tr_next.op in ReduceOps:
                          break
                      tr = tr_next
                  reduce_for_op[tr] = r
              realizes.add(tr)
          else:
              assert len(realized_children) == 1
              reduce_for_op[next(iter(realized_children.keys()))] = r
  
      return flatten(
          _recursive_schedule(x.base, seen, realizes, reduce_for_op)
          for x in outs
      )
  
imports: from __future__ import annotations
  import sys, math
  from collections import defaultdict
  from typing import Union, Optional, Any, Tuple, List, Set, Dict, DefaultDict, cast
  from tinygrad.dtype import dtypes, DType, ImageDType
  from tinygrad.helpers import prod, flatten, getenv, dedup, DEBUG, all_int, all_same, GRAPH
  from tinygrad.ops import LoadOps, UnaryOps, BinaryOps, TernaryOps, ReduceOps, BufferOps, Op, LazyOp, ConstBuffer, MemBuffer, ScheduleItem
  from tinygrad.shape.symbolic import sint, Variable
  from tinygrad.shape.shapetracker import ShapeTracker
  from tinygrad.device import Buffer
  from tinygrad.graph import log_lazybuffer
  from weakref import ref, ReferenceType
label_desc: Use image node_id 6 for calling a global function with example usage: create_schedule(outs, seen) and returns: flatten