
'''simple docstring'''



import argparse
import os
from pathlib import Path

import fairseq
import torch
from packaging import version
from torch import nn

from transformers import (
    BartConfig,
    BartForConditionalGeneration,
    BartForSequenceClassification,
    BartModel,
    BartTokenizer,
)
from transformers.utils import logging


_lowercase    =		["""bart.large""", """bart.large.mnli""", """bart.large.cnn""", """bart_xsum/model.pt"""]
_lowercase    =		{"""bart.large""": BartModel, """bart.large.mnli""": BartForSequenceClassification}
if version.parse(fairseq.__version__) < version.parse("""0.9.0"""):
						raise Exception("""requires fairseq >= 0.9.0""")


logging.set_verbosity_info()
_lowercase    =		logging.get_logger(__name__)

_lowercase    =		""" Hello world! cécé herlolip"""

_lowercase    =		[
    ("""model.classification_heads.mnli.dense.weight""", """classification_head.dense.weight"""),
    ("""model.classification_heads.mnli.dense.bias""", """classification_head.dense.bias"""),
    ("""model.classification_heads.mnli.out_proj.weight""", """classification_head.out_proj.weight"""),
    ("""model.classification_heads.mnli.out_proj.bias""", """classification_head.out_proj.bias"""),
]


def A				(__lowerCamelCase				:List[Any]		):
						_lowerCAmelCase  						=			[
						    """encoder.version""",
						    """decoder.version""",
						    """model.encoder.version""",
						    """model.decoder.version""",
						    """_float_tensor""",
						]
						for k in ignore_keys:
												state_dict.pop(__lowerCamelCase			,     __lowerCamelCase		)


def A				(__lowerCamelCase				:Optional[int]			,     __lowerCamelCase				:List[Any]			,     __lowerCamelCase				:Tuple		):
						_lowerCAmelCase  						=			dct.pop(__lowerCamelCase		)
						_lowerCAmelCase  						=			val


def A				(__lowerCamelCase				:str		):
						_lowerCAmelCase  						=			torch.load(__lowerCamelCase			,     map_location="""cpu"""		)
						_lowerCAmelCase  						=			torch.hub.load("""pytorch/fairseq"""			,     """bart.large.cnn"""		).eval()
						hub_interface.model.load_state_dict(sd["""model"""]		)
						return hub_interface


def A				(__lowerCamelCase				:Any		):
						_lowerCAmelCase						,   _lowerCAmelCase  						=			emb.weight.shape
						_lowerCAmelCase  						=			nn.Linear(__lowerCamelCase			,     __lowerCamelCase			,     bias=__lowerCamelCase		)
						_lowerCAmelCase  						=			emb.weight.data
						return lin_layer


@torch.no_grad()
def A				(__lowerCamelCase				:Optional[Any]			,     __lowerCamelCase				:Any			,     __lowerCamelCase				:Dict=None		):
						if not os.path.exists(__lowerCamelCase		):
												_lowerCAmelCase  						=			torch.hub.load("""pytorch/fairseq"""			,     __lowerCamelCase		).eval()
						else:
												_lowerCAmelCase  						=			load_xsum_checkpoint(__lowerCamelCase		)

						bart.model.upgrade_state_dict(bart.model.state_dict()		)
						if hf_checkpoint_name is None:
												_lowerCAmelCase  						=			checkpoint_path.replace("""."""			,     """-"""		)
						_lowerCAmelCase  						=			BartConfig.from_pretrained(__lowerCamelCase		)
						_lowerCAmelCase  						=			bart.encode(__lowerCamelCase		).unsqueeze(0		)
						_lowerCAmelCase  						=			BartTokenizer.from_pretrained(__lowerCamelCase		).encode(__lowerCamelCase			,     return_tensors="""pt"""		).unsqueeze(0		)
						if not torch.eq(__lowerCamelCase			,     __lowerCamelCase		).all():
												raise ValueError(
												    f'converted tokenizer and pretrained tokenizer returned different output: {tokens} != {tokensa}'		)

						if checkpoint_path == "bart.large.mnli":
												_lowerCAmelCase  						=			bart.state_dict()
												remove_ignore_keys_(__lowerCamelCase		)
												_lowerCAmelCase  						=			state_dict["""model.decoder.embed_tokens.weight"""]
												for src, dest in mnli_rename_keys:
																		rename_key(__lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase		)
												_lowerCAmelCase  						=			BartForSequenceClassification(__lowerCamelCase		).eval()
												model.load_state_dict(__lowerCamelCase		)
												_lowerCAmelCase  						=			bart.predict("""mnli"""			,     __lowerCamelCase			,     return_logits=__lowerCamelCase		)
												_lowerCAmelCase  						=			model(__lowerCamelCase		)[0]  # logits
						else:  # no classification heads to worry about
												_lowerCAmelCase  						=			bart.model.state_dict()
												remove_ignore_keys_(__lowerCamelCase		)
												_lowerCAmelCase  						=			state_dict["""decoder.embed_tokens.weight"""]
												_lowerCAmelCase  						=			bart.extract_features(__lowerCamelCase		)
												if hf_checkpoint_name == "facebook/bart-large":
																		_lowerCAmelCase  						=			BartModel(__lowerCamelCase		).eval()
																		model.load_state_dict(__lowerCamelCase		)
																		_lowerCAmelCase  						=			model(__lowerCamelCase		).model[0]
												else:
																		_lowerCAmelCase  						=			BartForConditionalGeneration(__lowerCamelCase		).eval()  # an existing summarization ckpt
																		model.model.load_state_dict(__lowerCamelCase		)
																		if hasattr(__lowerCamelCase			,     """lm_head"""		):
																								_lowerCAmelCase  						=			make_linear_from_emb(model.model.shared		)
																		_lowerCAmelCase  						=			model.model(__lowerCamelCase		)[0]

    # Check results
						if fairseq_output.shape != new_model_outputs.shape:
												raise ValueError(
												    f'`fairseq_output` shape and `new_model_output` shape are different: {fairseq_output.shape=}, {new_model_outputs.shape}'		)
						if (fairseq_output != new_model_outputs).any().item():
												raise ValueError("""Some values in `fairseq_output` are different from `new_model_outputs`"""		)
						Path(__lowerCamelCase		).mkdir(exist_ok=__lowerCamelCase		)
						model.save_pretrained(__lowerCamelCase		)


if __name__ == "__main__":
						_lowercase    =		argparse.ArgumentParser()
						# Required parameters
						parser.add_argument(
						    """fairseq_path""", type=str, help="""bart.large, bart.large.cnn or a path to a model.pt on local filesystem."""
						)
						parser.add_argument("""pytorch_dump_folder_path""", default=None, type=str, help="""Path to the output PyTorch model.""")
						parser.add_argument(
						    """--hf_config""", default=None, type=str, help="""Which huggingface architecture to use: bart-large-xsum"""
						)
						_lowercase    =		parser.parse_args()
						convert_bart_checkpoint(args.fairseq_path, args.pytorch_dump_folder_path, hf_checkpoint_name=args.hf_config)


'''simple docstring'''



import os


def A				():
						with open(os.path.dirname(__lowerCamelCase		) + """/grid.txt"""		) as f:
												_lowerCAmelCase  						=			[]  # noqa: E741
												for _ in range(20		):
																		l.append([int(__lowerCamelCase		) for x in f.readline().split()]		)

												_lowerCAmelCase  						=			0

												# right
												for i in range(20		):
																		for j in range(17		):
																								_lowerCAmelCase  						=			l[i][j] * l[i][j + 1] * l[i][j + 2] * l[i][j + 3]
																								if temp > maximum:
																														_lowerCAmelCase  						=			temp

        # down
												for i in range(17		):
																		for j in range(20		):
																								_lowerCAmelCase  						=			l[i][j] * l[i + 1][j] * l[i + 2][j] * l[i + 3][j]
																								if temp > maximum:
																														_lowerCAmelCase  						=			temp

        # diagonal 1
												for i in range(17		):
																		for j in range(17		):
																								_lowerCAmelCase  						=			l[i][j] * l[i + 1][j + 1] * l[i + 2][j + 2] * l[i + 3][j + 3]
																								if temp > maximum:
																														_lowerCAmelCase  						=			temp

        # diagonal 2
												for i in range(17		):
																		for j in range(3			,     20		):
																								_lowerCAmelCase  						=			l[i][j] * l[i + 1][j - 1] * l[i + 2][j - 2] * l[i + 3][j - 3]
																								if temp > maximum:
																														_lowerCAmelCase  						=			temp
												return maximum


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