



'''simple docstring'''





import subprocess
import sys

from transformers import BertConfig, BertModel, BertTokenizer, pipeline
from transformers.testing_utils import TestCasePlus, require_torch






class 	lowerCAmelCase_(    SCREAMING_SNAKE_CASE_					):
  '''simple docstring'''




  @require_torch
  def 							UpperCAmelCase_     (   self				)   ->		int:
      # this test is a bit tricky since TRANSFORMERS_OFFLINE can only be changed before
      # `transformers` is loaded, and it's too late for inside pytest - so we are changing it
      # while running an external program

      # python one-liner segments

      # this must be loaded before socket.socket is monkey-patched
      lowerCAmelCase__			:  Tuple											= """
from transformers import BertConfig, BertModel, BertTokenizer, pipeline
        """

      lowerCAmelCase__			:  str											= """
mname = \"hf-internal-testing/tiny-random-bert\"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
BertTokenizer.from_pretrained(mname)
pipe = pipeline(task=\"fill-mask\", model=mname)
print(\"success\")
        """

      lowerCAmelCase__			:  List[Any]											= """
import socket
def offline_socket(*args, **kwargs): raise RuntimeError(\"Offline mode is enabled, we shouldn't access internet\")
socket.socket = offline_socket
        """

      # Force fetching the files so that we can use the cache
      lowerCAmelCase__			:  int											= """hf-internal-testing/tiny-random-bert"""
      BertConfig.from_pretrained(__UpperCAmelCase				)
      BertModel.from_pretrained(__UpperCAmelCase				)
      BertTokenizer.from_pretrained(__UpperCAmelCase				)
      pipeline(task="""fill-mask"""  ,model=__UpperCAmelCase				)

      # baseline - just load from_pretrained with normal network
      lowerCAmelCase__			:  str											= [sys.executable, """-c""", """\n""".join([load, run, mock]				)]

      # should succeed
      lowerCAmelCase__			:  Any											= self.get_env()
      # should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
      lowerCAmelCase__			:  Optional[Any]											= """1"""
      lowerCAmelCase__			:  str											= subprocess.run(__UpperCAmelCase  ,env=__UpperCAmelCase  ,check=__UpperCAmelCase  ,capture_output=__UpperCAmelCase				)
      self.assertEqual(result.returncode  ,0  ,result.stderr				)
      self.assertIn("""success"""  ,result.stdout.decode()				)




  @require_torch
  def 							UpperCAmelCase_     (   self				)   ->		Optional[Any]:
      # python one-liner segments
      # this must be loaded before socket.socket is monkey-patched
      lowerCAmelCase__			:  List[Any]											= """
from transformers import BertConfig, BertModel, BertTokenizer, pipeline
        """

      lowerCAmelCase__			:  List[str]											= """
mname = \"hf-internal-testing/tiny-random-bert\"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
BertTokenizer.from_pretrained(mname)
pipe = pipeline(task=\"fill-mask\", model=mname)
print(\"success\")
        """

      lowerCAmelCase__			:  List[str]											= """
import socket
def offline_socket(*args, **kwargs): raise socket.error(\"Faking flaky internet\")
socket.socket = offline_socket
        """

      # Force fetching the files so that we can use the cache
      lowerCAmelCase__			:  int											= """hf-internal-testing/tiny-random-bert"""
      BertConfig.from_pretrained(__UpperCAmelCase				)
      BertModel.from_pretrained(__UpperCAmelCase				)
      BertTokenizer.from_pretrained(__UpperCAmelCase				)
      pipeline(task="""fill-mask"""  ,model=__UpperCAmelCase				)

      # baseline - just load from_pretrained with normal network
      lowerCAmelCase__			:  Union[str, Any]											= [sys.executable, """-c""", """\n""".join([load, run, mock]				)]

      # should succeed
      lowerCAmelCase__			:  str											= self.get_env()
      lowerCAmelCase__			:  str											= subprocess.run(__UpperCAmelCase  ,env=__UpperCAmelCase  ,check=__UpperCAmelCase  ,capture_output=__UpperCAmelCase				)
      self.assertEqual(result.returncode  ,0  ,result.stderr				)
      self.assertIn("""success"""  ,result.stdout.decode()				)




  @require_torch
  def 							UpperCAmelCase_     (   self				)   ->		Any:
      # this test is a bit tricky since TRANSFORMERS_OFFLINE can only be changed before
      # `transformers` is loaded, and it's too late for inside pytest - so we are changing it
      # while running an external program

      # python one-liner segments

      # this must be loaded before socket.socket is monkey-patched
      lowerCAmelCase__			:  Tuple											= """
from transformers import BertConfig, BertModel, BertTokenizer
        """

      lowerCAmelCase__			:  str											= """
mname = \"hf-internal-testing/tiny-random-bert-sharded\"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
print(\"success\")
        """

      lowerCAmelCase__			:  int											= """
import socket
def offline_socket(*args, **kwargs): raise ValueError(\"Offline mode is enabled\")
socket.socket = offline_socket
        """

      # baseline - just load from_pretrained with normal network
      lowerCAmelCase__			:  Tuple											= [sys.executable, """-c""", """\n""".join([load, run]				)]

      # should succeed
      lowerCAmelCase__			:  List[str]											= self.get_env()
      lowerCAmelCase__			:  int											= subprocess.run(__UpperCAmelCase  ,env=__UpperCAmelCase  ,check=__UpperCAmelCase  ,capture_output=__UpperCAmelCase				)
      self.assertEqual(result.returncode  ,0  ,result.stderr				)
      self.assertIn("""success"""  ,result.stdout.decode()				)

      # next emulate no network
      lowerCAmelCase__			:  Union[str, Any]											= [sys.executable, """-c""", """\n""".join([load, mock, run]				)]

      # Doesn't fail anymore since the model is in the cache due to other tests, so commenting this.
      # env["TRANSFORMERS_OFFLINE"] = "0"
      # result = subprocess.run(cmd, env=env, check=False, capture_output=True)
      # self.assertEqual(result.returncode, 1, result.stderr)

      # should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
      lowerCAmelCase__			:  Dict											= """1"""
      lowerCAmelCase__			:  Any											= subprocess.run(__UpperCAmelCase  ,env=__UpperCAmelCase  ,check=__UpperCAmelCase  ,capture_output=__UpperCAmelCase				)
      self.assertEqual(result.returncode  ,0  ,result.stderr				)
      self.assertIn("""success"""  ,result.stdout.decode()				)




  @require_torch
  def 							UpperCAmelCase_     (   self				)   ->		str:
      lowerCAmelCase__			:  int											= """
from transformers import pipeline
        """
      lowerCAmelCase__			:  Union[str, Any]											= """
mname = \"hf-internal-testing/tiny-random-bert\"
pipe = pipeline(model=mname)
        """

      lowerCAmelCase__			:  Union[str, Any]											= """
import socket
def offline_socket(*args, **kwargs): raise socket.error(\"Offline mode is enabled\")
socket.socket = offline_socket
        """
      lowerCAmelCase__			:  Any											= self.get_env()
      lowerCAmelCase__			:  str											= """1"""
      lowerCAmelCase__			:  int											= [sys.executable, """-c""", """\n""".join([load, mock, run]				)]
      lowerCAmelCase__			:  Optional[Any]											= subprocess.run(__UpperCAmelCase  ,env=__UpperCAmelCase  ,check=__UpperCAmelCase  ,capture_output=__UpperCAmelCase				)
      self.assertEqual(result.returncode  ,1  ,result.stderr				)
      self.assertIn(
          """You cannot infer task automatically within `pipeline` when using offline mode"""  ,result.stderr.decode().replace("""\n"""  ,""""""				)  ,)






  @require_torch
  def 							UpperCAmelCase_     (   self				)   ->		Optional[int]:
      lowerCAmelCase__			:  List[Any]											= """
from transformers import AutoModel
        """
      lowerCAmelCase__			:  Optional[Any]											= """
mname = \"hf-internal-testing/test_dynamic_model\"
AutoModel.from_pretrained(mname, trust_remote_code=True)
print(\"success\")
        """

      # baseline - just load from_pretrained with normal network
      lowerCAmelCase__			:  Union[str, Any]											= [sys.executable, """-c""", """\n""".join([load, run]				)]

      # should succeed
      lowerCAmelCase__			:  Dict											= self.get_env()
      lowerCAmelCase__			:  Tuple											= subprocess.run(__UpperCAmelCase  ,env=__UpperCAmelCase  ,check=__UpperCAmelCase  ,capture_output=__UpperCAmelCase				)
      self.assertEqual(result.returncode  ,0  ,result.stderr				)
      self.assertIn("""success"""  ,result.stdout.decode()				)

      # should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
      lowerCAmelCase__			:  Union[str, Any]											= """1"""
      lowerCAmelCase__			:  List[str]											= subprocess.run(__UpperCAmelCase  ,env=__UpperCAmelCase  ,check=__UpperCAmelCase  ,capture_output=__UpperCAmelCase				)
      self.assertEqual(result.returncode  ,0  ,result.stderr				)
      self.assertIn("""success"""  ,result.stdout.decode()				)







'''simple docstring'''





import os
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase      ):



    """simple docstring"""





    lowerCAmelCase__			:  List[str]											= len(grid[0]      )
    lowerCAmelCase__			:  int											= len(UpperCamelCase      )

    lowerCAmelCase__			:  Optional[int]											= 0
    lowerCAmelCase__			:  Tuple											= 0
    lowerCAmelCase__			:  Optional[Any]											= 0

    # Check vertically, horizontally, diagonally at the same time (only works
    # for nxn grid)
    for i in range(UpperCamelCase      ):
        for j in range(n_rows - 3      ):
            lowerCAmelCase__			:  str											= grid[j][i] * grid[j + 1][i] * grid[j + 2][i] * grid[j + 3][i]
            lowerCAmelCase__			:  Optional[int]											= 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:
                lowerCAmelCase__			:  Optional[int]											= (
                    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:
                lowerCAmelCase__			:  Tuple											= (
                    grid[i][j]
                    * grid[i - 1][j + 1]
                    * grid[i - 2][j + 2]
                    * grid[i - 3][j + 3]
                )

            lowerCAmelCase__			:  Dict											= max(
                UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase      )
            if max_product > largest:
                lowerCAmelCase__			:  Any											= max_product

    return largest
def        _SCREAMING_SNAKE_CASE  (	):



    """simple docstring"""





    lowerCAmelCase__			:  List[str]											= []
    with open(os.path.dirname(UpperCamelCase      ) + """/grid.txt"""      ) as file:
        for line in file:
            grid.append(line.strip("""\n"""      ).split(""" """      )      )

    lowerCAmelCase__			:  Dict											= [[int(UpperCamelCase      ) for i in grid[j]] for j in range(len(UpperCamelCase      )      )]

    return largest_product(UpperCamelCase      )


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


