code: def parse_duration(v: Optional[Union[int, str]]) -> Optional[int]:
      if v is None:
          return None
      if isinstance(v, int):
          return v
      regex = re.compile(r"(?P<amount>\d+) *(?P<unit>[smhdw])$")
      re_match = regex.match(v)
      if not re_match:
          raise ValueError(f"Cannot parse the duration {v}")
      amount, unit = int(re_match.group("amount")), re_match.group(
          "unit"
      )
      multiplier = {
          "s": 1,
          "m": 60,
          "h": 3600,
          "d": 24 * 3600,
          "w": 7 * 24 * 3600,
      }[unit]
      return amount * multiplier
  
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 2 for calling a global function with example usage: parse_duration(v) and returns: unknown, None, v