<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _patch_tf(tf):
 """Patch TF to maintain compatibility across versions."""

  global TF_PATCH
  if TF_PATCH:
    return

  v_1_12 = distutils.version.LooseVersion("1.12.0")
  v_1_13 = distutils.version.LooseVersion("1.13.0")
  v_2 = distutils.version.LooseVersion("2.0.0")
  tf_version = distutils.version.LooseVersion(tf.__version__)
  if v_1_12 <= tf_version < v_1_13:
    # TODO(b/123930850): remove when 1.13 is stable.
    TF_PATCH = "tf1_12"
    _patch_for_tf1_12(tf)
  elif v_1_13 <= tf_version < v_2:
    TF_PATCH = "tf1_13"
    _patch_for_tf1_13(tf)
  else:
    TF_PATCH = "tf2"
    _patch_for_tf2(tf)