





import subprocess
import sys

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



class    A__  (			__snake_case     ):





      @require_torch
      def 			__UpperCamelCase(					self  ):
       '''simple docstring'''




       UpperCamelCase      :   int			      =  "\nfrom transformers import BertConfig, BertModel, BertTokenizer, pipeline\n        "

       UpperCamelCase      :   Union[str, 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        "

       UpperCamelCase      :   int			      =  "\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
       UpperCamelCase      :   Any			      =  "hf-internal-testing/tiny-random-bert"
       BertConfig.from_pretrained(A_  )
       BertModel.from_pretrained(A_  )
       BertTokenizer.from_pretrained(A_  )
       pipeline(task="fill-mask"			,				model=A_  )

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

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





      @require_torch
      def 			__UpperCamelCase(					self  ):
       '''simple docstring'''




       UpperCamelCase      :   Dict			      =  "\nfrom transformers import BertConfig, BertModel, BertTokenizer, pipeline\n        "

       UpperCamelCase      :   str			      =  "\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        "

       UpperCamelCase      :   str			      =  "\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
       UpperCamelCase      :   Tuple			      =  "hf-internal-testing/tiny-random-bert"
       BertConfig.from_pretrained(A_  )
       BertModel.from_pretrained(A_  )
       BertTokenizer.from_pretrained(A_  )
       pipeline(task="fill-mask"			,				model=A_  )

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

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





      @require_torch
      def 			__UpperCamelCase(					self  ):
       '''simple docstring'''




       UpperCamelCase      :   Dict			      =  "\nfrom transformers import BertConfig, BertModel, BertTokenizer\n        "

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

       UpperCamelCase      :   Tuple			      =  "\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
       UpperCamelCase      :   Any			      =  [sys.executable, "-c", "\n".join([load, run]  )]

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

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





      @require_torch
      def 			__UpperCamelCase(					self  ):
       '''simple docstring'''




       UpperCamelCase      :   Optional[Any]			      =  "\nfrom transformers import pipeline\n        "
       UpperCamelCase      :   List[str]			      =  "\nmname = \"hf-internal-testing/tiny-random-bert\"\npipe = pipeline(model=mname)\n        "

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




       UpperCamelCase      :   Tuple			      =  "\nfrom transformers import AutoModel\n        "
       UpperCamelCase      :   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
       UpperCamelCase      :   str			      =  [sys.executable, "-c", "\n".join([load, run]  )]

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







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__lowerCamelCase			:	List[Any]					    =	{
    """configuration_chinese_clip""": [
        """CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """ChineseCLIPConfig""",
        """ChineseCLIPOnnxConfig""",
        """ChineseCLIPTextConfig""",
        """ChineseCLIPVisionConfig""",
    ],
    """processing_chinese_clip""": ["""ChineseCLIPProcessor"""],
}

try:
    if not is_vision_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase			:	Tuple					    =	["""ChineseCLIPFeatureExtractor"""]
    __lowerCamelCase			:	List[str]					    =	["""ChineseCLIPImageProcessor"""]

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase			:	str					    =	[
        """CHINESE_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST""",
        """ChineseCLIPModel""",
        """ChineseCLIPPreTrainedModel""",
        """ChineseCLIPTextModel""",
        """ChineseCLIPVisionModel""",
    ]

if TYPE_CHECKING:
    from .configuration_chinese_clip import (
        CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
        ChineseCLIPConfig,
        ChineseCLIPOnnxConfig,
        ChineseCLIPTextConfig,
        ChineseCLIPVisionConfig,
    )
    from .processing_chinese_clip import ChineseCLIPProcessor

    try:
        if not is_vision_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .feature_extraction_chinese_clip import ChineseCLIPFeatureExtractor, ChineseCLIPImageProcessor

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_chinese_clip import (
            CHINESE_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
            ChineseCLIPModel,
            ChineseCLIPPreTrainedModel,
            ChineseCLIPTextModel,
            ChineseCLIPVisionModel,
        )

else:
    import sys

    __lowerCamelCase			:	Any					    =	_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
