'''simple docstring'''




from typing import List, Optional, Tuple, Union

import torch

from ...models import UNetaDModel
from ...schedulers import ScoreSdeVeScheduler
from ...utils import randn_tensor
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput


class       UpperCAmelCase__  (       _snake_case			):






   """simple docstring"""
   A							:       UNetaDModel
   A							:       ScoreSdeVeScheduler
   def __init__(self       ,				_a       ,				_a				)    ->     Union[str, Any]:
        super().__init__()
        self.register_modules(unet=_a       ,				scheduler=_a				)





   @torch.no_grad()
   def __call__(self       ,				_a = 1       ,				_a = 2_000       ,				_a = None       ,				_a = "pil"       ,				_a = True       ,				**_a       ,				)    ->     Union[ImagePipelineOutput, Tuple]:
        lowercase_					:       Any     				=					self.unet.config.sample_size
        lowercase_					:       List[Any]     				=					(batch_size, 3, img_size, img_size)

        lowercase_					:       Any     				=					self.unet

        lowercase_					:       Tuple     				=					randn_tensor(_a       ,				generator=_a				) * self.scheduler.init_noise_sigma
        lowercase_					:       Optional[int]     				=					sample.to(self.device				)

        self.scheduler.set_timesteps(_a				)
        self.scheduler.set_sigmas(_a				)

        for i, t in enumerate(self.progress_bar(self.scheduler.timesteps				)				):
             lowercase_					:       Optional[Any]     				=					self.scheduler.sigmas[i] * torch.ones(shape[0]       ,				device=self.device				)

             # correction step
             for _ in range(self.scheduler.config.correct_steps				):
                  lowercase_					:       List[str]     				=					self.unet(_a       ,				_a				).sample
                  lowercase_					:       Optional[int]     				=					self.scheduler.step_correct(_a       ,				_a       ,				generator=_a				).prev_sample

             # prediction step
             lowercase_					:       List[str]     				=					model(_a       ,				_a				).sample
             lowercase_					:       List[str]     				=					self.scheduler.step_pred(_a       ,				_a       ,				_a       ,				generator=_a				)

             lowercase_				,lowercase_					:       List[str]     				=					output.prev_sample, output.prev_sample_mean

        lowercase_					:       List[Any]     				=					sample_mean.clamp(0       ,				1				)
        lowercase_					:       Optional[int]     				=					sample.cpu().permute(0       ,				2       ,				3       ,				1				).numpy()
        if output_type == "pil":
             lowercase_					:       List[str]     				=					self.numpy_to_pil(_a				)

        if not return_dict:
             return (sample,)

        return ImagePipelineOutput(images=_a				)





'''simple docstring'''




import os

def _UpperCamelCase   (       SCREAMING_SNAKE_CASE_							):
     lowercase_					:       List[Any]     				=					len(grid[0]							)
     lowercase_					:       Union[str, Any]     				=					len(SCREAMING_SNAKE_CASE_							)

     lowercase_					:       Union[str, Any]     				=					0
     lowercase_					:       int     				=					0
     lowercase_					:       Union[str, Any]     				=					0

     # Check vertically, horizontally, diagonally at the same time (only works
     # for nxn grid)
     for i in range(SCREAMING_SNAKE_CASE_							):
          for j in range(n_rows - 3							):
               lowercase_					:       Dict     				=					grid[j][i] * grid[j + 1][i] * grid[j + 2][i] * grid[j + 3][i]
               lowercase_					:       Optional[Any]     				=					grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3]

               # Left-to-right diagonal (\) product
               if i < n_columns - 3:
                    lowercase_					:       Tuple     				=					(
                        grid[i][j]
                        * grid[i + 1][j + 1]
                        * grid[i + 2][j + 2]
                        * grid[i + 3][j + 3]
                    )

               # Right-to-left diagonal(/) product
               if i > 2:
                    lowercase_					:       int     				=					(
                        grid[i][j]
                        * grid[i - 1][j + 1]
                        * grid[i - 2][j + 2]
                        * grid[i - 3][j + 3]
                    )

               lowercase_					:       Optional[int]     				=					max(
                   SCREAMING_SNAKE_CASE_  ,       SCREAMING_SNAKE_CASE_  ,       SCREAMING_SNAKE_CASE_  ,       SCREAMING_SNAKE_CASE_							)
               if max_product > largest:
                    lowercase_					:       List[Any]     				=					max_product

     return largest

def _UpperCamelCase   (       ):
     lowercase_					:       int     				=					[]
     with open(os.path.dirname(SCREAMING_SNAKE_CASE_							) + '/grid.txt'							) as file:
          for line in file:
               grid.append(line.strip('\n'							).split(' '							)							)

     lowercase_					:       Dict     				=					[[int(SCREAMING_SNAKE_CASE_							) for i in grid[j]] for j in range(len(SCREAMING_SNAKE_CASE_							)							)]

     return largest_product(SCREAMING_SNAKE_CASE_							)


if __name__ == "__main__":
 print(solution())




