code: def cosine_schedule(
      step: int,
      max_steps: int,
      start_value: float,
      end_value: float,
      period: Optional[int] = None,
  ) -> float:
      """Use cosine decay to gradually modify start_value to reach target end_value during
      iterations.
  
      Args:
          step:
              Current step number.
          max_steps:
              Total number of steps.
          start_value:
              Starting value.
          end_value:
              Target value.
          period (optional):
              The number of steps over which the cosine function completes a full cycle.
              If not provided, it defaults to max_steps.
  
      Returns:
          Cosine decay value.
  
      """
      if step < 0:
          raise ValueError("Current step number can't be negative")
      if max_steps < 1:
          raise ValueError("Total step number must be >= 1")
      if period is None and step > max_steps:
          warnings.warn(
              f"Current step number {step} exceeds max_steps {max_steps}.",
              category=RuntimeWarning,
          )
      if period is not None and period <= 0:
          raise ValueError("Period must be >= 1")
  
      decay: float
      if period is not None:  # "cycle" based on period, if provided
          decay = (
              end_value
              - (end_value - start_value)
              * (np.cos(2 * np.pi * step / period) + 1)
              / 2
          )
      elif max_steps == 1:
          # Avoid division by zero
          decay = end_value
      elif step == max_steps:
          # Special case for Pytorch Lightning which updates LR scheduler also for epoch
          # after last training epoch.
          decay = end_value
      else:
          decay = (
              end_value
              - (end_value - start_value)
              * (np.cos(np.pi * step / (max_steps - 1)) + 1)
              / 2
          )
      return decay
  
file_path: lightly/lightly/utils/scheduler.py
imports: import warnings
  from typing import Optional
  import numpy
  import torch
label_desc: Use image node_id 1 for calling a global function with example usage: cosine_schedule(step, max_steps, start_value, end_value, period) and returns: decay