code: def _validate_docker_tag(tag: str) -> str:
      from bentoml.exceptions import BentoMLException
  
      if ":" in tag:
          name, version = tag.split(":")[:2]
      else:
          name, version = tag, None
  
      valid_name_pattern = re.compile(
          r"""
          ^(
          [a-z0-9]+      # alphanumeric
          (.|_{1,2}|-+)? # seperators
          )*$
          """,
          re.VERBOSE,
      )
      valid_version_pattern = re.compile(
          r"""
          ^
          [a-zA-Z0-9] # cant start with .-
          [ -~]{,127} # ascii match rest, cap at 128
          $
          """,
          re.VERBOSE,
      )
  
      if not valid_name_pattern.match(name):
          raise BentoMLException(
              f"Provided Docker Image tag {tag} is invalid. Name components may contain lowercase letters, digits and separators. A separator is defined as a period, one or two underscores, or one or more dashes."
          )
      if version and not valid_version_pattern.match(version):
          raise BentoMLException(
              f"Provided Docker Image tag {tag} is invalid. A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes. A tag name may not start with a period or a dash and may contain a maximum of 128 characters."
          )
      return tag
  
imports: from __future__ import annotations
  import difflib
  import functools
  import logging
  import os
  import re
  import time
  import typing
  import attr
  import click
  import click_option_group
  from click import ClickException
  from click.exceptions import UsageError
label_desc: Use image node_id 2 for calling a global function with example usage: _validate_docker_tag(tag) and returns: tag