code: def generate_patch_grid_from_normalized_LAF(
      img: Tensor, LAF: Tensor, PS: int = 32
  ) -> Tensor:
      """Helper function for affine grid generation.
  
      Args:
          img: image tensor of shape :math:`(B, CH, H, W)`.
          LAF: laf with shape :math:`(B, N, 2, 3)`.
          PS: patch size to be extracted.
  
      Returns:
          grid :math:`(B*N, PS, PS, 2)`
      """
      KORNIA_CHECK_LAF(LAF)
      B, N, _, _ = LAF.size()
      _, ch, h, w = img.size()
  
      # norm, then renorm is needed for allowing detection on one resolution
      # and extraction at arbitrary other
      LAF_renorm = denormalize_laf(LAF, img)
  
      grid = F.affine_grid(
          LAF_renorm.view(B * N, 2, 3),
          [B * N, ch, PS, PS],
          align_corners=False,
      )
      grid[..., :, 0] = (
          2.0 * grid[..., :, 0].clone() / float(w - 1) - 1.0
      )
      grid[..., :, 1] = (
          2.0 * grid[..., :, 1].clone() / float(h - 1) - 1.0
      )
      return grid
  
imports: import math
  from typing import List, Optional, Tuple, Union
  import torch
  import torch.nn.functional
  from kornia.core import Tensor, concatenate, cos, sin, stack, tensor, zeros
  from kornia.core.check import KORNIA_CHECK_LAF, KORNIA_CHECK_SHAPE
  from kornia.geometry.conversions import angle_to_rotation_matrix, convert_points_from_homogeneous, rad2deg
  from kornia.geometry.linalg import transform_points
  from kornia.geometry.transform import pyrdown
label_desc: Use image node_id 14 for calling a global function with example usage: generate_patch_grid_from_normalized_LAF(img, LAF, PS) and returns: grid