def prepare_tiles(
        self,
        grid_rows,
        grid_cols,
        tile_weighting_method,
        tile_width,
        tile_height,
        normal_tile_overlap,
        border_tile_overlap,
        width,
        height,
        tile_sigma,
        batch_size,
        device,
        dtype,
    ):
        """
        Processes image tiles by dynamically adjusting overlap and calculating Gaussian or cosine weights.

        Args:
            grid_rows (int): Number of rows in the tile grid.
            grid_cols (int): Number of columns in the tile grid.
            tile_weighting_method (str): Method for weighting tiles. Options: "Gaussian" or "Cosine".
            tile_width (int): Width of each tile in pixels.
            tile_height (int): Height of each tile in pixels.
            normal_tile_overlap (int): Overlap between tiles in pixels for normal tiles.
            border_tile_overlap (int): Overlap between tiles in pixels for border tiles.
            width (int): Width of the image in pixels.
            height (int): Height of the image in pixels.
            tile_sigma (float): Sigma parameter for Gaussian weighting.
            batch_size (int): Batch size for weight tiles.
            device (torch.device): Device where tensors will be allocated (e.g., 'cuda' or 'cpu').
            dtype (torch.dtype): Data type of the tensors (e.g., torch.float32).

        Returns:
            tuple: A tuple containing:
                - tile_weights (np.ndarray): Array of weights for each tile.
                - tile_row_overlaps (np.ndarray): Array of row overlaps for each tile.
                - tile_col_overlaps (np.ndarray): Array of column overlaps for each tile.
        """

        # Create arrays to store dynamic overlaps and weights
        tile_row_overlaps = np.full((grid_rows, grid_cols), normal_tile_overlap)
        tile_col_overlaps = np.full((grid_rows, grid_cols), normal_tile_overlap)
        tile_weights = np.empty((grid_rows, grid_cols), dtype=object)  # Stores Gaussian or cosine weights

        # Iterate over tiles to adjust overlap and calculate weights
        for row in range(grid_rows):
            for col in range(grid_cols):
                # Calculate the size of the current tile
                px_row_init, px_row_end, px_col_init, px_col_end = _tile2pixel_indices(
                    row, col, tile_width, tile_height, normal_tile_overlap, normal_tile_overlap, width, height
                )
                current_tile_width = px_col_end - px_col_init
                current_tile_height = px_row_end - px_row_init
                sigma = tile_sigma

                # Adjust overlap for smaller tiles
                if current_tile_width < tile_width:
                    px_row_init, px_row_end, px_col_init, px_col_end = _tile2pixel_indices(
                        row, col, tile_width, tile_height, border_tile_overlap, border_tile_overlap, width, height
                    )
                    current_tile_width = px_col_end - px_col_init
                    tile_col_overlaps[row, col] = border_tile_overlap
                    sigma = tile_sigma * 1.2
                if current_tile_height < tile_height:
                    px_row_init, px_row_end, px_col_init, px_col_end = _tile2pixel_indices(
                        row, col, tile_width, tile_height, border_tile_overlap, border_tile_overlap, width, height
                    )
                    current_tile_height = px_row_end - px_row_init
                    tile_row_overlaps[row, col] = border_tile_overlap
                    sigma = tile_sigma * 1.2

                # Calculate weights for the current tile
                if tile_weighting_method == self.TileWeightingMethod.COSINE.value:
                    tile_weights[row, col] = self._generate_cosine_weights(
                        tile_width=current_tile_width,
                        tile_height=current_tile_height,
                        nbatches=batch_size,
                        device=device,
                        dtype=torch.float32,
                    )
                else:
                    tile_weights[row, col] = self._generate_gaussian_weights(
                        tile_width=current_tile_width,
                        tile_height=current_tile_height,
                        nbatches=batch_size,
                        device=device,
                        dtype=dtype,
                        sigma=sigma,
                    )

        return tile_weights, tile_row_overlaps, tile_col_overlaps

        Processes image tiles by dynamically adjusting overlap and calculating Gaussian or cosine weights.

        Args:
            grid_rows (int): Number of rows in the tile grid.
            grid_cols (int): Number of columns in the tile grid.
            tile_weighting_method (str): Method for weighting tiles. Options: "Gaussian" or "Cosine".
            tile_width (int): Width of each tile in pixels.
            tile_height (int): Height of each tile in pixels.
            normal_tile_overlap (int): Overlap between tiles in pixels for normal tiles.
            border_tile_overlap (int): Overlap between tiles in pixels for border tiles.
            width (int): Width of the image in pixels.
            height (int): Height of the image in pixels.
            tile_sigma (float): Sigma parameter for Gaussian weighting.
            batch_size (int): Batch size for weight tiles.
            device (torch.device): Device where tensors will be allocated (e.g., 'cuda' or 'cpu').
            dtype (torch.dtype): Data type of the tensors (e.g., torch.float32).

        Returns:
            tuple: A tuple containing:
                - tile_weights (np.ndarray): Array of weights for each tile.
                - tile_row_overlaps (np.ndarray): Array of row overlaps for each tile.
                - tile_col_overlaps (np.ndarray): Array of column overlaps for each tile.
        
examples/community/mod_controlnet_tile_sr_sdxl.py