





import subprocess
import sys

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





class A_					(			_lowerCamelCase   ):




   @require_torch
   def _lowerCAmelCase      (self	:Optional[int] )->					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
         __A          =				'''
from transformers import BertConfig, BertModel, BertTokenizer, pipeline
        '''

         __A          =				'''
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")
        '''

         __A          =				'''
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
         __A          =				'''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
         __A          =				[sys.executable, '''-c''', '''\n'''.join([load, run, mock] )]

         # should succeed
         __A          =				self.get_env()
         # should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
         __A          =				'''1'''
         __A          =				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 _lowerCAmelCase      (self	:str )->					List[str]:
         # python one-liner segments
         # this must be loaded before socket.socket is monkey-patched
         __A          =				'''
from transformers import BertConfig, BertModel, BertTokenizer, pipeline
        '''

         __A          =				'''
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")
        '''

         __A          =				'''
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
         __A          =				'''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
         __A          =				[sys.executable, '''-c''', '''\n'''.join([load, run, mock] )]

         # should succeed
         __A          =				self.get_env()
         __A          =				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 _lowerCAmelCase      (self	:Dict )->					Dict:
         # 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
         __A          =				'''
from transformers import BertConfig, BertModel, BertTokenizer
        '''

         __A          =				'''
mname = "hf-internal-testing/tiny-random-bert-sharded"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
print("success")
        '''

         __A          =				'''
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
         __A          =				[sys.executable, '''-c''', '''\n'''.join([load, run] )]

         # should succeed
         __A          =				self.get_env()
         __A          =				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
         __A          =				[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          =				'''1'''
         __A          =				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 _lowerCAmelCase      (self	:List[str] )->					str:
         __A          =				'''
from transformers import pipeline
        '''
         __A          =				'''
mname = "hf-internal-testing/tiny-random-bert"
pipe = pipeline(model=mname)
        '''

         __A          =				'''
import socket
def offline_socket(*args, **kwargs): raise socket.error("Offline mode is enabled")
socket.socket = offline_socket
        '''
         __A          =				self.get_env()
         __A          =				'''1'''
         __A          =				[sys.executable, '''-c''', '''\n'''.join([load, mock, run] )]
         __A          =				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 _lowerCAmelCase      (self	:str )->					Dict:
         __A          =				'''
from transformers import AutoModel
        '''
         __A          =				'''
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
         __A          =				[sys.executable, '''-c''', '''\n'''.join([load, run] )]

         # should succeed
         __A          =				self.get_env()
         __A          =				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
         __A          =				'''1'''
         __A          =				subprocess.run(_UpperCamelCase    ,   env=_UpperCamelCase    ,   check=_UpperCamelCase    ,   capture_output=_UpperCamelCase )
         self.assertEqual(result.returncode    ,   0    ,   result.stderr )
         self.assertIn('''success'''    ,   result.stdout.decode() )












import os
from datetime import datetime as dt

from github import Github


snake_case__					:							Union[str, Any]													=     [
    'good first issue',
    'feature request',
    'wip',
]



def _a				(	)	->						List[Any]:







      '''simple docstring'''






      __A          =				Github(os.environ['''GITHUB_TOKEN'''] )
      __A          =				g.get_repo('''huggingface/accelerate''' )
      __A          =				repo.get_issues(state='''open''' )

      for issue in open_issues:
            __A          =				sorted([comment for comment in issue.get_comments()]					,				key=lambda lowerCamelCase : i.created_at					,				reverse=lowerCamelCase )
            __A          =				comments[0] if len(lowerCamelCase ) > 0 else None
            __A          =				dt.utcnow()
            __A          =				(current_time - issue.updated_at).days
            __A          =				(current_time - issue.created_at).days
            if (
                last_comment is not None
                and last_comment.user.login == "github-actions[bot]"
                and days_since_updated > 7
                and days_since_creation >= 30
                and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels() )
            ):
                  # Close issue since it has been 7 days of inactivity since bot mention.
                  issue.edit(state='''closed''' )
            elif (
                days_since_updated > 23
                and days_since_creation >= 30
                and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels() )
            ):
                  # Add stale comment
                  issue.create_comment(
                      '''This issue has been automatically marked as stale because it has not had '''
                      '''recent activity. If you think this still needs to be addressed '''
                      '''please comment on this thread.\n\nPlease note that issues that do not follow the '''
                      '''[contributing guidelines](https://github.com/huggingface/accelerate/blob/main/CONTRIBUTING.md) '''
                      '''are likely to be ignored.''' )


if __name__ == "__main__":
       main()





