code: def parse_memory(v: Optional[Union[int, str]]) -> Optional[int]:
      """
      Converts human-readable sizes (MB and GB) to megabytes
      >>> parse_memory("512MB")
      512
      >>> parse_memory("1 GB")
      1024
      """
      if v is None:
          return None
      if isinstance(v, str):
          m = re.fullmatch(r"(\d+) *([mg]b)?", v.strip().lower())
          if not m:
              raise ValueError(f"Invalid memory size: {v}")
          v = int(m.group(1))
          if m.group(2) == "gb":
              v = v * 1024
      return int(v)
  
imports: import re
  from enum import Enum
  from typing import List, Optional, Tuple, Union
  from pydantic import Field, confloat, root_validator, validator
  from typing_extensions import Annotated, Literal
  from dstack._internal.core.models.backends.base import BackendType
  from dstack._internal.core.models.common import ForbidExtra
label_desc: Use image node_id 1 for calling a global function with example usage: parse_memory(v) and returns: int, None