class_docstr: Performs automatic optimization (forward, zero grad, backward, optimizer step)
docstr: Build a `zero_grad` function that zeroes the gradients before back-propagation.
  
  Returns ``None`` in the case backward needs to be skipped.
code: def _make_zero_grad_fn(
      self, batch_idx: int, optimizer: Optimizer
  ) -> Optional[Callable[[], None]]:
      """Build a `zero_grad` function that zeroes the gradients before back-propagation.
  
      Returns ``None`` in the case backward needs to be skipped.
  
      """
      if self._skip_backward:
          return None
  
      is_first_batch_to_accumulate = (
          batch_idx % self.trainer.accumulate_grad_batches == 0
      )
      if not is_first_batch_to_accumulate:
          return None
  
      def zero_grad_fn() -> None:
          self._on_before_zero_grad(optimizer)
          self._optimizer_zero_grad(batch_idx, optimizer)
  
      return zero_grad_fn
  
imports: from dataclasses import dataclass, field
  from functools import partial
  from typing import Any, Callable, Dict, Mapping, Optional, OrderedDict
  import torch
  from torch import Tensor
  from torch.optim import Optimizer
  from typing_extensions import override
  import lightning.pytorch
  from lightning.pytorch.loops.loop import _Loop
  from lightning.pytorch.loops.optimization.closure import AbstractClosure, OutputResult
  from lightning.pytorch.loops.progress import _OptimizationProgress
  from lightning.pytorch.loops.utilities import _block_parallel_sync_behavior
  from lightning.pytorch.trainer import call
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning.pytorch.utilities.rank_zero import WarningCache
  from lightning.pytorch.utilities.types import STEP_OUTPUT
label_desc: Use image node_id 5 for calling the _AutomaticOptimization obj's underlying member method code with example usage: obj._make_zero_grad_fn(batch_idx, optimizer) and returns: zero_grad_fn, None, None