




"""simple docstring"""

import subprocess
import sys

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

class        lowercase      (    __UpperCAmelCase):







				@require_torch
				def 					a_  (							self   :					int       ):



					"""simple docstring"""

					A_  :				Union[str, Any]	   =		'''\nfrom transformers import BertConfig, BertModel, BertTokenizer, pipeline\n        '''

					A_  :				Dict	   =		'''\nmname = "hf-internal-testing/tiny-random-bert"\nBertConfig.from_pretrained(mname)\nBertModel.from_pretrained(mname)\nBertTokenizer.from_pretrained(mname)\npipe = pipeline(task="fill-mask", model=mname)\nprint("success")\n        '''

					A_  :				Any	   =		'''\nimport socket\ndef offline_socket(*args, **kwargs): raise RuntimeError("Offline mode is enabled, we shouldn\'t access internet")\nsocket.socket = offline_socket\n        '''

					# Force fetching the files so that we can use the cache
					A_  :				Optional[Any]	   =		'''hf-internal-testing/tiny-random-bert'''
					BertConfig.from_pretrained(_lowerCamelCase       )
					BertModel.from_pretrained(_lowerCamelCase       )
					BertTokenizer.from_pretrained(_lowerCamelCase       )
					pipeline(task='''fill-mask'''      ,     model=_lowerCamelCase       )

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

					# should succeed
					A_  :				int	   =		self.get_env()
					# should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
					A_  :				Any	   =		'''1'''
					A_  :				Tuple	   =		subprocess.run(_lowerCamelCase      ,     env=_lowerCamelCase      ,     check=_lowerCamelCase      ,     capture_output=_lowerCamelCase       )
					self.assertEqual(result.returncode      ,     0      ,     result.stderr       )
					self.assertIn('''success'''      ,     result.stdout.decode()       )







				@require_torch
				def 					a_  (							self   :					str       ):



					"""simple docstring"""

					A_  :				Any	   =		'''\nfrom transformers import BertConfig, BertModel, BertTokenizer, pipeline\n        '''

					A_  :				List[Any]	   =		'''\nmname = "hf-internal-testing/tiny-random-bert"\nBertConfig.from_pretrained(mname)\nBertModel.from_pretrained(mname)\nBertTokenizer.from_pretrained(mname)\npipe = pipeline(task="fill-mask", model=mname)\nprint("success")\n        '''

					A_  :				Any	   =		'''\nimport socket\ndef offline_socket(*args, **kwargs): raise socket.error("Faking flaky internet")\nsocket.socket = offline_socket\n        '''

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

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

					# should succeed
					A_  :				Optional[Any]	   =		self.get_env()
					A_  :				str	   =		subprocess.run(_lowerCamelCase      ,     env=_lowerCamelCase      ,     check=_lowerCamelCase      ,     capture_output=_lowerCamelCase       )
					self.assertEqual(result.returncode      ,     0      ,     result.stderr       )
					self.assertIn('''success'''      ,     result.stdout.decode()       )







				@require_torch
				def 					a_  (							self   :					str       ):



					"""simple docstring"""

					A_  :				Optional[int]	   =		'''\nfrom transformers import BertConfig, BertModel, BertTokenizer\n        '''

					A_  :				str	   =		'''\nmname = "hf-internal-testing/tiny-random-bert-sharded"\nBertConfig.from_pretrained(mname)\nBertModel.from_pretrained(mname)\nprint("success")\n        '''

					A_  :				int	   =		'''\nimport socket\ndef offline_socket(*args, **kwargs): raise ValueError("Offline mode is enabled")\nsocket.socket = offline_socket\n        '''

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

					# should succeed
					A_  :				List[Any]	   =		self.get_env()
					A_  :				Union[str, Any]	   =		subprocess.run(_lowerCamelCase      ,     env=_lowerCamelCase      ,     check=_lowerCamelCase      ,     capture_output=_lowerCamelCase       )
					self.assertEqual(result.returncode      ,     0      ,     result.stderr       )
					self.assertIn('''success'''      ,     result.stdout.decode()       )

					# next emulate no network
					A_  :				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
					A_  :				Optional[Any]	   =		'''1'''
					A_  :				List[str]	   =		subprocess.run(_lowerCamelCase      ,     env=_lowerCamelCase      ,     check=_lowerCamelCase      ,     capture_output=_lowerCamelCase       )
					self.assertEqual(result.returncode      ,     0      ,     result.stderr       )
					self.assertIn('''success'''      ,     result.stdout.decode()       )







				@require_torch
				def 					a_  (							self   :					List[str]       ):



					"""simple docstring"""

					A_  :				int	   =		'''\nfrom transformers import pipeline\n        '''
					A_  :				int	   =		'''\nmname = "hf-internal-testing/tiny-random-bert"\npipe = pipeline(model=mname)\n        '''

					A_  :				Union[str, Any]	   =		'''\nimport socket\ndef offline_socket(*args, **kwargs): raise socket.error("Offline mode is enabled")\nsocket.socket = offline_socket\n        '''
					A_  :				List[str]	   =		self.get_env()
					A_  :				Optional[Any]	   =		'''1'''
					A_  :				Union[str, Any]	   =		[sys.executable, '''-c''', '''\n'''.join([load, mock, run]       )]
					A_  :				Tuple	   =		subprocess.run(_lowerCamelCase      ,     env=_lowerCamelCase      ,     check=_lowerCamelCase      ,     capture_output=_lowerCamelCase       )
					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 					a_  (							self   :					List[Any]       ):



					"""simple docstring"""

					A_  :				Tuple	   =		'''\nfrom transformers import AutoModel\n        '''
					A_  :				Optional[int]	   =		'''\nmname = "hf-internal-testing/test_dynamic_model"\nAutoModel.from_pretrained(mname, trust_remote_code=True)\nprint("success")\n        '''

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

					# should succeed
					A_  :				Union[str, Any]	   =		self.get_env()
					A_  :				Tuple	   =		subprocess.run(_lowerCamelCase      ,     env=_lowerCamelCase      ,     check=_lowerCamelCase      ,     capture_output=_lowerCamelCase       )
					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
					A_  :				Optional[Any]	   =		'''1'''
					A_  :				Optional[int]	   =		subprocess.run(_lowerCamelCase      ,     env=_lowerCamelCase      ,     check=_lowerCamelCase      ,     capture_output=_lowerCamelCase       )
					self.assertEqual(result.returncode      ,     0      ,     result.stderr       )
					self.assertIn('''success'''      ,     result.stdout.decode()       )










"""simple docstring"""

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowerCamelCase  :			Optional[Any]        =       logging.get_logger(__name__)

_lowerCamelCase  :			Any        =       {
    'studio-ousia/luke-base': 'https://huggingface.co/studio-ousia/luke-base/resolve/main/config.json',
    'studio-ousia/luke-large': 'https://huggingface.co/studio-ousia/luke-large/resolve/main/config.json',
}

class        lowercase      (    __UpperCAmelCase):
				__lowerCAmelCase    :    Any         =   """luke"""







				def __init__(							self   :					List[str]      ,     _lowerCamelCase   :					Union[str, Any]=5_02_67      ,     _lowerCamelCase   :					Tuple=50_00_00      ,     _lowerCamelCase   :					int=7_68      ,     _lowerCamelCase   :					Union[str, Any]=2_56      ,     _lowerCamelCase   :					Dict=12      ,     _lowerCamelCase   :					str=12      ,     _lowerCamelCase   :					Dict=30_72      ,     _lowerCamelCase   :					Union[str, Any]="gelu"      ,     _lowerCamelCase   :					Optional[int]=0.1      ,     _lowerCamelCase   :					str=0.1      ,     _lowerCamelCase   :					Union[str, Any]=5_12      ,     _lowerCamelCase   :					int=2      ,     _lowerCamelCase   :					Optional[int]=0.02      ,     _lowerCamelCase   :					int=1E-12      ,     _lowerCamelCase   :					List[str]=True      ,     _lowerCamelCase   :					str=None      ,     _lowerCamelCase   :					Union[str, Any]=1      ,     _lowerCamelCase   :					str=0      ,     _lowerCamelCase   :					Dict=2      ,     **_lowerCamelCase   :					Optional[int]      ,     ):



					"""simple docstring"""

					super().__init__(pad_token_id=_lowerCamelCase      ,     bos_token_id=_lowerCamelCase      ,     eos_token_id=_lowerCamelCase      ,     **_lowerCamelCase       )

					A_  :				str	   =		vocab_size
					A_  :				Optional[Any]	   =		entity_vocab_size
					A_  :				Optional[Any]	   =		hidden_size
					A_  :				List[str]	   =		entity_emb_size
					A_  :				Union[str, Any]	   =		num_hidden_layers
					A_  :				Dict	   =		num_attention_heads
					A_  :				Union[str, Any]	   =		hidden_act
					A_  :				Dict	   =		intermediate_size
					A_  :				int	   =		hidden_dropout_prob
					A_  :				str	   =		attention_probs_dropout_prob
					A_  :				List[Any]	   =		max_position_embeddings
					A_  :				Optional[Any]	   =		type_vocab_size
					A_  :				Optional[int]	   =		initializer_range
					A_  :				str	   =		layer_norm_eps
					A_  :				List[str]	   =		use_entity_aware_attention
					A_  :				Optional[int]	   =		classifier_dropout





